def test_api_redirect(): root = _create_test_config() # one section level root.add( "test__section_redirect", "A config var from a test case.", configparser.StrParam("test_default"), ) assert hasattr(root, "test__section_redirect") assert root.test__section_redirect == "test_default" assert hasattr(root, "test") assert isinstance(root.test, configparser._SectionRedirect) with pytest.warns(DeprecationWarning): assert root.test.section_redirect == "test_default" # two section levels root.add( "test__subsection__redirect", "A config var from a test case.", configparser.StrParam("test_default2"), ) assert hasattr(root, "test__subsection__redirect") assert root.test__subsection__redirect == "test_default2" with pytest.warns(DeprecationWarning): assert root.test.subsection.redirect == "test_default2"
def test_config_context(): root = _create_test_config() root.add( "test__config_context", "A config var from a test case.", configparser.StrParam("test_default"), ) assert hasattr(root, "test__config_context") assert root.test__config_context == "test_default" with root.change_flags(test__config_context="new_value"): assert root.test__config_context == "new_value" with root.change_flags({"test__config_context": "new_value2"}): assert root.test__config_context == "new_value2" assert root.test__config_context == "new_value" assert root.test__config_context == "test_default"
def test_api_deprecation_warning(): # accessing through configdefaults.config is the new best practice with pytest.warns(None): root = configdefaults.config assert isinstance(str(root), str) # accessing through configparser.config is discouraged root = configparser.config with pytest.warns(DeprecationWarning, match="instead"): root.add( "test_deprecationwarning", "A config var from a test case.", configparser.StrParam("test_default"), ) with pytest.warns(DeprecationWarning, match="instead"): with root.change_flags(test_deprecationwarning="new_value"): pass
def test_config_hash(): root = _create_test_config() root.add( "test__config_hash", "A config var from a test case.", configparser.StrParam("test_default"), ) h0 = root.get_config_hash() with root.change_flags(test__config_hash="new_value"): assert root.test__config_hash == "new_value" h1 = root.get_config_hash() h2 = root.get_config_hash() assert h1 != h0 assert h2 == h0