]> arthur.barton.de Git - bup.git/commitdiff
thelpers.py: use t/tmp as the tmpdir parent
authorRob Browning <rlb@defaultvalue.org>
Tue, 5 Aug 2014 17:33:43 +0000 (12:33 -0500)
committerRob Browning <rlb@defaultvalue.org>
Tue, 5 Aug 2014 17:33:43 +0000 (12:33 -0500)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/t/thelpers.py

index 02e89efb10c7b6f1c309441e9dcc46cbe408119d..97438142dcf71a01ed3fd5d5dc5ded141c89fcf9 100644 (file)
@@ -8,6 +8,8 @@ import bup._helpers as _helpers
 from bup.helpers import *
 from wvtest import *
 
+bup_tmp = os.path.realpath('../../../t/tmp')
+mkdirp(bup_tmp)
 
 @wvtest
 def test_next():
@@ -150,17 +152,19 @@ def test_batchpipe():
 
 @wvtest
 def test_atomically_replaced_file():
-    target_file = os.path.join(tempfile.gettempdir(),
-                               'test_atomic_write')
-    try:
-        with atomically_replaced_file(target_file, mode='w') as f:
-            f.write('asdf')
-            WVPASSEQ(f.mode, 'w')
-        f = open(target_file, 'r')
-        WVPASSEQ(f.read(), 'asdf')
-
-        with atomically_replaced_file(target_file, mode='wb') as f:
-            f.write(os.urandom(20))
-            WVPASSEQ(f.mode, 'wb')
-    finally:
-        unlink(target_file)
+    tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-thelper-')
+    target_file = os.path.join(tmpdir, 'test-atomic-write')
+    initial_failures = wvfailure_count()
+
+    with atomically_replaced_file(target_file, mode='w') as f:
+        f.write('asdf')
+        WVPASSEQ(f.mode, 'w')
+    f = open(target_file, 'r')
+    WVPASSEQ(f.read(), 'asdf')
+
+    with atomically_replaced_file(target_file, mode='wb') as f:
+        f.write(os.urandom(20))
+        WVPASSEQ(f.mode, 'wb')
+
+    if wvfailure_count() == initial_failures:
+        subprocess.call(['rm', '-rf', tmpdir])