src/pyams_pagelet/tests/test_utilsdocstrings.py
changeset 12 fc3542685741
parent 0 44692d47182f
equal deleted inserted replaced
11:bd5143e87b1d 12:fc3542685741
    12 
    12 
    13 """
    13 """
    14 Generic Test case for pyams_pagelet doc strings
    14 Generic Test case for pyams_pagelet doc strings
    15 """
    15 """
    16 
    16 
       
    17 import doctest
       
    18 import os
       
    19 import sys
       
    20 import unittest
       
    21 
       
    22 
    17 __docformat__ = 'restructuredtext'
    23 __docformat__ = 'restructuredtext'
    18 
    24 
    19 import unittest
    25 CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
    20 import doctest
       
    21 import sys
       
    22 import os
       
    23 
    26 
    24 
       
    25 current_dir = os.path.abspath(os.path.dirname(__file__))
       
    26 
    27 
    27 def doc_suite(test_dir, globs=None):
    28 def doc_suite(test_dir, globs=None):
    28     """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"""
    29     suite = []
    30     suite = []
    30     if globs is None:
    31     if globs is None:
    41     docs = [doc for doc in
    42     docs = [doc for doc in
    42             os.listdir(package_dir) if doc.endswith('.py')]
    43             os.listdir(package_dir) if doc.endswith('.py')]
    43     docs = [doc for doc in docs if not doc.startswith('__')]
    44     docs = [doc for doc in docs if not doc.startswith('__')]
    44 
    45 
    45     for test in docs:
    46     for test in docs:
    46         fd = open(os.path.join(package_dir, test))
    47         fd = open(os.path.join(package_dir, test))  # pylint: disable=invalid-name
    47         content = fd.read()
    48         content = fd.read()
    48         fd.close()
    49         fd.close()
    49         if '>>> ' not in content:
    50         if '>>> ' not in content:
    50             continue
    51             continue
    51         test = test.replace('.py', '')
    52         test = test.replace('.py', '')
    53         suite.append(doctest.DocTestSuite(location, optionflags=flags,
    54         suite.append(doctest.DocTestSuite(location, optionflags=flags,
    54                                           globs=globs))
    55                                           globs=globs))
    55 
    56 
    56     return unittest.TestSuite(suite)
    57     return unittest.TestSuite(suite)
    57 
    58 
       
    59 
    58 def test_suite():
    60 def test_suite():
    59     """returns the test suite"""
    61     """returns the test suite"""
    60     return doc_suite(current_dir)
    62     return doc_suite(CURRENT_DIR)
       
    63 
    61 
    64 
    62 if __name__ == '__main__':
    65 if __name__ == '__main__':
    63     unittest.main(defaultTest='test_suite')
    66     unittest.main(defaultTest='test_suite')