From: Rob Browning Date: Sat, 9 Oct 2010 17:54:46 +0000 (-0500) Subject: Add helpers.detect_fakeroot() and use it in relevant metadata tests. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=9d94c90d3e53279ea0bc4c9de07fe56ae775f15f;p=packages%2Fb%2Fbup.git Add helpers.detect_fakeroot() and use it in relevant metadata tests. Test geteuid == 0 or detect_fakeroot() to skip tmetadata.py test_from_path_error() and test_apply_to_path_error() since they rely on the user not being root. --- diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py index 606c135..f7688da 100644 --- a/lib/bup/helpers.py +++ b/lib/bup/helpers.py @@ -129,6 +129,11 @@ def realpath(p): return out +def detect_fakeroot(): + "Return True if we appear to be running under fakeroot." + return os.getenv("FAKEROOTKEY") != None + + _username = None def username(): """Get the user's login name.""" diff --git a/lib/bup/t/thelpers.py b/lib/bup/t/thelpers.py index 9f24962..c06f553 100644 --- a/lib/bup/t/thelpers.py +++ b/lib/bup/t/thelpers.py @@ -1,3 +1,5 @@ +import os + from bup.helpers import * from wvtest import * @@ -10,3 +12,11 @@ def test_parse_num(): WVPASSEQ(pn('2 gb'), 2*1024*1024*1024) WVPASSEQ(pn('1e+9 k'), 1000000000 * 1024) WVPASSEQ(pn('-3e-3mb'), int(-0.003 * 1024 * 1024)) + + +@wvtest +def test_detect_fakeroot(): + if os.getenv('FAKEROOTKEY'): + WVPASS(detect_fakeroot()) + else: + WVPASS(not detect_fakeroot()) diff --git a/lib/bup/t/tmetadata.py b/lib/bup/t/tmetadata.py index 0fdc0b8..e5973f6 100644 --- a/lib/bup/t/tmetadata.py +++ b/lib/bup/t/tmetadata.py @@ -1,6 +1,7 @@ import tempfile import subprocess from bup import metadata +from bup.helpers import detect_fakeroot from wvtest import * @@ -88,6 +89,8 @@ def test_clean_up_extract_path(): @wvtest def test_from_path_error(): + if os.geteuid == 0 or detect_fakeroot(): + return tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-') try: path = tmpdir + '/foo' @@ -106,6 +109,8 @@ def test_from_path_error(): @wvtest def test_apply_to_path_error(): + if os.geteuid == 0 or detect_fakeroot(): + return tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-') try: path = tmpdir + '/foo'