summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodolfo Carvalho <rhcarvalho@gmail.com>2017-02-18 22:38:15 +0100
committerRodolfo Carvalho <rhcarvalho@gmail.com>2017-02-20 18:12:03 +0100
commitd9c87a571f03fcd9eb386e4b112de3307d8c27c9 (patch)
treee33c04cbdfa758f115f826767c52b6f98540787c
parentfbc8d14bec58035601b2bfd571c49993c9f907dc (diff)
downloadopenshift-d9c87a571f03fcd9eb386e4b112de3307d8c27c9.tar.gz
openshift-d9c87a571f03fcd9eb386e4b112de3307d8c27c9.tar.bz2
openshift-d9c87a571f03fcd9eb386e4b112de3307d8c27c9.tar.xz
openshift-d9c87a571f03fcd9eb386e4b112de3307d8c27c9.zip
Replace nose yield-style tests w/ pytest fixtures
-rw-r--r--roles/openshift_master_facts/test/conftest.py54
-rw-r--r--roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py221
-rw-r--r--roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py220
3 files changed, 247 insertions, 248 deletions
diff --git a/roles/openshift_master_facts/test/conftest.py b/roles/openshift_master_facts/test/conftest.py
new file mode 100644
index 000000000..e67d24f04
--- /dev/null
+++ b/roles/openshift_master_facts/test/conftest.py
@@ -0,0 +1,54 @@
+import os
+import sys
+
+import pytest
+
+sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins"))
+
+from openshift_master_facts_default_predicates import LookupModule as PredicatesLookupModule # noqa: E402
+from openshift_master_facts_default_priorities import LookupModule as PrioritiesLookupModule # noqa: E402
+
+
+@pytest.fixture()
+def predicates_lookup():
+ return PredicatesLookupModule()
+
+
+@pytest.fixture()
+def priorities_lookup():
+ return PrioritiesLookupModule()
+
+
+@pytest.fixture()
+def facts(request):
+ return {
+ 'openshift': {
+ 'common': {}
+ }
+ }
+
+
+@pytest.fixture(params=[True, False])
+def regions_enabled(request):
+ return request.param
+
+
+@pytest.fixture(params=[True, False])
+def zones_enabled(request):
+ return request.param
+
+
+def v_prefix(release):
+ """Prefix a release number with 'v'."""
+ return "v" + release
+
+
+def minor(release):
+ """Add a suffix to release, making 'X.Y' become 'X.Y.Z'."""
+ return release + ".1"
+
+
+@pytest.fixture(params=[str, v_prefix, minor])
+def release_mod(request):
+ """Modifies a release string to alternative valid values."""
+ return request.param
diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py
index 51547ce7e..bef02e548 100644
--- a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py
+++ b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py
@@ -1,10 +1,5 @@
-import copy
-import os
-import sys
+import pytest
-sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins"))
-
-from openshift_master_facts_default_predicates import LookupModule # noqa: E402
# Predicates ordered according to OpenShift Origin source:
# origin/vendor/k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
@@ -85,123 +80,99 @@ TEST_VARS = [
]
-class TestOpenShiftMasterFactsDefaultPredicates(object):
- lookup = LookupModule()
- default_facts = {
- 'openshift': {
- 'common': {}
- }
- }
+def test_openshift_version(predicates_lookup, openshift_version_fixture, regions_enabled):
+ facts, default_predicates = openshift_version_fixture
+ results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled)
+ if regions_enabled:
+ assert results == default_predicates + [REGION_PREDICATE]
+ else:
+ assert results == default_predicates
+
+
+@pytest.fixture(params=TEST_VARS)
+def openshift_version_fixture(request, facts):
+ version, deployment_type, default_predicates = request.param
+ version += '.1'
+ facts['openshift_version'] = version
+ facts['openshift']['common']['deployment_type'] = deployment_type
+ return facts, default_predicates
+
+
+def test_openshift_release(predicates_lookup, openshift_release_fixture, regions_enabled):
+ facts, default_predicates = openshift_release_fixture
+ results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled)
+ if regions_enabled:
+ assert results == default_predicates + [REGION_PREDICATE]
+ else:
+ assert results == default_predicates
+
+
+@pytest.fixture(params=TEST_VARS)
+def openshift_release_fixture(request, facts, release_mod):
+ release, deployment_type, default_predicates = request.param
+ facts['openshift_release'] = release_mod(release)
+ facts['openshift']['common']['deployment_type'] = deployment_type
+ return facts, default_predicates
+
+
+def test_short_version(predicates_lookup, short_version_fixture, regions_enabled):
+ facts, default_predicates = short_version_fixture
+ results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled)
+ if regions_enabled:
+ assert results == default_predicates + [REGION_PREDICATE]
+ else:
+ assert results == default_predicates
+
+
+@pytest.fixture(params=TEST_VARS)
+def short_version_fixture(request, facts):
+ short_version, deployment_type, default_predicates = request.param
+ facts['openshift']['common']['short_version'] = short_version
+ facts['openshift']['common']['deployment_type'] = deployment_type
+ return facts, default_predicates
+
+
+def test_short_version_kwarg(predicates_lookup, short_version_kwarg_fixture, regions_enabled):
+ facts, short_version, default_predicates = short_version_kwarg_fixture
+ results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled, short_version=short_version)
+ if regions_enabled:
+ assert results == default_predicates + [REGION_PREDICATE]
+ else:
+ assert results == default_predicates
+
+
+@pytest.fixture(params=TEST_VARS)
+def short_version_kwarg_fixture(request, facts):
+ short_version, deployment_type, default_predicates = request.param
+ facts['openshift']['common']['deployment_type'] = deployment_type
+ return facts, short_version, default_predicates
+
+
+def test_deployment_type_kwarg(predicates_lookup, deployment_type_kwarg_fixture, regions_enabled):
+ facts, deployment_type, default_predicates = deployment_type_kwarg_fixture
+ results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled, deployment_type=deployment_type)
+ if regions_enabled:
+ assert results == default_predicates + [REGION_PREDICATE]
+ else:
+ assert results == default_predicates
+
+
+@pytest.fixture(params=TEST_VARS)
+def deployment_type_kwarg_fixture(request, facts):
+ short_version, deployment_type, default_predicates = request.param
+ facts['openshift']['common']['short_version'] = short_version
+ return facts, deployment_type, default_predicates
+
+
+def test_short_version_deployment_type_kwargs(predicates_lookup, short_version_deployment_type_kwargs_fixture, regions_enabled):
+ short_version, deployment_type, default_predicates = short_version_deployment_type_kwargs_fixture
+ results = predicates_lookup.run(None, regions_enabled=regions_enabled, short_version=short_version, deployment_type=deployment_type)
+ if regions_enabled:
+ assert results == default_predicates + [REGION_PREDICATE]
+ else:
+ assert results == default_predicates
+
- def test_openshift_version(self):
- for regions_enabled in (True, False):
- for version, deployment_type, default_predicates in TEST_VARS:
- version = version + '.1'
- yield self.check_defaults_version, version, deployment_type, default_predicates, regions_enabled
-
- def check_defaults_version(self, version, deployment_type, default_predicates,
- regions_enabled):
- facts = copy.deepcopy(self.default_facts)
- facts['openshift_version'] = version
- facts['openshift']['common']['deployment_type'] = deployment_type
- results = self.lookup.run(None, variables=facts,
- regions_enabled=regions_enabled)
- if regions_enabled:
- assert results == default_predicates + [REGION_PREDICATE]
- else:
- assert results == default_predicates
-
- def test_release_defaults(self):
- for regions_enabled in (True, False):
- for release, deployment_type, default_predicates in TEST_VARS:
- yield self.check_defaults_release, release, deployment_type, default_predicates, regions_enabled
-
- def test_v_release_defaults(self):
- for regions_enabled in (True, False):
- for release, deployment_type, default_predicates in TEST_VARS:
- yield self.check_defaults_release, 'v' + release, deployment_type, default_predicates, regions_enabled
-
- def test_trunc_openshift_release(self):
- for release, deployment_type, default_predicates in TEST_VARS:
- release = release + '.1'
- yield self.check_defaults_release, release, deployment_type, default_predicates, False
-
- def check_defaults_release(self, release, deployment_type, default_predicates,
- regions_enabled):
- facts = copy.deepcopy(self.default_facts)
- facts['openshift_release'] = release
- facts['openshift']['common']['deployment_type'] = deployment_type
- results = self.lookup.run(None, variables=facts,
- regions_enabled=regions_enabled)
- if regions_enabled:
- assert results == default_predicates + [REGION_PREDICATE]
- else:
- assert results == default_predicates
-
- def test_short_version_defaults(self):
- for regions_enabled in (True, False):
- for short_version, deployment_type, default_predicates in TEST_VARS:
- yield self.check_defaults_short_version, short_version, deployment_type, default_predicates, regions_enabled
-
- def check_defaults_short_version(self, short_version, deployment_type, default_predicates,
- regions_enabled):
- facts = copy.deepcopy(self.default_facts)
- facts['openshift']['common']['short_version'] = short_version
- facts['openshift']['common']['deployment_type'] = deployment_type
- results = self.lookup.run(None, variables=facts,
- regions_enabled=regions_enabled)
- if regions_enabled:
- assert results == default_predicates + [REGION_PREDICATE]
- else:
- assert results == default_predicates
-
- def test_short_version_kwarg(self):
- for regions_enabled in (True, False):
- for short_version, deployment_type, default_predicates in TEST_VARS:
- yield self.check_defaults_short_version_kwarg, short_version, deployment_type, default_predicates, regions_enabled
-
- def check_defaults_short_version_kwarg(self, short_version, deployment_type, default_predicates,
- regions_enabled):
- facts = copy.deepcopy(self.default_facts)
- facts['openshift']['common']['deployment_type'] = deployment_type
- results = self.lookup.run(None, variables=facts,
- regions_enabled=regions_enabled,
- short_version=short_version)
- if regions_enabled:
- assert results == default_predicates + [REGION_PREDICATE]
- else:
- assert results == default_predicates
-
- def test_deployment_type_kwarg(self):
- for regions_enabled in (True, False):
- for short_version, deployment_type, default_predicates in TEST_VARS:
- yield self.check_defaults_deployment_type_kwarg, short_version, deployment_type, default_predicates, regions_enabled
-
- def check_defaults_deployment_type_kwarg(self, short_version, deployment_type,
- default_predicates, regions_enabled):
- facts = copy.deepcopy(self.default_facts)
- facts['openshift']['common']['short_version'] = short_version
- results = self.lookup.run(None, variables=facts,
- regions_enabled=regions_enabled,
- deployment_type=deployment_type)
- if regions_enabled:
- assert results == default_predicates + [REGION_PREDICATE]
- else:
- assert results == default_predicates
-
- def test_only_kwargs(self):
- for regions_enabled in (True, False):
- for short_version, deployment_type, default_predicates in TEST_VARS:
- yield self.check_defaults_only_kwargs, short_version, deployment_type, default_predicates, regions_enabled
-
- def check_defaults_only_kwargs(self, short_version, deployment_type,
- default_predicates, regions_enabled):
- facts = copy.deepcopy(self.default_facts)
- results = self.lookup.run(None, variables=facts,
- regions_enabled=regions_enabled,
- short_version=short_version,
- deployment_type=deployment_type)
- if regions_enabled:
- assert results == default_predicates + [REGION_PREDICATE]
- else:
- assert results == default_predicates
+@pytest.fixture(params=TEST_VARS)
+def short_version_deployment_type_kwargs_fixture(request):
+ return request.param
diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py
index 4fb900b98..1343acb56 100644
--- a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py
+++ b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py
@@ -1,10 +1,5 @@
-import copy
-import os
-import sys
+import pytest
-sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins"))
-
-from openshift_master_facts_default_priorities import LookupModule # noqa: E402
DEFAULT_PRIORITIES_1_1 = [
{'name': 'LeastRequestedPriority', 'weight': 1},
@@ -73,120 +68,99 @@ TEST_VARS = [
]
-class TestOpenShiftMasterFactsDefaultPredicates(object):
- lookup = LookupModule()
- default_facts = {
- 'openshift': {
- 'common': {}
- }
- }
-
- def test_openshift_version(self):
- for zones_enabled in (True, False):
- for version, deployment_type, default_priorities in TEST_VARS:
- version = version + '.1'
- yield self.check_defaults_version, version, deployment_type, default_priorities, zones_enabled
-
- def check_defaults_version(self, version, deployment_type, default_priorities,
- zones_enabled):
- facts = copy.deepcopy(self.default_facts)
- facts['openshift_version'] = version
- facts['openshift']['common']['deployment_type'] = deployment_type
- results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled)
- if zones_enabled:
- assert results == default_priorities + [ZONE_PRIORITY]
- else:
- assert results == default_priorities
-
- def test_release_defaults(self):
- for zones_enabled in (True, False):
- for release, deployment_type, default_priorities in TEST_VARS:
- yield self.check_defaults_release, release, deployment_type, default_priorities, zones_enabled
-
- def test_v_release_defaults(self):
- for zones_enabled in (True, False):
- for release, deployment_type, default_priorities in TEST_VARS:
- yield self.check_defaults_release, 'v' + release, deployment_type, default_priorities, zones_enabled
-
- def test_trunc_openshift_release(self):
- for release, deployment_type, default_priorities in TEST_VARS:
- release = release + '.1'
- yield self.check_defaults_release, release, deployment_type, default_priorities, False
-
- def check_defaults_release(self, release, deployment_type, default_priorities,
- zones_enabled):
- facts = copy.deepcopy(self.default_facts)
- facts['openshift_release'] = release
- facts['openshift']['common']['deployment_type'] = deployment_type
- results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled)
- if zones_enabled:
- assert results == default_priorities + [ZONE_PRIORITY]
- else:
- assert results == default_priorities
-
- def test_short_version_defaults(self):
- for zones_enabled in (True, False):
- for short_version, deployment_type, default_priorities in TEST_VARS:
- yield self.check_defaults_short_version, short_version, deployment_type, default_priorities, zones_enabled
-
- def check_defaults_short_version(self, short_version, deployment_type,
- default_priorities, zones_enabled):
- facts = copy.deepcopy(self.default_facts)
- facts['openshift']['common']['short_version'] = short_version
- facts['openshift']['common']['deployment_type'] = deployment_type
- results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled)
- if zones_enabled:
- assert results == default_priorities + [ZONE_PRIORITY]
- else:
- assert results == default_priorities
-
- def test_short_version_kwarg(self):
- for zones_enabled in (True, False):
- for short_version, deployment_type, default_priorities in TEST_VARS:
- yield self.check_defaults_short_version_kwarg, short_version, deployment_type, default_priorities, zones_enabled
-
- def check_defaults_short_version_kwarg(self, short_version, deployment_type,
- default_priorities, zones_enabled):
- facts = copy.deepcopy(self.default_facts)
- facts['openshift']['common']['deployment_type'] = deployment_type
- results = self.lookup.run(None, variables=facts,
- zones_enabled=zones_enabled,
- short_version=short_version)
- if zones_enabled:
- assert results == default_priorities + [ZONE_PRIORITY]
- else:
- assert results == default_priorities
-
- def test_deployment_type_kwarg(self):
- for zones_enabled in (True, False):
- for short_version, deployment_type, default_priorities in TEST_VARS:
- yield self.check_defaults_deployment_type_kwarg, short_version, deployment_type, default_priorities, zones_enabled
-
- def check_defaults_deployment_type_kwarg(self, short_version, deployment_type,
- default_priorities, zones_enabled):
- facts = copy.deepcopy(self.default_facts)
- facts['openshift']['common']['short_version'] = short_version
- results = self.lookup.run(None, variables=facts,
- zones_enabled=zones_enabled,
- deployment_type=deployment_type)
- if zones_enabled:
- assert results == default_priorities + [ZONE_PRIORITY]
- else:
- assert results == default_priorities
-
- def test_only_kwargs(self):
- for zones_enabled in (True, False):
- for short_version, deployment_type, default_priorities in TEST_VARS:
- yield self.check_defaults_only_kwargs, short_version, deployment_type, default_priorities, zones_enabled
-
- def check_defaults_only_kwargs(self, short_version, deployment_type,
- default_priorities, zones_enabled):
- facts = copy.deepcopy(self.default_facts)
- results = self.lookup.run(None, variables=facts,
- zones_enabled=zones_enabled,
- short_version=short_version,
- deployment_type=deployment_type)
- if zones_enabled:
- assert results == default_priorities + [ZONE_PRIORITY]
- else:
- assert results == default_priorities
+def test_openshift_version(priorities_lookup, openshift_version_fixture, zones_enabled):
+ facts, default_priorities = openshift_version_fixture
+ results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled)
+ if zones_enabled:
+ assert results == default_priorities + [ZONE_PRIORITY]
+ else:
+ assert results == default_priorities
+
+
+@pytest.fixture(params=TEST_VARS)
+def openshift_version_fixture(request, facts):
+ version, deployment_type, default_priorities = request.param
+ version += '.1'
+ facts['openshift_version'] = version
+ facts['openshift']['common']['deployment_type'] = deployment_type
+ return facts, default_priorities
+
+
+def test_openshift_release(priorities_lookup, openshift_release_fixture, zones_enabled):
+ facts, default_priorities = openshift_release_fixture
+ results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled)
+ if zones_enabled:
+ assert results == default_priorities + [ZONE_PRIORITY]
+ else:
+ assert results == default_priorities
+
+
+@pytest.fixture(params=TEST_VARS)
+def openshift_release_fixture(request, facts, release_mod):
+ release, deployment_type, default_priorities = request.param
+ facts['openshift_release'] = release_mod(release)
+ facts['openshift']['common']['deployment_type'] = deployment_type
+ return facts, default_priorities
+
+
+def test_short_version(priorities_lookup, short_version_fixture, zones_enabled):
+ facts, default_priorities = short_version_fixture
+ results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled)
+ if zones_enabled:
+ assert results == default_priorities + [ZONE_PRIORITY]
+ else:
+ assert results == default_priorities
+
+
+@pytest.fixture(params=TEST_VARS)
+def short_version_fixture(request, facts):
+ short_version, deployment_type, default_priorities = request.param
+ facts['openshift']['common']['short_version'] = short_version
+ facts['openshift']['common']['deployment_type'] = deployment_type
+ return facts, default_priorities
+
+
+def test_short_version_kwarg(priorities_lookup, short_version_kwarg_fixture, zones_enabled):
+ facts, short_version, default_priorities = short_version_kwarg_fixture
+ results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled, short_version=short_version)
+ if zones_enabled:
+ assert results == default_priorities + [ZONE_PRIORITY]
+ else:
+ assert results == default_priorities
+
+
+@pytest.fixture(params=TEST_VARS)
+def short_version_kwarg_fixture(request, facts):
+ short_version, deployment_type, default_priorities = request.param
+ facts['openshift']['common']['deployment_type'] = deployment_type
+ return facts, short_version, default_priorities
+
+
+def test_deployment_type_kwarg(priorities_lookup, deployment_type_kwarg_fixture, zones_enabled):
+ facts, deployment_type, default_priorities = deployment_type_kwarg_fixture
+ results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled, deployment_type=deployment_type)
+ if zones_enabled:
+ assert results == default_priorities + [ZONE_PRIORITY]
+ else:
+ assert results == default_priorities
+
+
+@pytest.fixture(params=TEST_VARS)
+def deployment_type_kwarg_fixture(request, facts):
+ short_version, deployment_type, default_priorities = request.param
+ facts['openshift']['common']['short_version'] = short_version
+ return facts, deployment_type, default_priorities
+
+
+def test_short_version_deployment_type_kwargs(priorities_lookup, short_version_deployment_type_kwargs_fixture, zones_enabled):
+ short_version, deployment_type, default_priorities = short_version_deployment_type_kwargs_fixture
+ results = priorities_lookup.run(None, zones_enabled=zones_enabled, short_version=short_version, deployment_type=deployment_type)
+ if zones_enabled:
+ assert results == default_priorities + [ZONE_PRIORITY]
+ else:
+ assert results == default_priorities
+
+
+@pytest.fixture(params=TEST_VARS)
+def short_version_deployment_type_kwargs_fixture(request):
+ return request.param