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 | |
| parent | fac431b15799fd9561346efcc128e0b5e8aec3d0 (diff) | |
| download | sqlparse-521a87c900a19e39f9e508c898cb191acfc75199.tar.gz | |
Move regression test to separate directory.
| -rw-r--r-- | tests/regressiontests/__init__.py | 0 | ||||
| -rw-r--r-- | tests/regressiontests/issue9.py (renamed from tests/test_regressions.py) | 10 | ||||
| -rwxr-xr-x | tests/run_tests.py | 32 |
3 files changed, 29 insertions, 13 deletions
diff --git a/tests/regressiontests/__init__.py b/tests/regressiontests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/regressiontests/__init__.py diff --git a/tests/test_regressions.py b/tests/regressiontests/issue9.py index 41ca531..b40d88a 100644 --- a/tests/test_regressions.py +++ b/tests/regressiontests/issue9.py @@ -1,15 +1,13 @@ -# -*- coding: utf-8 -*- +import unittest import sqlparse from sqlparse import tokens as T -from sqlparse.engine.grouping import * +from sqlparse.engine.grouping import Statement, Parenthesis -from tests.utils import TestCaseBase +class TestIssue9(unittest.TestCase): -class TestRegression(TestCaseBase): - - def test_where_doesnt_consume_parenthesis(self): # issue9 + def test_where_doesnt_consume_parenthesis(self): p = sqlparse.parse('(where 1)')[0] self.assert_(isinstance(p, Statement)) self.assertEqual(len(p.tokens), 1) 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) |
