]> arthur.barton.de Git - bup.git/commitdiff
Add helpers.detect_fakeroot() and use it in relevant metadata tests.
authorRob Browning <rlb@defaultvalue.org>
Sat, 9 Oct 2010 17:54:46 +0000 (12:54 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 9 Oct 2010 17:54:46 +0000 (12:54 -0500)
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.

lib/bup/helpers.py
lib/bup/t/thelpers.py
lib/bup/t/tmetadata.py

index 606c1351ccdf619e875ce1c2bf072e030d8811cd..f7688da7fbc733a1e1c4676031968ba704f917bc 100644 (file)
@@ -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."""
index 9f24962644fb25072c27879968f98e38ee62fba8..c06f5538209c2518ca6fbc42c3983cf765febee1 100644 (file)
@@ -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())
index 0fdc0b8643e84ac0e49906e3250644e270903c61..e5973f622a0de48aaffcf94545d2c24ef1fc80bd 100644 (file)
@@ -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'