Exemplo n.º 1
0
    def __setitem__(self, key, value):
        if is_nested_key(key):
            subkeys = key.split('.')

            reduce(lambda d, k: d[k], subkeys[:-1], self.data)[subkeys[-1]] = value
            return

        self.data[key] = value
Exemplo n.º 2
0
    def __setitem__(self, key, value):
        if is_nested_key(key):
            subkeys = key.split('.')

            reduce(lambda d, k: d[k], subkeys[:-1], self.data)[subkeys[-1]] = value
            return

        self.data[key] = value
Exemplo n.º 3
0
def test_is_nested_with_invalid_key_nesting_raises():
    with pytest.raises(MalformationError):
        is_nested_key('.abc.123')

    with pytest.raises(MalformationError):
        is_nested_key('abc.123.')

    with pytest.raises(MalformationError):
        is_nested_key('abc..123')
Exemplo n.º 4
0
def test_is_nested_with_invalid_key_nesting_raises():
    with pytest.raises(MalformationError):
        is_nested_key('.abc.123')

    with pytest.raises(MalformationError):
        is_nested_key('abc.123.')

    with pytest.raises(MalformationError):
        is_nested_key('abc..123')
Exemplo n.º 5
0
    def __getitem__(self, key):
        if is_nested_key(key):
            subkeys = key.split('.')
            return reduce(lambda d, k: d[k], subkeys, self.data)

        return self.data[key]
Exemplo n.º 6
0
    def __getitem__(self, key):
        if is_nested_key(key):
            subkeys = key.split('.')
            return reduce(lambda d, k: d[k], subkeys, self.data)

        return self.data[key]
Exemplo n.º 7
0
def test_is_nested_with_nested_key():
    assert is_nested_key('abc.123') is True
Exemplo n.º 8
0
def test_is_nested_with_non_nested_key():
    assert is_nested_key('abc 123') is False
Exemplo n.º 9
0
def test_is_nested_with_nested_key():
    assert is_nested_key('abc.123') is True
Exemplo n.º 10
0
def test_is_nested_with_non_nested_key():
    assert is_nested_key('abc 123') is False