Split into 3 modules: plugin fixtures, plugin helpers, testing functions
authorKarl O. Pinc <kop@karlpinc.com>
Tue, 1 Sep 2020 02:13:38 +0000 (21:13 -0500)
committerKarl O. Pinc <kop@karlpinc.com>
Tue, 1 Sep 2020 03:42:02 +0000 (22:42 -0500)
setup.py
src/pgwui_testing/pytest_plugin.py [new file with mode: 0644]
src/pgwui_testing/pytest_plugin_helpers.py [new file with mode: 0644]
src/pgwui_testing/testing.py
tests/test_pytest_plugin.py [new file with mode: 0644]
tests/test_pytest_plugin_helpers.py [new file with mode: 0644]
tests/test_testing.py

index 9f6658077a8b074ef6b6f9ebca397b075b72306d..6a25f0a64de393d4555779f0c771a7357a748514 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -163,6 +163,6 @@ setup(
     #     ],
     # },
     entry_points={
-        'pytest11': ['pgwui = pgwui_testing.testing'],
+        'pytest11': ['pgwui = pgwui_testing.pytest_plugin'],
     },
 )
diff --git a/src/pgwui_testing/pytest_plugin.py b/src/pgwui_testing/pytest_plugin.py
new file mode 100644 (file)
index 0000000..025e55d
--- /dev/null
@@ -0,0 +1,62 @@
+# Copyright (C) 2015, 2018, 2020 The Meme Factory, Inc.
+# http://www.karlpinc.com/
+
+# This file is part of PGWUI_Testing.
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program 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
+# Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
+#
+
+# Karl O. Pinc <kop@karlpinc.com>
+
+from pytest import (
+    fixture,
+)
+from pyramid.testing import (
+    DummyRequest,
+    setUp,
+    tearDown
+)
+
+from pgwui_testing import pytest_plugin_helpers
+
+
+# Fixtures
+
+@fixture
+def pyramid_config():
+    yield setUp()
+    tearDown()
+
+
+@fixture
+def pyramid_request_config():
+    request = DummyRequest()
+    yield setUp(request=request)
+    tearDown()
+
+
+@fixture
+def pgwui_component_entry_point():
+    '''Test that the supplied pgwui component is a pgui.components entry point
+    '''
+    return pytest_plugin_helpers.pgwui_entry_point('pgwui.components')
+
+
+@fixture
+def pgwui_check_settings_entry_point():
+    '''Test that the supplied pgwui component is a pgwui.check_settings
+    entry point
+    '''
+    return pytest_plugin_helpers.pgwui_entry_point('pgwui.check_settings')
diff --git a/src/pgwui_testing/pytest_plugin_helpers.py b/src/pgwui_testing/pytest_plugin_helpers.py
new file mode 100644 (file)
index 0000000..da1cbf2
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright (C) 2015, 2018, 2020 The Meme Factory, Inc.
+# http://www.karlpinc.com/
+
+# This file is part of PGWUI_Testing.
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program 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
+# Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
+#
+
+# Karl O. Pinc <kop@karlpinc.com>
+
+'''Functions used by the pytest_plugin module.
+'''
+
+import pkg_resources
+
+
+def pgwui_entry_point(ep_name):
+    '''Test that the supplied pgwui component is a entry point with the
+    given name
+    '''
+    def run(module):
+        return (module in
+                [entry_point.module_name for entry_point in
+                 pkg_resources.iter_entry_points(ep_name)])
+
+    return run
index 23cad3bd3f31f5020e2f3026ab0d6f2fb4e4984c..8b8c3e08e4852b15620bcbfb27554b7d6390c814 100644 (file)
 
 # Karl O. Pinc <kop@karlpinc.com>
 
-import pkg_resources
+from pytest import fixture
 from unittest import mock
 
-from pytest import (
-    fixture,
-)
-from pyramid.testing import (
-    DummyRequest,
-    setUp,
-    tearDown
-)
-
-
-# Fixtures
-
-@fixture
-def pyramid_config():
-    yield setUp()
-    tearDown()
-
-
-@fixture
-def pyramid_request_config():
-    request = DummyRequest()
-    yield setUp(request=request)
-    tearDown()
-
-
-def pgwui_entry_point(ep_name):
-    '''Test that the supplied pgwui component is a entry point with the
-    given name
-    '''
-    def run(module):
-        return (module in
-                [entry_point.module_name for entry_point in
-                 pkg_resources.iter_entry_points(ep_name)])
-
-    return run
-
-
-@fixture
-def pgwui_component_entry_point():
-    '''Test that the supplied pgwui component is a pgui.components entry point
-    '''
-    return pgwui_entry_point('pgwui.components')
-
-
-@fixture
-def pgwui_check_settings_entry_point():
-    '''Test that the supplied pgwui component is a pgwui.check_settings
-    entry point
-    '''
-    return pgwui_entry_point('pgwui.check_settings')
-
 
 # Mock support
 
