13 PYSIZE_EXAMPLE_PATH
= '/tmp/pysize_example_dir'
14 ALL_TESTS
= unittest
.TestSuite()
17 if not os
.path
.exists('/tmp/pysize_example_dir'):
18 tar
= tarfile
.open('pysize_example_dir.tar.bz2', 'r:bz2')
19 print 'Extracting pysize_example_dir.tar.bz2'
21 tar
.extract(tarinfo
, '/tmp')
25 print 'Removing', PYSIZE_EXAMPLE_PATH
26 shutil
.rmtree(PYSIZE_EXAMPLE_PATH
)
29 py_files
= [p
for p
in os
.listdir('tests') if p
.endswith('.py')]
30 tests
= list(set([p
[:p
.index('.')] for p
in py_files
]))
32 module
= getattr(__import__('tests.' + name
), name
)
33 for test
in module
.TESTS
:
34 suite
= unittest
.defaultTestLoader
.loadTestsFromTestCase(test
)
35 ALL_TESTS
.addTest(suite
)
38 parser
= optparse
.OptionParser()
39 parser
.add_option('--keep', '-k', action
='store_true', dest
='keep',
40 default
=False, help='keep /tmp/pysize_example_dir')
41 parser
.add_option('--coverage', '-c', action
='store_true', dest
='coverage',
42 default
=False, help='include coverage tests')
43 (options
, args
) = parser
.parse_args()
55 for (name
, module
) in sys
.modules
.iteritems():
56 if name
.startswith('pysize.') and module
:
57 path
= '../' + name
.replace('.', '/') + '.py'
58 if os
.path
.exists(path
):
59 modules
.append(module
)
60 coverage
.report(modules
)
64 options
= parse_cmdline()
65 sys
.path
.insert(0, '..')
71 unittest
.main(argv
=[sys
.argv
[0], '-v'], defaultTest
='ALL_TESTS')
78 if __name__
== '__main__':