def test_keys_rec_parent_path(keys):
    expected = [
        '$.x<-$', '$.x.x<-x', '$.x.y<-x', '$.x.z<-x', '$.y<-$', '$.y.x<-y',
        '$.y.y<-y', '$.y.z<-y', '$.z<-$', '$.z.x<-z', '$.z.y<-z', '$.z.z<-z'
    ]
    actual = [fm.path for fm in find_matches(path.rec.parent, keys)]
    assert actual == expected
Esempio n. 2
0
def test_a_k_k_a_k_k_k_a_find_all_tuple_path(a_k_k_a_k_k_k_a):
    result = find_matches(path[0, 1, 2].y.y[0, 1, 2].y.y.y[0, 1, 2], a_k_k_a_k_k_k_a)
    for expected_path, expected_value in gen_test_data(a_k_k_a_k_k_k_a, naia, nyiy, nyiy, naia, nyiy, nyiy, nyiy, yaia):
        actual = next(result)
        assert str(actual) == f"{expected_path}={expected_value}"

    assert_done_iterating(result)
def test_3d_list_wc_x_parent_path(three_dimensional_list):
    expected = ['$[0][1]<-0', '$[1][1]<-1', '$[2][1]<-2']
    actual = [
        fm.path
        for fm in find_matches(path[wc][1].parent, three_dimensional_list)
    ]
    assert actual == expected
Esempio n. 4
0
def test_k_a_a_k_a_a_a_k_find_all_wildcard_path(k_a_a_k_a_a_a_k):
    result = find_matches(path.y[wildcard][wildcard].y[wildcard][wildcard][wildcard].y, k_a_a_k_a_a_a_k)
    for expected_path, expected_value in gen_test_data(k_a_a_k_a_a_a_k, nyiy, naia, naia, nyiy, naia, naia, naia, yyia):
        actual = next(result)
        assert str(actual) == f"{expected_path}={expected_value}"

    assert_done_iterating(result)
Esempio n. 5
0
def test_a_k_k_a_k_k_k_a_find_all_wildcard_path(a_k_k_a_k_k_k_a):
    result = find_matches(path[0].wc.wc[0].wc.wc.wc[0], a_k_k_a_k_k_k_a)
    for expected_path, expected_value in gen_test_data(a_k_k_a_k_k_k_a, n0i0,
                                                       naia, naia, n0i0, naia,
                                                       naia, naia, y0i0):
        actual = next(result)
        assert str(actual) == f"{expected_path}={expected_value}"
    assert_done_iterating(result)
Esempio n. 6
0
def test_3d_find_all_wildcard_path(three_dimensional_list):
    result = find_matches(path[wildcard][wildcard][wildcard], three_dimensional_list)
    for l1 in range(0, 3):
        for l2 in range(0, 3):
            for l3 in range(0, 3):
                actual = next(result)
                assert str(actual) == f"$[{l1}][{l2}][{l3}]={actual.data}"
    assert_done_iterating(result)
Esempio n. 7
0
def test_3d_list_match_all_all_has_1(three_dimensional_list):
    exp_iter = find_matches(path.rec[has(path[1])], three_dimensional_list)
    count = 0
    for expected_path, expected_value in gen_test_data(three_dimensional_list, yria, yaia, yaia):
        count += 1
        actual = next(exp_iter)
        assert repr(actual) == f"{expected_path}={expected_value}"
    assert count == 13
    assert_done_iterating(exp_iter)
def test_keys_x_y_parent_rec_path(keys):
    expected = [
        '$.x.y<-x', '$.x.y<-x.x', '$.x.y<-x.x.x', '$.x.y<-x.x.y',
        '$.x.y<-x.x.z', '$.x.y<-x.y', '$.x.y<-x.y.x', '$.x.y<-x.y.y',
        '$.x.y<-x.y.z', '$.x.y<-x.z', '$.x.y<-x.z.x', '$.x.y<-x.z.y',
        '$.x.y<-x.z.z'
    ]
    actual = [fm.path for fm in find_matches(path.x.y.parent.rec, keys)]
    assert actual == expected
Esempio n. 9
0
def test_keys_match_all_all_has_x(keys):
    exp_iter = find_matches(path.rec[has(path.x)], keys)
    count = 0
    for expected_path, expected_value in gen_test_data(keys, yria, yaia, yaia):
        count += 1
        actual = next(exp_iter)
        assert repr(actual) == f"{expected_path}={expected_value}"
    assert count == 13
    assert_done_iterating(exp_iter)
Esempio n. 10
0
def test_k_a_a_k_a_a_a_k_find_all_tuple_path(k_a_a_k_a_a_a_k):
    result = find_matches(
        path["x", "y", "z"][0][0]["x", "y", "z"][0][0][0]["x", "y", "z"],
        k_a_a_k_a_a_a_k)
    for expected_path, expected_value in gen_test_data(k_a_a_k_a_a_a_k, naia,
                                                       n0i0, n0i0, naia, n0i0,
                                                       n0i0, n0i0, yaia):
        actual = next(result)
        assert str(actual) == f"{expected_path}={expected_value}"
    assert_done_iterating(result)
Esempio n. 11
0
def test_3d_list_match_all_all_has_1_eq_1(three_dimensional_list):
    exp_iter = find_matches(path.rec[1][has(path.rec[1] == 14)], three_dimensional_list)
    actual = next(exp_iter)
    expected = get_match(path[1], three_dimensional_list)
    assert repr(actual) == repr(expected)

    actual = next(exp_iter)
    expected = get_match(path[1][1], three_dimensional_list)
    assert repr(actual) == repr(expected)

    assert_done_iterating(exp_iter)
