Пример #1
0
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"
Пример #2
0
def test_config_context():
    # TODO: use custom config instance for the test
    root = configparser.config
    configparser.AddConfigVar(
        "test_config_context",
        "A config var from a test case.",
        configparser.StrParam("test_default"),
        root=root,
    )
    assert hasattr(root, "test_config_context")
    assert root.test_config_context == "test_default"

    with configparser.change_flags(test_config_context="new_value"):
        assert root.test_config_context == "new_value"
    assert root.test_config_context == "test_default"
Пример #3
0
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"
Пример #4
0
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
Пример #5
0
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
Пример #6
0
def test_config_hash():
    # TODO: use custom config instance for the test
    root = configparser.config
    configparser.AddConfigVar(
        "test_config_hash",
        "A config var from a test case.",
        configparser.StrParam("test_default"),
        root=root,
    )

    h0 = configparser.get_config_hash()

    with configparser.change_flags(test_config_hash="new_value"):
        assert root.test_config_hash == "new_value"
        h1 = configparser.get_config_hash()

    h2 = configparser.get_config_hash()
    assert h1 != h0
    assert h2 == h0