def test_separator():  # type: ignore
    from . import python_config_2

    cfg = config_from_python(
        python_config_2, prefix="CONFIG", separator="__", lowercase_keys=True
    )
    assert cfg == config_from_dict(DICT, lowercase_keys=True)
Exemple #2
0
def test_repr_and_str():  # type: ignore
    import sys

    path = os.path.join(os.path.dirname(__file__), "python_config.py")
    cfg = ConfigurationSet(
        config_from_dict(DICT2_1, lowercase_keys=True),
        config_from_dict(DICT2_2, lowercase_keys=True),
        config_from_env(prefix=PREFIX, lowercase_keys=True),
        config_from_python(path, prefix="CONFIG", lowercase_keys=True),
    )

    joined_dicts = dict((k, str(v)) for k, v in DICT1.items())
    joined_dicts.update(DICT2_1)
    joined_dicts.update(DICT2_2)
    joined_dicts["sys.version"] = sys.hexversion
    assert hex(id(cfg)) in repr(cfg)

    assert (
        str(cfg)
        == "{'a1.b1.c1': '1', 'a1.b1.c2': '2', 'a1.b1.c3': '3', 'a1.b2.c1': 'a', 'a1.b2.c2': 'True', "
        "'a1.b2.c3': '1.1', 'a2.b1.c1': 'f', 'a2.b1.c2': False, 'a2.b1.c3': None, 'a2.b2.c1': 10, "
        "'a2.b2.c2': 'YWJjZGVmZ2g=', 'a2.b2.c3': 'abcdefgh', 'sys.version': "
        + str(sys.hexversion)
        + "}"
    )
Exemple #3
0
def test_equality():  # type: ignore
    import python_config

    cfg = config_from_python(python_config,
                             prefix="CONFIG",
                             lowercase_keys=True)
    assert cfg == config_from_dict(DICT, lowercase_keys=True)
Exemple #4
0
def test_load_from_module():  # type: ignore
    import python_config

    cfg = config_from_python(python_config,
                             prefix="CONFIG",
                             lowercase_keys=True)
    assert cfg["a1.b2"].as_dict() == {"c1": "a", "c2": True, "c3": 1.1}
    assert cfg["sys.version"] == sys.hexversion
def test_reload():  # type: ignore
    from . import python_config

    cfg = config_from_python(python_config, prefix="CONFIG", lowercase_keys=True)
    assert cfg == config_from_dict(DICT, lowercase_keys=True)

    python_config.CONFIG_A10_B10 = "a"
    cfg.reload()
    cfg2 = config_from_dict(DICT, lowercase_keys=True)
    cfg2["a10.b10"] = "a"
    assert cfg == cfg2
def test_repr():  # type: ignore
    import sys
    path = os.path.join(os.path.dirname(__file__), 'python_config.py')
    cfg = ConfigurationSet(config_from_dict(DICT2_1),
                           config_from_dict(DICT2_2),
                           config_from_env(prefix=PREFIX),
                           config_from_python(path, prefix='CONFIG'))

    joined_dicts = dict((k, str(v)) for k, v in DICT1.items())
    joined_dicts.update(DICT2_1)
    joined_dicts.update(DICT2_2)
    joined_dicts['sys.version'] = sys.hexversion
    assert str(dict(
        (k.lower(), v) for k, v in joined_dicts.items())) in repr(cfg)
Exemple #7
0
def test_repr():  # type: ignore
    import sys

    path = os.path.join(os.path.dirname(__file__), "python_config.py")
    cfg = ConfigurationSet(
        config_from_dict(DICT2_1, lowercase_keys=True),
        config_from_dict(DICT2_2, lowercase_keys=True),
        config_from_env(prefix=PREFIX, lowercase_keys=True),
        config_from_python(path, prefix="CONFIG", lowercase_keys=True),
    )

    joined_dicts = dict((k, str(v)) for k, v in DICT1.items())
    joined_dicts.update(DICT2_1)
    joined_dicts.update(DICT2_2)
    joined_dicts["sys.version"] = sys.hexversion
    assert str(dict(
        (k.lower(), v) for k, v in joined_dicts.items())) in repr(cfg)
def test_equality_from_path():  # type: ignore
    path = os.path.join(os.path.dirname(__file__), "python_config.py")
    cfg = config_from_python(path, prefix="CONFIG", lowercase_keys=True)
    assert cfg == config_from_dict(DICT, lowercase_keys=True)
def test_load_from_path():  # type: ignore
    path = os.path.join(os.path.dirname(__file__), "python_config.py")
    cfg = config_from_python(path, prefix="CONFIG", lowercase_keys=True)
    assert cfg["a1.b2"].as_dict() == {"c1": "a", "c2": True, "c3": 1.1}
    assert cfg["sys.version"] == sys.hexversion
Exemple #10
0
def test_equality_from_path():  # type: ignore
    path = os.path.join(os.path.dirname(__file__), 'python_config.py')
    cfg = config_from_python(path, prefix='CONFIG')
    assert cfg == config_from_dict(DICT)
Exemple #11
0
def test_equality():  # type: ignore
    import python_config
    cfg = config_from_python(python_config, prefix='CONFIG')
    assert cfg == config_from_dict(DICT)
Exemple #12
0
def test_load_from_module_string():  # type: ignore
    path = 'tests.python_config'
    cfg = config_from_python(path, prefix='CONFIG')
    assert cfg["a1.b2"].as_dict() == {"c1": "a", "c2": True, "c3": 1.1}
    assert cfg['sys.version'] == sys.hexversion
Exemple #13
0
def test_load_from_path():  # type: ignore
    path = os.path.join(os.path.dirname(__file__), 'python_config.py')
    cfg = config_from_python(path, prefix='CONFIG')
    assert cfg["a1.b2"].as_dict() == {"c1": "a", "c2": True, "c3": 1.1}
    assert cfg['sys.version'] == sys.hexversion
Exemple #14
0
def test_load_from_module():  # type: ignore
    import python_config
    cfg = config_from_python(python_config, prefix='CONFIG')
    assert cfg["a1.b2"].as_dict() == {"c1": "a", "c2": True, "c3": 1.1}
    assert cfg['sys.version'] == sys.hexversion