Esempio n. 1
0
def test_get():
    test_config = Config(CONFIG_NAME)
    test_config.config = {'x': 1, 'y': {'a': 2}}

    assert test_config.get('x') == 1
    assert test_config['x'] == 1
    assert test_config.get('y.a') == 2
    assert test_config['y.a'] == 2
    assert test_config.get('y.b', 123) == 123
    with pytest.raises(KeyError):
        test_config.get('y.b')
    with pytest.raises(KeyError):
        test_config['y.b']
Esempio n. 2
0
def test_env_var_canonical_name(monkeypatch):
    value = 3
    monkeypatch.setenv(ENV_PREFIX + 'A_B', str(value))
    config = Config(CONFIG_NAME)

    assert config.get('a_b') == value
    assert config.get('a-b') == value
Esempio n. 3
0
def test_env_var_normalization(monkeypatch):
    value = 3
    monkeypatch.setenv('TEST_A_B', str(value))
    config = Config(config_name)

    assert config.get('a_b') == value
    assert config.get('a-b') == value
Esempio n. 4
0
def test_get_set_canonical_name():
    c = {'x-y': {'a_b': 123}}
    config = Config(CONFIG_NAME)
    config.update(c)

    keys = ['x_y.a_b', 'x-y.a-b', 'x_y.a-b']
    for k in keys:
        assert config.get(k) == 123

    with config.set({'x_y': {'a-b': 456}}):
        for k in keys:
            assert config.get(k) == 456

    # No change to new keys in sub dicts
    with config.set({'x_y': {'a-b': {'c_d': 1}, 'e-f': 2}}):
        assert config.get('x_y.a-b') == {'c_d': 1}
        assert config.get('x_y.e_f') == 2
Esempio n. 5
0
def test_get_set_roundtrip(key):
    value = 123
    config = Config(CONFIG_NAME)
    with config.set({key: value}):
        assert config.get('custom_key') == value
        assert config.get('custom-key') == value