"""A module for testing examples within docstrings.This module checks all other modules in the packageand ensures that the examples within each docstringare executed properly and obtain the expected output."""# Import external modulesimportdoctestimportunittestfromosimportpathfromglobimportglobfromsysimportplatform
[docs]classTestDocstringExamples(unittest.TestCase):"""Class to test examples within docstrings. """
[docs]deftest_docstring_python_examples(self,examples=True):"""Function to test examples within docstrings. Args: examples (bool, optional, default=True): Whether to test examples. Returns: int: The total number of failures from all files. """tests_dir=path.dirname(__file__)files=glob(path.join(tests_dir,'./*.py'))files+=glob(path.join(tests_dir,'../*.py'))ifexamples:files+=glob(path.join(tests_dir,'../examples/*.py'))else:# pragma: no coverifplatform=='win32'orplatform=='win64':files.remove(glob(path.join(tests_dir,'..\\swfjc.py'))[0])else:files.remove(glob(path.join(tests_dir,'../swfjc.py'))[0])forfileinfiles:self.assertFalse(doctest.testfile(file,module_relative=False)[0])
if__name__=='__main__':# pragma: no coverunittest.main()