diff options
author | OpenShift Bot <eparis+openshiftbot@redhat.com> | 2017-03-28 07:54:59 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-28 07:54:59 -0500 |
commit | e9a4e751bc28f43583087ce6502a36c5d83cf30d (patch) | |
tree | 9a5f816d8dd5c40d6b682fe514ce41fd4435d4cb /roles/openshift_health_checker/test/openshift_check_test.py | |
parent | 0d38f04595fc2098cf8304faf20e15e62f43955c (diff) | |
parent | d6cf72a4f488d8c275bfbaf27620ff716da1ae5d (diff) | |
download | openshift-e9a4e751bc28f43583087ce6502a36c5d83cf30d.tar.gz openshift-e9a4e751bc28f43583087ce6502a36c5d83cf30d.tar.bz2 openshift-e9a4e751bc28f43583087ce6502a36c5d83cf30d.tar.xz openshift-e9a4e751bc28f43583087ce6502a36c5d83cf30d.zip |
Merge pull request #3745 from rhcarvalho/checks-unit-tests
Merged by openshift-bot
Diffstat (limited to 'roles/openshift_health_checker/test/openshift_check_test.py')
-rw-r--r-- | roles/openshift_health_checker/test/openshift_check_test.py | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/roles/openshift_health_checker/test/openshift_check_test.py b/roles/openshift_health_checker/test/openshift_check_test.py index c4c8cd1c2..e3153979c 100644 --- a/roles/openshift_health_checker/test/openshift_check_test.py +++ b/roles/openshift_health_checker/test/openshift_check_test.py @@ -1,6 +1,7 @@ import pytest -from openshift_checks import get_var, OpenShiftCheckException +from openshift_checks import OpenShiftCheck, OpenShiftCheckException +from openshift_checks import load_checks, get_var # Fixtures @@ -22,6 +23,64 @@ def missing_keys(request): # Tests +def test_OpenShiftCheck_init(): + class TestCheck(OpenShiftCheck): + name = "test_check" + run = NotImplemented + + # initialization requires at least one argument (apart from self) + with pytest.raises(TypeError) as excinfo: + TestCheck() + assert 'execute_module' in str(excinfo.value) + assert 'module_executor' in str(excinfo.value) + + execute_module = object() + + # initialize with positional argument + check = TestCheck(execute_module) + # new recommended name + assert check.execute_module == execute_module + # deprecated attribute name + assert check.module_executor == execute_module + + # initialize with keyword argument, recommended name + check = TestCheck(execute_module=execute_module) + # new recommended name + assert check.execute_module == execute_module + # deprecated attribute name + assert check.module_executor == execute_module + + # initialize with keyword argument, deprecated name + check = TestCheck(module_executor=execute_module) + # new recommended name + assert check.execute_module == execute_module + # deprecated attribute name + assert check.module_executor == execute_module + + +def test_subclasses(): + """OpenShiftCheck.subclasses should find all subclasses recursively.""" + class TestCheck1(OpenShiftCheck): + pass + + class TestCheck2(OpenShiftCheck): + pass + + class TestCheck1A(TestCheck1): + pass + + local_subclasses = set([TestCheck1, TestCheck1A, TestCheck2]) + known_subclasses = set(OpenShiftCheck.subclasses()) + + assert local_subclasses - known_subclasses == set(), "local_subclasses should be a subset of known_subclasses" + + +def test_load_checks(): + """Loading checks should load and return Python modules.""" + modules = load_checks() + assert modules + + @pytest.mark.parametrize("keys,expected", [ (("foo",), 42), (("bar", "baz"), "openshift"), |