diff --git a/tests/test_pytest_plugin.py b/tests/test_pytest_plugin.py
new file mode 100644 (file)
index 0000000..6f03215
--- /dev/null
@@ -0,0 +1,108 @@
+# Copyright (C) 2018, 2019, 2020 The Meme Factory, Inc.
+# http://www.karlpinc.com/
+
+# This file is part of PGWUI_Testing.
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program 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
+# Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
+#
+
+# Karl O. Pinc <kop@karlpinc.com>
+
+# See: https://pytest-cov.readthedocs.io/en/latest/plugins.html
+
+# Allow use of the testdir fixture
+pytest_plugins = ("pytester",)
+
+
+# Test fixtures
+
+
+# pgwui_component_entry_point()
+# pgwui_check_settings_entry_point()
+
+def test_pgwui_testing_fixtures(testdir):
+    '''Test the fixtures supplied by the pytest_plugin module
+    '''
+    testdir.makepyfile(
+        '''
+        from pgwui_testing import pytest_plugin_helpers
+        import pytest
+
+        from unittest import mock
+
+        from pyramid.config import (
+            Configurator
+        )
+        from pyramid.threadlocal import (
+            get_current_request
+        )
+
+
+        # Activiate our pytest plugin
+        pytest_plugins = ("pgwui_testing",)
+
+        # pyramid_config
+
+        def test_pyramid_config(pyramid_config):
+            # A pyramid_config is a Configurator instance
+            result = pyramid_config
+            assert isinstance(result, Configurator)
+
+
+        # pyramid_test_config
+
+        def test_pyramid_request_config(pyramid_request_config):
+            # Is a Configurator instance and has a non-None request
+            result = pyramid_request_config
+            assert isinstance(result, Configurator)
+            assert get_current_request() is not None
+
+
+        @pytest.fixture
+        def mock_pgwui_entry_point(monkeypatch):
+            mocked = mock.Mock(
+                spec=getattr(pytest_plugin_helpers, 'pgwui_entry_point'),
+                name='pgwui_entry_point')
+            monkeypatch.setattr(pytest_plugin_helpers, 'pgwui_entry_point',
+                                 mocked)
+            return mocked
+
+
+        # pgwui_component_entry_point
+
+        def test_pgwui_component_entry_point(
+                mock_pgwui_entry_point, pgwui_component_entry_point):
+            #Calls pgwui_entry_point
+
+            pgwui_component_entry_point('pgwui_example')
+            mock_pgwui_entry_point.assert_called_once()
+
+
+        # pgwui_check_settings_entry_point
+
+        def test_pgwui_check_settings_entry_point(
+                mock_pgwui_entry_point, pgwui_check_settings_entry_point):
+            #Calls pgwui_entry_point
+
+            pgwui_check_settings_entry_point('pgwui_example')
+            mock_pgwui_entry_point.assert_called_once()
+
+
+        '''
+    )
+
+    result = testdir.runpytest()
+
+    result.assert_outcomes(passed=4)
diff --git a/tests/test_pytest_plugin_helpers.py b/tests/test_pytest_plugin_helpers.py
new file mode 100644 (file)
index 0000000..09cb066
--- /dev/null
@@ -0,0 +1,56 @@
+# Copyright (C) 2020 The Meme Factory, Inc.
+# http://www.karlpinc.com/
+
+# This file is part of PGWUI_Testing.
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program 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
+# Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
+#
+
+# Karl O. Pinc <kop@karlpinc.com>
+
+# See: https://pytest-cov.readthedocs.io/en/latest/plugins.html
+
+from pgwui_testing import pytest_plugin_helpers
+
+
+# pgwui_entry_point()
+
+def test_pgwui_entry_point_there(monkeypatch):
+    '''True when the component is a pgwui.components entry point
+    '''
+    test_name = 'pgwui_example'
+
+    class MockEntryPoint():
+        def __init__(self, module_name):
+            self.module_name = module_name
+
+    monkeypatch.setattr(
+        pytest_plugin_helpers.pkg_resources, 'iter_entry_points',
+        lambda *args: [MockEntryPoint(test_name)])
+
+    assert (
+        pytest_plugin_helpers.pgwui_entry_point(test_name)(test_name)
+        is True)
+
+
+def test_pgwui_entry_point_not_there(monkeypatch):
+    '''False when the component is not pgwui.components entry point
+    '''
+    monkeypatch.setattr(
+        pytest_plugin_helpers.pkg_resources, 'iter_entry_points',
+        lambda *args: [])
+
+    assert (pytest_plugin_helpers.pgwui_entry_point('foo')('foo')
+            is False)
index 500a54bd642fc9890cb47e02710cef9bb0a7fb3c..28c2c722946caa030413f28382a2ccaf96a45c8d 100644 (file)
 
 # See: https://pytest-cov.readthedocs.io/en/latest/plugins.html
 
