chiark / gitweb /
documentation/python: don't add implicit INPUT_MODULES in all tests.
authorVladimír Vondruš <mosra@centrum.cz>
Sun, 5 May 2019 12:41:39 +0000 (14:41 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Tue, 21 May 2019 12:42:12 +0000 (14:42 +0200)
Only in the inspect tests, elsewhere it's counterproductive.

documentation/test_python/__init__.py
documentation/test_python/test_inspect.py
documentation/test_python/test_layout.py
documentation/test_python/test_pybind.py

index 1c9a7379ae7932cbbd064f8a66bf4df843eb8d14..79c69555c3be9de8f48bbef6118f4609928eee23 100644 (file)
@@ -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)
index 4457bc4a2779060a7db70f0b939a170319fed0c0..aecaa62876d6c960658b87e638320840574fff80 100644 (file)
@@ -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)
 
index 1d7ca6bbc7903d7a404a2b1aa1de33c2d489110c..e74c9508b4d4e5c1a644251963a8c44f079466ef 100644 (file)
@@ -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}>`_",
index a03f91d4eba4d426e6ff94ba4068bf80318e406d..2cf7338321be3d17f424169c180c0b877f109e66 100644 (file)
@@ -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)