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