Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 71 lines (55 sloc) 1.826 kB
361122e @andialbrecht Initial import.
authored
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """Test runner for sqlparse."""
5
521a87c @andialbrecht Move regression test to separate directory.
authored
6 import fnmatch
087de87 @andialbrecht * Added profile option to run_tests.py.
authored
7 import optparse
361122e @andialbrecht Initial import.
authored
8 import os
9 import sys
10 import unittest
11
af3c47a @andialbrecht Only add full path to test module if it isn't already in sys.path.
authored
12 test_mod = os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))
13 if test_mod not in sys.path:
14 sys.path.insert(1, test_mod)
361122e @andialbrecht Initial import.
authored
15
16
087de87 @andialbrecht * Added profile option to run_tests.py.
authored
17 parser = optparse.OptionParser()
18 parser.add_option('-P', '--profile',
19 help='Create hotshot profile.',
20 action='store_true', default=False)
21
22
521a87c @andialbrecht Move regression test to separate directory.
authored
23 def _path_matches(path, *patterns):
24 if not patterns:
25 return True
26 for pattern in patterns:
27 if fnmatch.fnmatch(path, pattern):
28 return True
29 return False
30
31
32 def _collect_test_modules(base=None, *patterns):
33 for root, dirnames, filenames in os.walk(os.path.dirname(__file__)):
34 print root, filenames
35 for fname in filenames:
36 if not fname.endswith('.py'):
37 continue
38 elif not _path_matches(os.path.join(root, fname), *patterns):
39 continue
40 if not root in sys.path:
41 sys.path.append(root)
42 modname = os.path.splitext(fname)[0]
43 yield __import__(modname)
44
45
087de87 @andialbrecht * Added profile option to run_tests.py.
authored
46 def main(args):
361122e @andialbrecht Initial import.
authored
47 """Create a TestSuite and run it."""
48 loader = unittest.TestLoader()
49 suite = unittest.TestSuite()
521a87c @andialbrecht Move regression test to separate directory.
authored
50 for mod in _collect_test_modules(*args):
361122e @andialbrecht Initial import.
authored
51 suite.addTests(loader.loadTestsFromModule(mod))
b252592 Fix return code when running unittests.
Andreas Albrecht authored
52 return unittest.TextTestRunner(verbosity=2).run(suite)
361122e @andialbrecht Initial import.
authored
53
54
55
56
57 if __name__ == '__main__':
087de87 @andialbrecht * Added profile option to run_tests.py.
authored
58 opts, args = parser.parse_args()
59 if opts.profile:
393dfca @andialbrecht Conditional hotshot import.
authored
60 import hotshot
087de87 @andialbrecht * Added profile option to run_tests.py.
authored
61 prof = hotshot.Profile("sqlparse.prof")
62 prof.runcall(main, args)
63 prof.close()
64 else:
b252592 Fix return code when running unittests.
Andreas Albrecht authored
65 result = main(args)
66 if not result.wasSuccessful():
67 return_code = 1
68 else:
69 return_code = 0
70 sys.exit(return_code)
Something went wrong with that request. Please try again.