-# 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.
#
# 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)
# 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)
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
exclude = .tox,*.egg,build,data,devel
select = E,W,F
ignore = W503
+
+[tool:pytest]
+addopts = --cov --cov-append
\ No newline at end of file