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
'''
- def run(component):
- return (component in
- [entry_point.resolve().__name__ for entry_point in
- pkg_resources.iter_entry_points('pgwui.components')])
+ return pgwui_entry_point('pgwui.components')
- return run
+
+@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
assert get_current_request() is not None
-def test_pgwui_component_entry_point(testdir):
- '''Test the pgwui_component_entry_point fixture
+# 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
- # pgwui_component_entry_point
- def test_pgwui_component_entry_point_there(
- monkeypatch, pgwui_component_entry_point):
- # True when the component is a pgwui.components entry point
- test_name = 'pgwui_example'
+ @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
- class MockEntryPoint():
- def __init__(self, name):
- self.name = name
+ def test_pgwui_component_entry_point(
+ mock_pgwui_entry_point, pgwui_component_entry_point):
+ #Calls pgwui_entry_point
- def resolve(self):
- class MockModule():
- def __init__(self, name):
- self.__name__ = name
+ pgwui_component_entry_point('pgwui_example')
+ mock_pgwui_entry_point.assert_called_once()
- return MockModule(self.name)
- monkeypatch.setattr(
- testing.pkg_resources, 'iter_entry_points',
- lambda *args: [MockEntryPoint(test_name)])
+ # pgwui_check_settings_entry_point
- assert pgwui_component_entry_point(test_name) is True
+ 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()
- def test_pgwui_component_entry_point_not_there(
- monkeypatch, pgwui_component_entry_point):
- # False when the component is not pgwui.components entry point
- monkeypatch.setattr(
- testing.pkg_resources, 'iter_entry_points',
- lambda *args: [])
- assert pgwui_component_entry_point('foo') is False
'''
)