Exemplo n.º 1
0
def test_at_cannot_get_an_attribute_value_from_a_leaf():
    tree = Tree(hello=Mock(name="hello", some_value=sentinel.some_value))
    path = Path(tree).hello.some_value
    with pytest.raises(Exception):
        at(path)
Exemplo n.º 2
0
def test_at_can_get_a_leaf_from_a_tree(example_tree):
    path = Path(example_tree).foo.bar.baz
    assert at(path) == sentinel.foobarbaz
Exemplo n.º 3
0
def test_at_can_get_a_subtree_from_a_tree(example_tree):
    path = Path(example_tree).foo.bar
    expected = Tree(baz=sentinel.foobarbaz, bang=sentinel.foobarbang)
    assert at(path) == expected
Exemplo n.º 4
0
def test_at_can_apply_multiple_contexts_and_kwargs_to_a_wildcarded_path(example_tree):
    path = Path(example_tree)['%x'].bar['%y']
    assert at(path, [Context(y='baz'),
                     Context(y='bang')], x='foo') == [sentinel.foobarbaz, sentinel.foobarbang]
Exemplo n.º 5
0
def test_at_can_apply_context_from_another_path_and_kwargs_to_a_wildcarded_path(example_tree):
    path1 = Path(example_tree)['%x'].bar['%y']
    path2 = Path(Tree(baz=sentinel.meh))['%y']
    assert at(path1, path2, x='foo') == [sentinel.foobarbaz]
Exemplo n.º 6
0
def test_at_can_apply_kwargs_and_context_to_a_wildcarded_path(example_tree):
    path = Path(example_tree)['%x'].bar['%y']
    assert at(path, {'x': 'foo'}, y='baz') == sentinel.foobarbaz
Exemplo n.º 7
0
def test_at_can_apply_a_context_to_a_wildcarded_path(example_tree):
    path = Path(example_tree)['%x'].bar['%y']
    assert at(path, {'x': 'foo', 'y': 'baz'}) == sentinel.foobarbaz