|
1 # |
|
2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net> |
|
3 # All Rights Reserved. |
|
4 # |
|
5 # 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. |
|
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
10 # FOR A PARTICULAR PURPOSE. |
|
11 # |
|
12 |
|
13 """ |
|
14 Generic Test case for pyams_zmq doc strings |
|
15 """ |
|
16 __docformat__ = 'restructuredtext' |
|
17 |
|
18 import unittest |
|
19 import doctest |
|
20 import sys |
|
21 import os |
|
22 |
|
23 |
|
24 current_dir = os.path.abspath(os.path.dirname(__file__)) |
|
25 |
|
26 def doc_suite(test_dir, globs=None): |
|
27 """Returns a test suite, based on doc tests strings found in /*.py""" |
|
28 suite = [] |
|
29 if globs is None: |
|
30 globs = globals() |
|
31 |
|
32 flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | |
|
33 doctest.REPORT_ONLY_FIRST_FAILURE) |
|
34 |
|
35 package_dir = os.path.split(test_dir)[0] |
|
36 if package_dir not in sys.path: |
|
37 sys.path.append(package_dir) |
|
38 |
|
39 # filtering files on extension |
|
40 docs = [doc for doc in |
|
41 os.listdir(package_dir) if doc.endswith('.py')] |
|
42 docs = [doc for doc in docs if not doc.startswith('__')] |
|
43 |
|
44 for test in docs: |
|
45 fd = open(os.path.join(package_dir, test)) |
|
46 content = fd.read() |
|
47 fd.close() |
|
48 if '>>> ' not in content: |
|
49 continue |
|
50 test = test.replace('.py', '') |
|
51 location = 'pyams_zmq.%s' % test |
|
52 suite.append(doctest.DocTestSuite(location, optionflags=flags, |
|
53 globs=globs)) |
|
54 |
|
55 return unittest.TestSuite(suite) |
|
56 |
|
57 def test_suite(): |
|
58 """returns the test suite""" |
|
59 return doc_suite(current_dir) |
|
60 |
|
61 if __name__ == '__main__': |
|
62 unittest.main(defaultTest='test_suite') |