]> arthur.barton.de Git - bup.git/blob - buptest.py
Git: Ignore two more generated files
[bup.git] / buptest.py
1
2 from contextlib import contextmanager
3 from os.path import basename, dirname, realpath
4 from traceback import extract_stack
5 import subprocess, sys, tempfile
6
7 from wvtest import WVPASSEQ, wvfailure_count
8
9 from bup import helpers
10
11
12 @contextmanager
13 def no_lingering_errors():
14     def fail_if_errors():
15         if helpers.saved_errors:
16             bt = extract_stack()
17             src_file, src_line, src_func, src_txt = bt[-4]
18             msg = 'saved_errors ' + repr(helpers.saved_errors)
19             print '! %-70s %s' % ('%s:%-4d %s' % (basename(src_file),
20                                                   src_line,
21                                                   msg),
22                                   'FAILED')
23             sys.stdout.flush()
24     fail_if_errors()
25     helpers.clear_errors()
26     yield
27     fail_if_errors()
28     helpers.clear_errors()
29
30
31 # Assumes (of course) this file is at the top-level of the source tree
32 _bup_tmp = realpath(dirname(__file__) + '/t/tmp')
33 helpers.mkdirp(_bup_tmp)
34
35
36 @contextmanager
37 def test_tempdir(prefix):
38     initial_failures = wvfailure_count()
39     tmpdir = tempfile.mkdtemp(dir=_bup_tmp, prefix=prefix)
40     yield tmpdir
41     if wvfailure_count() == initial_failures:
42         subprocess.call(['chmod', '-R', 'u+rwX', tmpdir])
43         subprocess.call(['rm', '-rf', tmpdir])