[157] | 1 | # -*- coding: utf-8 -*- |
---|
| 2 | """ |
---|
| 3 | Grabs the tests in doctest |
---|
| 4 | """ |
---|
| 5 | __docformat__ = 'restructuredtext' |
---|
| 6 | |
---|
| 7 | from zopeskel.tests.test_zopeskeldocs import * |
---|
| 8 | |
---|
| 9 | current_dir = os.path.abspath(os.path.dirname(__file__)) |
---|
| 10 | |
---|
| 11 | def doc_suite(test_dir, setUp=testSetUp, tearDown=testTearDown, globs=None): |
---|
| 12 | """Returns a test suite, based on doctests found in /doctest.""" |
---|
| 13 | suite = [] |
---|
| 14 | if globs is None: |
---|
| 15 | globs = globals() |
---|
| 16 | |
---|
| 17 | flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | |
---|
| 18 | doctest.REPORT_ONLY_FIRST_FAILURE) |
---|
| 19 | |
---|
| 20 | package_dir = os.path.split(test_dir)[0] |
---|
| 21 | if package_dir not in sys.path: |
---|
| 22 | sys.path.append(package_dir) |
---|
| 23 | |
---|
| 24 | doctest_dir = package_dir |
---|
| 25 | |
---|
| 26 | # filtering files on extension |
---|
| 27 | docs = [os.path.join(doctest_dir, doc) for doc in |
---|
| 28 | os.listdir(doctest_dir) if doc.endswith('.txt')] |
---|
| 29 | |
---|
| 30 | for test in docs: |
---|
| 31 | suite.append(doctest.DocFileSuite(test, optionflags=flags, |
---|
| 32 | globs=globs, setUp=setUp, |
---|
| 33 | tearDown=tearDown, |
---|
| 34 | module_relative=False)) |
---|
| 35 | |
---|
| 36 | return unittest.TestSuite(suite) |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | def test_suite(): |
---|
| 40 | """returns the test suite""" |
---|
| 41 | suite = doc_suite(current_dir) |
---|
| 42 | suite.layer = ZopeSkelLayer |
---|
| 43 | return suite |
---|
| 44 | |
---|
| 45 | if __name__ == '__main__': |
---|
| 46 | unittest.main(defaultTest='test_suite') |
---|
| 47 | |
---|