Example #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)
Example #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
Example #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
Example #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]
Example #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]
Example #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
Example #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