From 64f72774deb43e5557142446c920fa97b21ff63e Mon Sep 17 00:00:00 2001 From: Patrick Lannigan Date: Sun, 1 Oct 2023 10:44:26 -0400 Subject: [PATCH] Add test cases to confirm implementation of mock_config() --- testing/test_assertion.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 67cef9735..c58fcf015 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -38,6 +38,41 @@ def mock_config(verbose: int = 0, assertion_override: Optional[int] = None): return Config() +class TestMockConfig: + SOME_VERBOSITY_LEVEL = 3 + SOME_OTHER_VERBOSITY_LEVEL = 10 + + def test_verbose_exposes_value(self): + config = mock_config(verbose=TestMockConfig.SOME_VERBOSITY_LEVEL) + + assert config.output_verbosity.verbose == TestMockConfig.SOME_VERBOSITY_LEVEL + + def test_verbosity_for_assertion_override_not_set_verbose_value(self): + config = mock_config(verbose=TestMockConfig.SOME_VERBOSITY_LEVEL) + + assert ( + config.output_verbosity.verbosity_for("assertions") + == TestMockConfig.SOME_VERBOSITY_LEVEL + ) + + def test_verbosity_for_assertion_override_set_custom_value(self): + config = mock_config( + verbose=TestMockConfig.SOME_VERBOSITY_LEVEL, + assertion_override=TestMockConfig.SOME_OTHER_VERBOSITY_LEVEL, + ) + + assert ( + config.output_verbosity.verbosity_for("assertions") + == TestMockConfig.SOME_OTHER_VERBOSITY_LEVEL + ) + + def test_verbosity_for_unsupported_type_error(self): + config = mock_config(verbose=TestMockConfig.SOME_VERBOSITY_LEVEL) + + with pytest.raises(KeyError): + config.output_verbosity.verbosity_for("NOT CONFIGURED NAME") + + class TestImportHookInstallation: @pytest.mark.parametrize("initial_conftest", [True, False]) @pytest.mark.parametrize("mode", ["plain", "rewrite"])