From 7f4323bf5a7ecc10ce4574cf86e12018934a104f Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Tue, 5 Aug 2014 12:33:43 -0500 Subject: [PATCH] thelpers.py: use t/tmp as the tmpdir parent Signed-off-by: Rob Browning --- lib/bup/t/thelpers.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/bup/t/thelpers.py b/lib/bup/t/thelpers.py index 02e89ef..9743814 100644 --- a/lib/bup/t/thelpers.py +++ b/lib/bup/t/thelpers.py @@ -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]) -- 2.39.2