src/pyams_template/tests/test_utilsdocstrings.py
changeset 17 e94c6b8d5b50
parent 0 31ded33115d7
equal deleted inserted replaced
16:ac179d1bfc0b 17:e94c6b8d5b50
     1 ### -*- coding: utf-8 -*- ####################################################
       
     2 ##############################################################################
       
     3 #
     1 #
     4 # Copyright (c) 2008-2010 Thierry Florac <tflorac AT ulthar.net>
     2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
     5 # All Rights Reserved.
     3 # All Rights Reserved.
     6 #
     4 #
     7 # This software is subject to the provisions of the Zope Public License,
     5 # 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.
     6 # 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
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
    10 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    11 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
    12 # FOR A PARTICULAR PURPOSE.
    10 # FOR A PARTICULAR PURPOSE.
    13 #
    11 #
    14 ##############################################################################
       
    15 
    12 
    16 """
    13 """
    17 Generic Test case for pyams_template doc strings
    14 Generic Test case for pyams_template doc strings
    18 """
    15 """
       
    16 
       
    17 import doctest
       
    18 import os
       
    19 import sys
       
    20 import unittest
       
    21 
       
    22 
    19 __docformat__ = 'restructuredtext'
    23 __docformat__ = 'restructuredtext'
    20 
    24 
    21 import unittest
    25 CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
    22 import doctest
       
    23 import sys
       
    24 import os
       
    25 
    26 
    26 
       
    27 current_dir = os.path.abspath(os.path.dirname(__file__))
       
    28 
    27 
    29 def doc_suite(test_dir, globs=None):
    28 def doc_suite(test_dir, globs=None):
    30     """Returns a test suite, based on doc tests strings found in /*.py"""
    29     """Returns a test suite, based on doc tests strings found in /*.py"""
    31     suite = []
    30     suite = []
    32     if globs is None:
    31     if globs is None:
    43     docs = [doc for doc in
    42     docs = [doc for doc in
    44             os.listdir(package_dir) if doc.endswith('.py')]
    43             os.listdir(package_dir) if doc.endswith('.py')]
    45     docs = [doc for doc in docs if not doc.startswith('__')]
    44     docs = [doc for doc in docs if not doc.startswith('__')]
    46 
    45 
    47     for test in docs:
    46     for test in docs:
    48         fd = open(os.path.join(package_dir, test))
    47         fd = open(os.path.join(package_dir, test))  # pylint: disable=invalid-name
    49         content = fd.read()
    48         content = fd.read()
    50         fd.close()
    49         fd.close()
    51         if '>>> ' not in content:
    50         if '>>> ' not in content:
    52             continue
    51             continue
    53         test = test.replace('.py', '')
    52         test = test.replace('.py', '')
    55         suite.append(doctest.DocTestSuite(location, optionflags=flags,
    54         suite.append(doctest.DocTestSuite(location, optionflags=flags,
    56                                           globs=globs))
    55                                           globs=globs))
    57 
    56 
    58     return unittest.TestSuite(suite)
    57     return unittest.TestSuite(suite)
    59 
    58 
       
    59 
    60 def test_suite():
    60 def test_suite():
    61     """returns the test suite"""
    61     """returns the test suite"""
    62     return doc_suite(current_dir)
    62     return doc_suite(CURRENT_DIR)
       
    63 
    63 
    64 
    64 if __name__ == '__main__':
    65 if __name__ == '__main__':
    65     unittest.main(defaultTest='test_suite')
    66     unittest.main(defaultTest='test_suite')