src/pyams_default_theme/tests/test_utilsdocs.py
changeset 0 ee195bbaf3ed
equal deleted inserted replaced
-1:000000000000 0:ee195bbaf3ed
       
     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_default_theme doctest
       
    15 """
       
    16 __docformat__ = 'restructuredtext'
       
    17 
       
    18 import unittest
       
    19 import doctest
       
    20 import sys
       
    21 import os
       
    22 
       
    23 
       
    24 current_dir = os.path.dirname(__file__)
       
    25 
       
    26 def doc_suite(test_dir, setUp=None, tearDown=None, globs=None):
       
    27     """Returns a test suite, based on doctests found in /doctest."""
       
    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     doctest_dir = os.path.join(package_dir, 'doctests')
       
    40 
       
    41     # filtering files on extension
       
    42     docs = [os.path.join(doctest_dir, doc) for doc in
       
    43             os.listdir(doctest_dir) if doc.endswith('.txt')]
       
    44 
       
    45     for test in docs:
       
    46         suite.append(doctest.DocFileSuite(test, optionflags=flags,
       
    47                                           globs=globs, setUp=setUp,
       
    48                                           tearDown=tearDown,
       
    49                                           module_relative=False))
       
    50 
       
    51     return unittest.TestSuite(suite)
       
    52 
       
    53 def test_suite():
       
    54     """returns the test suite"""
       
    55     return doc_suite(current_dir)
       
    56 
       
    57 if __name__ == '__main__':
       
    58     unittest.main(defaultTest='test_suite')
       
    59