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 | # Create patch to hide --no-interactive paster option |
---|
10 | # to prevent confusing of a user. |
---|
11 | orig_paster = paster |
---|
12 | def paster(cmd): |
---|
13 | return orig_paster(cmd + " --no-interactive") |
---|
14 | |
---|
15 | current_dir = os.path.abspath(os.path.dirname(__file__)) |
---|
16 | |
---|
17 | def doc_suite(test_dir, setUp=testSetUp, tearDown=testTearDown, globs=None): |
---|
18 | """Returns a test suite, based on doctests found in /doctest.""" |
---|
19 | suite = [] |
---|
20 | if globs is None: |
---|
21 | globs = globals() |
---|
22 | |
---|
23 | flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | |
---|
24 | doctest.REPORT_ONLY_FIRST_FAILURE) |
---|
25 | |
---|
26 | package_dir = os.path.split(test_dir)[0] |
---|
27 | if package_dir not in sys.path: |
---|
28 | sys.path.append(package_dir) |
---|
29 | |
---|
30 | doctest_dir = package_dir |
---|
31 | |
---|
32 | # filtering files on extension |
---|
33 | docs = [os.path.join(doctest_dir, doc) for doc in |
---|
34 | os.listdir(doctest_dir) if doc.endswith('.txt')] |
---|
35 | |
---|
36 | for test in docs: |
---|
37 | suite.append(doctest.DocFileSuite(test, optionflags=flags, |
---|
38 | globs=globs, setUp=setUp, |
---|
39 | tearDown=tearDown, |
---|
40 | module_relative=False)) |
---|
41 | |
---|
42 | return unittest.TestSuite(suite) |
---|
43 | |
---|
44 | |
---|
45 | def test_suite(): |
---|
46 | """returns the test suite""" |
---|
47 | suite = doc_suite(current_dir) |
---|
48 | suite.layer = ZopeSkelLayer |
---|
49 | return suite |
---|
50 | |
---|
51 | if __name__ == '__main__': |
---|
52 | unittest.main(defaultTest='test_suite') |
---|
53 | |
---|