From 0967d3e05e2c282d57816b99bdd52bee97d5b656 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 5 May 2019 14:41:39 +0200 Subject: [PATCH] documentation/python: don't add implicit INPUT_MODULES in all tests. Only in the inspect tests, elsewhere it's counterproductive. --- documentation/test_python/__init__.py | 21 ++++++++++++++------- documentation/test_python/test_inspect.py | 12 +++++++----- documentation/test_python/test_layout.py | 2 -- documentation/test_python/test_pybind.py | 8 ++++---- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/documentation/test_python/__init__.py b/documentation/test_python/__init__.py index 1c9a7379..79c69555 100644 --- a/documentation/test_python/__init__.py +++ b/documentation/test_python/__init__.py @@ -54,18 +54,12 @@ class BaseTestCase(unittest.TestCase): 'FAVICON': None, 'LINKS_NAVBAR1': None, 'LINKS_NAVBAR2': None, - # None instead of [] so we can detect even an empty override - 'INPUT_MODULES': None, 'SEARCH_DISABLED': True, 'OUTPUT': os.path.join(self.path, 'output') }) - # Update it with config overrides, specify the input module if not - # already + # Update it with config overrides config.update(config_overrides) - if config['INPUT_MODULES'] is None: - sys.path.append(self.path) - config['INPUT_MODULES'] = [self.dirname] run(self.path, config, templates=templates) @@ -77,3 +71,16 @@ class BaseTestCase(unittest.TestCase): with open(os.path.join(self.path, 'output', actual)) as f: actual_contents = f.read().strip() return actual_contents, expected_contents + +class BaseInspectTestCase(BaseTestCase): + def run_python(self, config_overrides={}, templates=default_templates): + if 'INPUT_MODULES' not in config_overrides: + sys.path.append(self.path) + + # Have to do a deep copy to avoid overwriting the parameter default + # value. UGH. + config = copy.deepcopy(config_overrides) + config['INPUT_MODULES'] = [self.dirname] + config_overrides = config + + BaseTestCase.run_python(self, config_overrides, templates) diff --git a/documentation/test_python/test_inspect.py b/documentation/test_python/test_inspect.py index 4457bc4a..aecaa628 100644 --- a/documentation/test_python/test_inspect.py +++ b/documentation/test_python/test_inspect.py @@ -22,6 +22,7 @@ # DEALINGS IN THE SOFTWARE. # +import copy import math import os import sys @@ -29,9 +30,10 @@ import unittest from distutils.version import LooseVersion -from . import BaseTestCase +from python import default_templates +from . import BaseInspectTestCase -class String(BaseTestCase): +class String(BaseInspectTestCase): def __init__(self, *args, **kwargs): super().__init__(__file__, 'string', *args, **kwargs) @@ -49,7 +51,7 @@ class String(BaseTestCase): self.assertEqual(*self.actual_expected_contents('classes.html')) self.assertEqual(*self.actual_expected_contents('modules.html')) -class Object(BaseTestCase): +class Object(BaseInspectTestCase): def __init__(self, *args, **kwargs): super().__init__(__file__, 'object', *args, **kwargs) @@ -74,7 +76,7 @@ class Object(BaseTestCase): self.assertEqual(*self.actual_expected_contents('classes.html', '../inspect_string/classes.html')) self.assertEqual(*self.actual_expected_contents('modules.html', '../inspect_string/modules.html')) -class AllProperty(BaseTestCase): +class AllProperty(BaseInspectTestCase): def __init__(self, *args, **kwargs): super().__init__(__file__, 'all_property', *args, **kwargs) @@ -82,7 +84,7 @@ class AllProperty(BaseTestCase): self.run_python() self.assertEqual(*self.actual_expected_contents('inspect_all_property.html')) -class Annotations(BaseTestCase): +class Annotations(BaseInspectTestCase): def __init__(self, *args, **kwargs): super().__init__(__file__, 'annotations', *args, **kwargs) diff --git a/documentation/test_python/test_layout.py b/documentation/test_python/test_layout.py index 1d7ca6bb..e74c9508 100644 --- a/documentation/test_python/test_layout.py +++ b/documentation/test_python/test_layout.py @@ -35,8 +35,6 @@ class Layout(BaseTestCase): 'PROJECT_TITLE': "A project", 'PROJECT_SUBTITLE': "is cool", - 'INPUT_MODULES': [], # Explicitly none - 'THEME_COLOR': '#00ffff', 'FAVICON': 'favicon-light.png', 'PAGE_HEADER': "`A self link <{filename}>`_", diff --git a/documentation/test_python/test_pybind.py b/documentation/test_python/test_pybind.py index a03f91d4..2cf73383 100644 --- a/documentation/test_python/test_pybind.py +++ b/documentation/test_python/test_pybind.py @@ -27,7 +27,7 @@ import unittest from python import parse_pybind_signature -from . import BaseTestCase +from . import BaseInspectTestCase class Signature(unittest.TestCase): def test(self): @@ -131,7 +131,7 @@ class Signature(unittest.TestCase): '(arg0: MyClass) -> float'), ('', '', [('arg0', 'MyClass', None)], 'float')) -class Signatures(BaseTestCase): +class Signatures(BaseInspectTestCase): def __init__(self, *args, **kwargs): super().__init__(__file__, 'signatures', *args, **kwargs) @@ -173,7 +173,7 @@ class Signatures(BaseTestCase): self.assertEqual(*self.actual_expected_contents('pybind_signatures.html')) self.assertEqual(*self.actual_expected_contents('pybind_signatures.MyClass.html')) -class Enums(BaseTestCase): +class Enums(BaseInspectTestCase): def __init__(self, *args, **kwargs): super().__init__(__file__, 'enums', *args, **kwargs) @@ -183,7 +183,7 @@ class Enums(BaseTestCase): }) self.assertEqual(*self.actual_expected_contents('pybind_enums.html')) -class Submodules(BaseTestCase): +class Submodules(BaseInspectTestCase): def __init__(self, *args, **kwargs): super().__init__(__file__, 'submodules', *args, **kwargs) -- 2.30.2