|
1 # -*- coding: utf-8 -*- ###################################################### |
|
2 ############################################################################## |
1 # |
3 # |
2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net> |
4 # Copyright (c) 2008-2010 Thierry Florac <tflorac AT ulthar.net> |
3 # All Rights Reserved. |
5 # All Rights Reserved. |
4 # |
6 # |
5 # This software is subject to the provisions of the Zope Public License, |
7 # This software is subject to the provisions of the Zope Public License, |
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
8 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
9 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
10 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
11 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
10 # FOR A PARTICULAR PURPOSE. |
12 # FOR A PARTICULAR PURPOSE. |
11 # |
13 # |
|
14 ############################################################################## |
12 |
15 |
13 """ |
16 """ |
14 Generic Test case for pyams_zmq doctest |
17 Generic test case for pyams_zmq doctests |
15 """ |
18 """ |
|
19 |
16 __docformat__ = 'restructuredtext' |
20 __docformat__ = 'restructuredtext' |
17 |
21 |
|
22 import doctest |
|
23 import os |
18 import unittest |
24 import unittest |
19 import doctest |
25 |
20 import sys |
26 from pyams_utils.tests import get_package_dir |
21 import os |
|
22 |
27 |
23 |
28 |
24 current_dir = os.path.dirname(__file__) |
29 CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) |
25 |
30 |
26 def doc_suite(test_dir, setUp=None, tearDown=None, globs=None): |
31 |
|
32 def doc_suite(test_dir, setUp=None, tearDown=None, globs=None): # pylint: disable=invalid-name |
27 """Returns a test suite, based on doctests found in /doctest.""" |
33 """Returns a test suite, based on doctests found in /doctest.""" |
28 suite = [] |
34 suite = [] |
29 if globs is None: |
35 if globs is None: |
30 globs = globals() |
36 globs = globals() |
31 |
37 |
32 flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | |
38 flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | |
33 doctest.REPORT_ONLY_FIRST_FAILURE) |
39 doctest.REPORT_ONLY_FIRST_FAILURE) |
34 |
40 |
35 package_dir = os.path.split(test_dir)[0] |
41 package_dir = get_package_dir(test_dir) |
36 if package_dir not in sys.path: |
|
37 sys.path.append(package_dir) |
|
38 |
|
39 doctest_dir = os.path.join(package_dir, 'doctests') |
42 doctest_dir = os.path.join(package_dir, 'doctests') |
40 |
43 |
41 # filtering files on extension |
44 # filtering files on extension |
42 docs = [os.path.join(doctest_dir, doc) for doc in |
45 docs = [os.path.join(doctest_dir, doc) for doc in |
43 os.listdir(doctest_dir) if doc.endswith('.txt')] |
46 os.listdir(doctest_dir) if doc.endswith('.txt') or doc.endswith('.rst')] |
44 |
47 |
45 for test in docs: |
48 for test in docs: |
46 suite.append(doctest.DocFileSuite(test, optionflags=flags, |
49 suite.append(doctest.DocFileSuite(test, optionflags=flags, |
47 globs=globs, setUp=setUp, |
50 globs=globs, setUp=setUp, |
48 tearDown=tearDown, |
51 tearDown=tearDown, |
49 module_relative=False)) |
52 module_relative=False)) |
50 |
53 |
51 return unittest.TestSuite(suite) |
54 return unittest.TestSuite(suite) |
52 |
55 |
|
56 |
53 def test_suite(): |
57 def test_suite(): |
54 """returns the test suite""" |
58 """returns the test suite""" |
55 return doc_suite(current_dir) |
59 return doc_suite(CURRENT_DIR) |
|
60 |
56 |
61 |
57 if __name__ == '__main__': |
62 if __name__ == '__main__': |
58 unittest.main(defaultTest='test_suite') |
63 unittest.main(defaultTest='test_suite') |
59 |
|