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