1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
from test.lib import *
import os
import 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):
# TODO: ensure examples are actually run regardless of check for
# "__main__", perhaps standardizing the format of all examples.
# ensure that examples with external dependencies are not run if
# those dependencies are not present (i.e. elementtree, postgis)
def test_examples(self):
pass
# for module in find_modules(): check_import.description =
# module yield check_import, module
|