Test global fs cache
[pysize.git] / tests / pysize_tests.py
blobef03c63cb25761adec266899b2d7444ac8727085
1 #!/usr/bin/env python
3 import imp
4 import os
5 import tarfile
6 import unittest
7 import shutil
8 import sys
10 PYSIZE_EXAMPLE_PATH = '/tmp/pysize_example_dir'
11 ALL_TESTS = unittest.TestSuite()
13 def setup():
14 if not os.path.exists('/tmp/pysize_example_dir'):
15 os.mkdir('/tmp/pysize_example_dir')
16 tar = tarfile.open('pysize_example_dir.tar.bz2', 'r:bz2')
17 print 'Extracting pysize_example_dir.tar.bz2'
18 for tarinfo in tar:
19 tar.extract(tarinfo, '/tmp')
20 tar.close()
22 def cleanup():
23 os.chmod('/tmp/pysize_example_dir/unreadable_dir', 0700)
24 print 'Removing', PYSIZE_EXAMPLE_PATH
25 shutil.rmtree(PYSIZE_EXAMPLE_PATH)
27 def import_tests():
28 py_files = [p for p in os.listdir('tests') if p.endswith('.py')]
29 tests = list(set([p[:p.index('.')] for p in py_files]))
30 for name in tests:
31 module = getattr(__import__('tests.' + name), name)
32 for test in module.TESTS:
33 suite = unittest.defaultTestLoader.loadTestsFromTestCase(test)
34 ALL_TESTS.addTest(suite)
36 def main():
37 sys.path.insert(0, '..')
38 import_tests()
39 try:
40 setup()
41 unittest.main(argv=[sys.argv[0], '-v'], defaultTest='ALL_TESTS')
42 finally:
43 if '-k' not in sys.argv:
44 cleanup()
46 if __name__ == '__main__':
47 main()