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