Only turn introspection on during development
authorKarl O. Pinc <kop@karlpinc.com>
Tue, 8 Dec 2020 05:13:53 +0000 (23:13 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Tue, 8 Dec 2020 20:31:53 +0000 (14:31 -0600)
src/pgwui_server/pgwui_server.py
tests/test_pgwui_server.py

index ad556b2b84adf189b8123fd5ba5c2b960e40861b..a85aa58fbf730371623550cd29b3aba128becd7a 100644 (file)
@@ -204,10 +204,28 @@ def autoconfigurable_components(settings, components):
     return components
 
 
+def in_development(settings):
+    '''Boolean: Whether or not the pyramid testing pack is installed
+    '''
+    pyramid_includes = settings.get('pyramid.includes', [])
+    if isinstance(pyramid_includes, str):
+        if '\n' in pyramid_includes:
+            pyramid_includes = pyramid_includes.splitlines()
+        else:
+            pyramid_includes = pyramid_includes.split(' ')
+    result = 'pyramid_debugtoolbar' in pyramid_includes
+    log.debug(
+        f'pyramid_debugtoolbar included: {result}  '
+        f'So introspection set to: {result}')
+    return result
+
+
 def apply_component_defaults(settings, components):
     '''Apply component default settings to existing settings
     '''
-    with Configurator(settings=settings) as config:
+    introspection = in_development(settings)
+    with Configurator(settings=settings,
+                      introspection=introspection) as config:
         config.include('pgwui_common')
 
         components_to_config = autoconfigurable_components(
index 4090563d123e9dfdd39d6f4b0a9698cadfca491e..be52e3afd3a8e49a20821f994b9aa10265f0d822 100644 (file)
@@ -506,9 +506,48 @@ mock_autoconfigurable_components = testing.make_mock_fixture(
     pgwui_server, 'autoconfigurable_components')
 
 
+# in_development()
+
+@pytest.mark.parametrize(
+    ('settings', 'expected'), [
+        ({},
+         False),
+        ({'pyramid.includes': 'unrecognized'},
+         False),
+        ({'pyramid.includes': '\nunrecognized'},
+         False),
+        ({'pyramid.includes': ['unrecognized']},
+         False),
+        ({'pyramid.includes': '\nunrecognized\npyramid_debugtoolbar'},
+         True),
+        ({'pyramid.includes': 'unrecognized pyramid_debugtoolbar'},
+         True),
+        ({'pyramid.includes': 'pyramid_debugtoolbar'},
+         True),
+        ({'pyramid.includes': '\npyramid_debugtoolbar'},
+         True),
+        ({'pyramid.includes': ['unrecognized', 'pyramid_debugtoolbar']},
+         True)])
+def test_in_development(caplog, settings, expected):
+    '''Do the settings yield the expected result?
+    '''
+    caplog.set_level(logging.DEBUG)
+    result = pgwui_server.in_development(settings)
+
+    assert result == expected
+    logs = caplog.record_tuples
+    assert len(logs) == 1
+    assert logs[0][1] == logging.DEBUG
+
+
+mock_in_development = testing.make_mock_fixture(
+    pgwui_server, 'in_development')
+
+
 # apply_component_defaults()
 
 def test_apply_component_defaults(caplog,
+                                  mock_in_development,
                                   MockConfigurator,
                                   mock_autoconfigurable_components,
                                   mock_add_routes):