diff options
Diffstat (limited to 'test/ex/test_examples.py')
-rw-r--r-- | test/ex/test_examples.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/ex/test_examples.py b/test/ex/test_examples.py new file mode 100644 index 000000000..c31b21e76 --- /dev/null +++ b/test/ex/test_examples.py @@ -0,0 +1,46 @@ +from sqlalchemy.test import * +import os, re + + +def find_py_files(dirs): + for dn in dirs: + dn = os.path.abspath(dn) + for root, dirs, files in os.walk(dn): + for r in '.svn', 'CVS', '.git', '.hg': + try: + dirs.remove(r) + except ValueError: + pass + + pyfiles = [fn for fn in files if fn.endswith('.py')] + if not pyfiles: + continue + + # Find the root of the packages. + packroot = root + while 1: + if not os.path.exists(os.path.join(packroot, '__init__.py')): + break + packroot = os.path.dirname(packroot) + + for fn in pyfiles: + yield os.path.join(root[len(packroot)+1:], fn) + +def filename_to_module_name(fn): + if os.path.basename(fn) == '__init__.py': + fn = os.path.dirname(fn) + return re.sub('\.py$', '', fn.replace(os.sep, '.')) + +def find_modules(*args): + for fn in find_py_files(args or ('../examples',)): + yield filename_to_module_name(fn) + +def check_import(module): + __import__(module) + + +class ExamplesTest(TestBase): + def test_examples(self): + for module in find_modules(): + check_import.description = module + yield check_import, module |