New fixture to test that distribution is pgwui pluggable
authorKarl O. Pinc <kop@karlpinc.com>
Thu, 26 Dec 2019 22:27:37 +0000 (16:27 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Thu, 26 Dec 2019 22:27:37 +0000 (16:27 -0600)
.gitignore
Makefile
README.rst
setup.cfg
setup.py
src/pgwui_testing/testing.py
tests/test_testing.py
tox.ini

index a550952edce6d0beb0ccf0fe0be2fbd8bd5ad4ef..bd5d3f5928d1696dd3cf90fa1d3e7cfaed842a15 100644 (file)
@@ -1,6 +1,7 @@
 __pycache__/
 .cache/
 .coverage
+.coverage.*
 .tox/
 build/
 devel/
index ef832dfa6e95e12cb16850a7814485fd43ba93e7..7078d697d11adafa6287eaf58808a63736743a52 100644 (file)
--- a/Makefile
+++ b/Makefile
 PGWUI_NAME := testing
 
 include Makefile_pgwui.mk
+
+
+# For check
+export COV_CORE_SOURCE   := pgwui_testing
+export COV_CORE_CONFIG   := .coveragerc
+export COV_CORE_DATAFILE := .coverage.eager
+
+# For clean
+COVERAGE_STUFF := $(COVERAGE_STUFF) .coverage.*
index f97451d48991aa7676fd31b3b96e896a7577621a..6b9b7cce44c3be863aecde1b0a5c5461e38ce231 100644 (file)
 
 .. #End Of Copyright Marker#
 
+.. Bugs:  (Due to fixture testing)
+   "make check" picks up tox tests
+   "make run_tests" leaves .coverage.eager.* files about
+   Probably we need to get rid of the .coverage files in both cases.
+     (removing .coverage fixes "make check" pickup of tox dirs)
+
 PGWUI_Testing
 =============
 
index 24eff81ceb4a7cc2e7d96435ae1ab214e109a627..f290ea58df198f9afc4f85c1cc334662690c6c60 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,3 +1,10 @@
 [bdist_wheel]
 # Work with both python 2 and 3.
 universal=1
+
+[tool:pytest]
+# Tell coverage to turn on and append results so that when we
+# test we don't lose coverage due to warnings of previously having
+# imported a module.  Necessary for testing fixtures.
+# See: https://pytest-cov.readthedocs.io/en/latest/plugins.html
+addopts = --cov --cov-append
index 8d3f30653f016b9da751d413cb182cc842ed0dfc..d17903f0cfb56cd58b0722079168c8cd5eaefb0b 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -129,6 +129,7 @@ setup(
 
     # Run-time dependencies.
     install_requires=[
+        'setuptools',        # for pkg_resources module
         'pyramid',
         'WebTest >= 1.3.1',  # py3 compat
         'pytest>=3.7.4',
index d5763c1fc57148fc1d5f7de835a6d79e2e43acde..fb567fa36d48b5767a574c4ae9582894bd6c0bb2 100644 (file)
@@ -19,6 +19,8 @@
 
 # Karl O. Pinc <kop@meme.com>
 
+import pkg_resources
+
 from pytest import (
     fixture,
 )
@@ -42,3 +44,15 @@ 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
+    '''
+    def run(component):
+        return (component in
+                [entry_point.resolve().__name__ for entry_point in
+                 pkg_resources.iter_entry_points('pgwui.components')])
+
+    return run
index 29f57836abb2d7efeef755d1e9968d4e028847ff..13063bbc9a8daf05498826442b162606744cdb88 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2018 The Meme Factory, Inc.  http://www.meme.com/
+# Copyright (C) 2018, 2019 The Meme Factory, Inc.  http://www.meme.com/
 
 # This file is part of PGWUI_Testing.
 #
@@ -30,15 +30,16 @@ from pyramid.threadlocal import (
 
 
 # Activiate our pytest plugin
-pytest_plugins = ("pgwui",)
-
+pytest_plugins = ("pgwui_testing",
+                  "pytester")
 
 # Test fixtures
 
+
 # pyramid_config
 
 def test_pyramid_config(pyramid_config):
-    '''A pyramid_config is a Configurator instance'''
+    # A pyramid_config is a Configurator instance
     result = pyramid_config
     assert isinstance(result, Configurator)
 
@@ -46,7 +47,57 @@ def test_pyramid_config(pyramid_config):
 # pyramid_test_config
 
 def test_pyramid_request_config(pyramid_request_config):
-    '''Is a Configurator instance and has a non-None request'''
+    # 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
+
+
+def test_pgwui_component_entry_point(testdir):
+    '''Test the pgwui_component_entry_point fixture
+    '''
+    testdir.makepyfile(
+        '''
+        import pgwui_testing.testing as testing
+        import pytest
+
+
+        # 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'
+
+            class MockEntryPoint():
+                def __init__(self, name):
+                    self.name = name
+
+                def resolve(self):
+                    class MockModule():
+                        def __init__(self, name):
+                            self.__name__ = name
+
+                    return MockModule(self.name)
+
+            monkeypatch.setattr(
+                testing.pkg_resources, 'iter_entry_points',
+                lambda *args: [MockEntryPoint(test_name)])
+
+            assert pgwui_component_entry_point(test_name) is True
+
+
+        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
+        '''
+    )
+
+    result = testdir.runpytest()
+
+    result.assert_outcomes(passed=2)
diff --git a/tox.ini b/tox.ini
index 3c38d58571b962878f1853bc72c02f48debbda52..36271087968644aba884f81a50a2864282e9ca5d 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -15,12 +15,24 @@ deps =
     pytest-cov
     twine
     # coverage
+
+# Tell coverage to turn on and append results so that when we
+# test we don't lose coverage due to warnings of previously having
+# imported a module.  Necessary for testing fixtures.
+# (Also, in commands=,  we don't: --cov=pgwui_testing)
+# (And, we have the [tool:pytest] section.)
+# See: https://pytest-cov.readthedocs.io/en/latest/plugins.html
+setenv =
+    COV_CORE_SOURCE=
+    COV_CORE_CONFIG={toxinidir}/.coveragerc
+    COV_CORE_DATAFILE={toxinidir}/.coverage.eager
+
 commands =
     check-manifest
     python setup.py sdist
     twine check dist/*
     flake8 .
-    py.test --cov=pgwui_testing tests/
+    py.test --cov --cov-append tests/
     # coverage run  --source src/testing -m py.test
     # coverage report
 
@@ -28,3 +40,6 @@ commands =
 exclude = .tox,*.egg,build,data,devel
 select = E,W,F
 ignore = W503
+
+[tool:pytest]
+addopts = --cov --cov-append
\ No newline at end of file