Exemplo n.º 1
0
def test_get_parent_while_searching():
    root = {"a": {"b": {"c": 1}}}

    parents = []
    history = []

    class TestName(Name):
        def find(self, element):
            parents.append(var_parent.get())
            history.append(element)
            return super().find(element)

    assert Root().Search(TestName("c")).find(root) == [1]
    assert parents == [root, root, root["a"], root["a"]["b"]]
    assert history == [root, root["a"], root["a"]["b"], 1]
Exemplo n.º 2
0
def test_slice_in_array(start, end, step, data, expect):
    jp = Root().Array(Slice(start, end, step))
    assert_find(jp, data, expect)
Exemplo n.º 3
0
def test_root(data):
    assert_find(Root(), data, [data])
Exemplo n.º 4
0
def test_slice(start, end, step, data, expect):
    jp = Root().Slice(start, end, step)
    assert_find(jp, data, expect)
Exemplo n.º 5
0
        (0, 1, 1, [1, 2], [1]),
        (0, None, 1, [1, 2], [1, 2]),
        (None, -1, 1, [1, 2, 3], [1, 2]),
        (None, None, 2, [1, 2, 3], [1, 3]),
    ],
    ids=reprlib.repr,
)
def test_slice_in_array(start, end, step, data, expect):
    jp = Root().Array(Slice(start, end, step))
    assert_find(jp, data, expect)


@pytest.mark.parametrize(
    "expr,data,expect",
    [
        (Root().Search(Array(0)), {"boo": [{"boo": [1]}]}, [{"boo": [1]}, 1]),
        (
            Root().Search(Array()),
            {"boo": [{"boo": [1, 2]}]},
            [{"boo": [1, 2]}, 1, 2],
        ),
        (
            Root().Search(Array(Slice(None, -1, 2))),
            {"boo": [{"boo": [1, 2, 3, 4, 5]}, 1]},
            [{"boo": [1, 2, 3, 4, 5]}, 1, 3],
        ),
    ],
)
def test_search(expr, data, expect):
    assert_find(expr, data, expect)
Exemplo n.º 6
0
def test_root(data):
    assert Root().find(data) == [data]
Exemplo n.º 7
0
def test_slice(start, end, step, data, expect):
    jp = Root().Slice(start, end, step)
    assert jp.find(data) == expect