diff options
| author | Andi Albrecht <albrecht.andi@gmail.com> | 2010-06-17 20:07:23 +0200 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2010-06-17 20:07:23 +0200 |
| commit | 521a87c900a19e39f9e508c898cb191acfc75199 (patch) | |
| tree | af10a365c2df4b38447c64e336474055b9a3254f /tests/run_tests.py | |
| parent | fac431b15799fd9561346efcc128e0b5e8aec3d0 (diff) | |
| download | sqlparse-521a87c900a19e39f9e508c898cb191acfc75199.tar.gz | |
Move regression test to separate directory.
Diffstat (limited to 'tests/run_tests.py')
| -rwxr-xr-x | tests/run_tests.py | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/tests/run_tests.py b/tests/run_tests.py index 9a532fc..c057216 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -3,6 +3,7 @@ """Test runner for sqlparse.""" +import fnmatch import optparse import os import sys @@ -19,17 +20,34 @@ parser.add_option('-P', '--profile', action='store_true', default=False) +def _path_matches(path, *patterns): + if not patterns: + return True + for pattern in patterns: + if fnmatch.fnmatch(path, pattern): + return True + return False + + +def _collect_test_modules(base=None, *patterns): + for root, dirnames, filenames in os.walk(os.path.dirname(__file__)): + print root, filenames + for fname in filenames: + if not fname.endswith('.py'): + continue + elif not _path_matches(os.path.join(root, fname), *patterns): + continue + if not root in sys.path: + sys.path.append(root) + modname = os.path.splitext(fname)[0] + yield __import__(modname) + + def main(args): """Create a TestSuite and run it.""" loader = unittest.TestLoader() suite = unittest.TestSuite() - fnames = [os.path.split(f)[-1] for f in args] - for fname in os.listdir(os.path.dirname(__file__)): - if (not fname.startswith('test_') or not fname.endswith('.py') - or (fnames and fname not in fnames)): - continue - modname = os.path.splitext(fname)[0] - mod = __import__(os.path.splitext(fname)[0]) + for mod in _collect_test_modules(*args): suite.addTests(loader.loadTestsFromModule(mod)) return unittest.TextTestRunner(verbosity=2).run(suite) |
