diff options
author | Michael Trier <mtrier@gmail.com> | 2009-07-27 02:12:15 +0000 |
---|---|---|
committer | Michael Trier <mtrier@gmail.com> | 2009-07-27 02:12:15 +0000 |
commit | 34aaabf7ea18af8e8a7721238b5bba00e3532c4c (patch) | |
tree | e1073f8dc9a4b1b643e79a658b00a09c7da4d569 /test/ex/test_examples.py | |
parent | 73554aa4fa60459cd949ca8ac690ac0746a7c445 (diff) | |
download | sqlalchemy-34aaabf7ea18af8e8a7721238b5bba00e3532c4c.tar.gz |
Added in Examples into the test suite so they get exercised regularly. Cleaned up some deprecation warnings in the examples.
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 |