From: Thomas Fillon Date: Thu, 7 Nov 2013 12:55:32 +0000 (+0100) Subject: Add a test collecting all doctests X-Git-Tag: 0.5.1-0~3 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=fb123e3751bd0736fbc44098ff435199ece3b849;p=timeside.git Add a test collecting all doctests --- diff --git a/tests/test_run_all_doctests.py b/tests/test_run_all_doctests.py new file mode 100644 index 0000000..47bc4b6 --- /dev/null +++ b/tests/test_run_all_doctests.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2007-2013 Parisson SARL + +# This file is part of TimeSide. + +# TimeSide is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. + +# TimeSide is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with TimeSide. If not, see . + +# Authors: +# Thomas Fillon + + +import unittest +import doctest +import timeside +import pkgutil + + +def load_tests(loader, tests, ignore): + + import fnmatch + import os + + finder = doctest.DocTestFinder(exclude_empty=False) + + timeside_path = os.path.dirname(timeside.__path__[0]) + + # Create tests for doctest ReST files + rst_files = [] + for root, dirnames, filenames in os.walk(timeside_path): + for filename in fnmatch.filter(filenames, '*.rst'): + rst_files.append(os.path.join(root, filename)) + + for filename in rst_files: + tests.addTests(doctest.DocFileSuite(filename, module_relative=False)) + + # Create tests for doctest in timeside modules and sub-modules + modules_list = [modname for _, modname, _ in pkgutil.walk_packages( + path=timeside.__path__, + prefix=timeside.__name__ + '.', + onerror=lambda x: None)] + + for module in modules_list: + tests.addTests(doctest.DocTestSuite(module, test_finder=finder)) + + return tests + + +if __name__ == '__main__': + unittest.main()