From: Rob Browning Date: Tue, 5 Aug 2014 17:33:43 +0000 (-0500) Subject: thelpers.py: use t/tmp as the tmpdir parent X-Git-Tag: 0.27-rc1~47^2 X-Git-Url: https://arthur.barton.de/gitweb/?a=commitdiff_plain;h=7f4323bf5a7ecc10ce4574cf86e12018934a104f;hp=a01949cd7bef41c7f43e6334e6989878d47b29b6;p=bup.git thelpers.py: use t/tmp as the tmpdir parent Signed-off-by: Rob Browning --- 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])