Esempio n. 12
0
def test_keys_match_all_all_has_x_eq_1(keys):
    exp_iter = find_matches(path.rec.x[has(path.rec.x == "1")], keys)
    actual = next(exp_iter)
    expected = get_match(path.x, keys)
    assert repr(actual) == repr(expected)

    actual = next(exp_iter)
    expected = get_match(path.x.x, keys)
    assert repr(actual) == repr(expected)

    assert_done_iterating(exp_iter)
Esempio n. 13
0
def test_traversal_function_find_matches(solar_system):
    """## find_matches"""
    # The **find_matches** function returns an Iterator that iterates to each match the path leads to.  Each match is
    # determine on its iteration.

    # Find the path to each of the inner planets.
    for match in find_matches(path.star.planets.inner[wc], solar_system):
        assert match.path in [
            '$.star.planets.inner[0]',
            '$.star.planets.inner[1]',
            '$.star.planets.inner[2]',
            '$.star.planets.inner[3]',
        ]

    # The data source can be a json data structure or a Match object.
    parent_match = get_match(path.star.planets.inner, solar_system)
    for match in find_matches(path[wc], parent_match):
        assert match.path in [
            '$.star.planets.inner[0]',
            '$.star.planets.inner[1]',
            '$.star.planets.inner[2]',
            '$.star.planets.inner[3]',
        ]
def test_keys_wc_x_parent_path(keys):
    expected = ['$.x.x<-x', '$.y.x<-y', '$.z.x<-z']
    actual = [fm.path for fm in find_matches(path.wc.x.parent, keys)]
    assert actual == expected
def test_keys_parent_rec_path(keys):
    expected = []
    actual = [fm.path for fm in find_matches(path.parent.rec, keys)]
    assert actual == expected
Esempio n. 16
0
def test_3d_list_match_all_all_has_a(three_dimensional_list):
    exp_iter = find_matches(path.rec[has(path[4])], three_dimensional_list)
    assert_done_iterating(exp_iter)
Esempio n. 17
0
def test_keys_match_all_root_wc_has_a(keys):
    result = find_matches(path.wc[has(path.a)], keys)
    assert_done_iterating(result)
Esempio n. 18
0
def test_3d_list_match_all_root_wc_has_a(three_dimensional_list):
    result = find_matches(path[wc][has(path[4])], three_dimensional_list)
    assert_done_iterating(result)
Esempio n. 19
0
def test_keys_find_all_wildcard_path(keys):
    result = find_matches(path.wildcard.wildcard.wildcard, keys)
    for expected_path, expected_value in gen_test_data(keys, naia, naia, yaia):
        actual = next(result)
        assert str(actual) == f"{expected_path}={actual.data}"
    assert_done_iterating(result)
Esempio n. 20
0
def test_keys_match_all_all_has_a(keys):
    exp_iter = find_matches(path.rec[has(path.a)], keys)
    assert_done_iterating(exp_iter)
Esempio n. 21
0
def test_3d_find_all_slice_variety_path(three_dimensional_list):
    test_data = [(expected_path, expected_value) for expected_path, expected_value in
                 gen_test_data(three_dimensional_list, naia, naia, yaia)]
    for actual in find_matches(path[::-1][:1:][0::2], three_dimensional_list):
        expected_path, expected_value = test_data[actual.data - 1]
        assert str(actual) == f"{expected_path}={expected_value}"
Esempio n. 22
0
def test_3d_find_all__comma_delimited_path(three_dimensional_list):
    test_data = [(expected_path, expected_value) for expected_path, expected_value in
                 gen_test_data(three_dimensional_list, naia, naia, yaia)]
    for actual in find_matches(path[2, 1, 0][0, 1][0, 2, 1], three_dimensional_list):
        expected_path, expected_value = test_data[actual.data - 1]
        assert str(actual) == f"{expected_path}={expected_value}"
Esempio n. 23
0
def test_nested_find_matches(keys):
    expected = "[$.y.y.x=13, $.y.y.y=14, $.y.y.z=15]"
    actual = get_match(path.y.y, keys)
    actual = [v for v in find_matches(path.wc, actual)]
    assert repr(actual) == expected
Esempio n. 24
0
def test_keys_find_all_tuple_path(keys):
    match_iter = find_matches(
        path["x", "y", "z"]["x", "y", "z"]["x", "y", "z"], keys)
    for expected_path, expected_value in gen_test_data(keys, naia, naia, yaia):
        actual = next(match_iter)
        assert str(actual) == f"{expected_path}={actual.data}"
Esempio n. 25
0
def test_keys_match_all_root_wc_has_x(keys):
    result = find_matches(path.wc[has(path.x)], keys)
    for expected_path, expected_value in gen_test_data(keys, yaia):
        actual = next(result)
        assert str(actual) == f"{expected_path}={actual.data}"
    assert_done_iterating(result)
Esempio n. 26
0
def test_3d_find_all_slice_path(three_dimensional_list):
    match_iter = find_matches(path[:][:][:], three_dimensional_list)
    for expected_path, expected_value in gen_test_data(three_dimensional_list, naia, naia, yaia):
        actual = next(match_iter)
        assert str(actual) == f"{expected_path}={expected_value}"
    assert_done_iterating(match_iter)
Esempio n. 27
0
def test_3d_list_match_all_root_wc_has_1(three_dimensional_list):
    result = find_matches(path[wc][has(path[1])], three_dimensional_list)
    for expected_path, expected_value in gen_test_data(three_dimensional_list, yaia):
        actual = next(result)
        assert str(actual) == f"{expected_path}={actual.data}"
    assert_done_iterating(result)