Ejemplo n.º 1
0
def test_pop_a_predicate_match_not_found():
    actual = {"a": 0, "x": 2}
    expected_error_message = 'MatchNotFoundError(No get_match occurred on path: $[has($.a == 1)].a)'
    expected = {"a": 0, "x": 2}
    with pytest.raises(MatchNotFoundError) as exc_info:
        pop(path[has(path.a == 1)].a, actual)
    assert actual == expected
    assert repr(exc_info.value) == expected_error_message
Ejemplo n.º 2
0
def test_pop_0():
    actual = [1, 2]
    expected_return = 1
    expected = [2]
    actual_return = pop(path[0], actual)
    assert actual == expected
    assert actual_return == expected_return
Ejemplo n.º 3
0
def test_pop_a_predicate_default():
    actual = {"a": 0, "x": 2}
    expected_return = 0
    expected = {"a": 0, "x": 2}
    actual_return = pop(path[has(path.a == 1)].a, actual, default=0)
    assert actual == expected
    assert actual_return == expected_return
Ejemplo n.º 4
0
def test_pop_a_b_c():
    actual = {"a": {"b": {"c": 1}}}
    expected_return = 1
    expected = {"a": {"b": {}}}
    actual_return = pop(path.a.b.c, actual)
    assert actual == expected
    assert actual_return == expected_return
Ejemplo n.º 5
0
def test_pop_a():
    actual = {"a": 1, "x": 2}
    expected_return = 1
    expected = {"x": 2}
    actual_return = pop(path.a, actual)
    assert actual == expected
    assert actual_return == expected_return
Ejemplo n.º 6
0
def test_pop_0_predicate_default():
    actual = [1, 2]
    expected_return = 0
    expected = [1, 2]
    actual_return = pop(path[has(path.a == 1)].a, actual, default=0)
    assert actual == expected
    assert actual_return == expected_return
Ejemplo n.º 7
0
def test_pop_0_predicate():
    actual = [1, 2]
    expected_return = 1
    expected = [2]
    actual_return = pop(path[has(path[0] == 1)][0], actual)
    assert actual == expected
    assert actual_return == expected_return
Ejemplo n.º 8
0
def test_pop_0_1_2():
    actual = [[[1]]]
    expected_return = 1
    expected = [[[]]]
    actual_return = pop(path[0][0][0], actual)
    assert actual == expected
    assert actual_return == expected_return
Ejemplo n.º 9
0
def test_pop_wc_invalid_path():
    expected = "PopError(The path $[*] does not support pop.  It can only be a key or index\n  path: $[*])"
    data = [0, 1]
    with pytest.raises(PopError) as exc_info:
        pop(path[wc], data)
    assert repr(exc_info.value) == expected