# ],
# },
entry_points={
- 'pytest11': ['pgwui = pgwui_testing.testing'],
+ 'pytest11': ['pgwui = pgwui_testing.pytest_plugin'],
},
)
--- /dev/null
+# 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')
--- /dev/null
+# 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
# 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
--- /dev/null
+# 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)
--- /dev/null
+# 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)
# 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
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()
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
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()