14 ############################################################################## |
14 ############################################################################## |
15 |
15 |
16 """ |
16 """ |
17 Generic Test case for pyams_utils doc strings |
17 Generic Test case for pyams_utils doc strings |
18 """ |
18 """ |
|
19 |
19 __docformat__ = 'restructuredtext' |
20 __docformat__ = 'restructuredtext' |
20 |
21 |
|
22 import doctest |
|
23 import os |
21 import unittest |
24 import unittest |
22 import doctest |
25 |
23 import sys |
26 from pyams_utils.tests import get_package_dir |
24 import os |
|
25 |
27 |
26 |
28 |
27 current_dir = os.path.abspath(os.path.dirname(__file__)) |
29 CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) |
|
30 |
28 |
31 |
29 def doc_suite(test_dir, globs=None): |
32 def doc_suite(test_dir, globs=None): |
30 """Returns a test suite, based on doc tests strings found in /*.py""" |
33 """Returns a test suite, based on doc tests strings found in /*.py""" |
31 suite = [] |
34 suite = [] |
32 if globs is None: |
35 if globs is None: |
33 globs = globals() |
36 globs = globals() |
34 |
37 |
35 flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | |
38 flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | |
36 doctest.REPORT_ONLY_FIRST_FAILURE) |
39 doctest.REPORT_ONLY_FIRST_FAILURE) |
37 |
40 |
38 package_dir = os.path.split(test_dir)[0] |
41 package_dir = get_package_dir(test_dir) |
39 if package_dir not in sys.path: |
|
40 sys.path.append(package_dir) |
|
41 |
42 |
42 # filtering files on extension |
43 # filtering files on extension |
43 docs = [doc for doc in |
44 docs = [doc for doc in |
44 os.listdir(package_dir) if doc.endswith('.py')] |
45 os.listdir(package_dir) if doc.endswith('.py')] |
45 docs = [doc for doc in docs if not doc.startswith('__')] |
46 docs = [doc for doc in docs if not doc.startswith('__')] |
55 suite.append(doctest.DocTestSuite(location, optionflags=flags, |
56 suite.append(doctest.DocTestSuite(location, optionflags=flags, |
56 globs=globs)) |
57 globs=globs)) |
57 |
58 |
58 return unittest.TestSuite(suite) |
59 return unittest.TestSuite(suite) |
59 |
60 |
|
61 |
60 def test_suite(): |
62 def test_suite(): |
61 """returns the test suite""" |
63 """returns the test suite""" |
62 return doc_suite(current_dir) |
64 return doc_suite(CURRENT_DIR) |
|
65 |
63 |
66 |
64 if __name__ == '__main__': |
67 if __name__ == '__main__': |
65 unittest.main(defaultTest='test_suite') |
68 unittest.main(defaultTest='test_suite') |