Exemplo n.º 1
0
def test_get_key():
    config = Config()
    config['x'] = 10
    config['sub'] = {'y': 20}
    config['sub']['sub'] = {'z': 30}
    
    assert get_key(config, "x") == 10
    assert get_key(config, "sub.y") == 20
    assert get_key(config, ("sub", "y")) == 20
    assert get_key(config, "sub.sub.z") == 30
    assert get_key(config, ("sub", "sub", "z")) == 30
    assert get_key(config, ()) == config
    with pytest.raises(KeyError) as exc_info:
        get_key(config, "y")
    assert str(exc_info.value) == "'y'"
Exemplo n.º 2
0
def test_get_key_error():
    config = Config()
    with pytest.raises(TypeError):
        get_key(config, 4.5)