+
 import sys
 
 from pgwui_testing import testing
 
-from pyramid.config import (
-    Configurator
-)
-from pyramid.threadlocal import (
-    get_current_request
-)
-
-
-# Activiate our pytest plugin
-pytest_plugins = ("pgwui_testing",
-                  "pytester")
-
-# Test fixtures
-
-
-# pyramid_config
-
-def test_pyramid_config(pyramid_config):
-    # A pyramid_config is a Configurator instance
-    result = pyramid_config
-    assert isinstance(result, Configurator)
-
-
-# pyramid_test_config
-
-def test_pyramid_request_config(pyramid_request_config):
-    # Is a Configurator instance and has a non-None request
-    result = pyramid_request_config
-    assert isinstance(result, Configurator)
-    assert get_current_request() is not None
-
-
-# pgwui_entry_point()
-
-def test_pgwui_entry_point_there(monkeypatch):
-    # True when the component is a pgwui.components entry point
-    test_name = 'pgwui_example'
-
-    class MockEntryPoint():
-        def __init__(self, module_name):
-            self.module_name = module_name
-
-    monkeypatch.setattr(
-        testing.pkg_resources, 'iter_entry_points',
-        lambda *args: [MockEntryPoint(test_name)])
-
-    assert testing.pgwui_entry_point(test_name)(test_name) is True
-
-
-def test_pgwui_entry_point_not_there(monkeypatch):
-    # False when the component is not pgwui.components entry point
-    monkeypatch.setattr(
-        testing.pkg_resources, 'iter_entry_points',
-        lambda *args: [])
-
-    assert testing.pgwui_entry_point('foo')('foo') is False
-
-
-# pgwui_component_entry_point()
-# pgwui_check_settings_entry_point()
-
-def test_pgwui_testing_fixtures(testdir):
-    '''Test the fixtures supplied by the testing module
-    '''
-    testdir.makepyfile(
-        '''
-        import pgwui_testing.testing as testing
-        import pytest
-
-        from unittest import mock
-
-
-        @pytest.fixture
-        def mock_pgwui_entry_point(monkeypatch):
-            mocked = mock.Mock(
-                spec=getattr(testing, 'pgwui_entry_point'),
-                name='pgwui_entry_point')
-            monkeypatch.setattr(testing, 'pgwui_entry_point', mocked)
-            return mocked
-
-
-        # pgwui_component_entry_point
-
-        def test_pgwui_component_entry_point(
-                mock_pgwui_entry_point, pgwui_component_entry_point):
-            #Calls pgwui_entry_point
-
-            pgwui_component_entry_point('pgwui_example')
-            mock_pgwui_entry_point.assert_called_once()
-
-
-        # pgwui_check_settings_entry_point
-
-        def test_pgwui_check_settings_entry_point(
-                mock_pgwui_entry_point, pgwui_check_settings_entry_point):
-            #Calls pgwui_entry_point
-
-            pgwui_check_settings_entry_point('pgwui_example')
-            mock_pgwui_entry_point.assert_called_once()
-
-
-        '''
-    )
-
-    result = testdir.runpytest()
-
-    result.assert_outcomes(passed=2)
-
 
 # Test functions
 
@@ -151,8 +44,8 @@ mocked_func = testing.make_mock_fixture(
 
 
 def test_make_mock_fixture_fixture(mocked_func):
-    '''The mock of the function works
-    '''
+    The mock of the function works
+
     test_value = 'test value'
     mocked_func.return_value = test_value
     result = mocked_func()
@@ -178,8 +71,8 @@ mocked_method = testing.instance_method_mock_fixture('method_to_mock')
 
 
 def test_instance_method_mock_fixture(mocked_method):
-    '''The mock of the instance method works
-    '''
+    The mock of the instance method works
+
     test_value = 'mocked value'
     cls = TestClass()
     mocked_method(cls).return_value = test_value
@@ -190,8 +83,8 @@ def test_instance_method_mock_fixture(mocked_method):
 
 
 def test_instance_method_mock_fixture_unmocked():
-    '''The test class works after the mocking
-    '''
+    The test class works after the mocking
+
     cls = TestClass()
     result = cls.method_to_mock()