Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/tests/test_api_client.py
Show First 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | expected = [ | ||||
( | ( | ||||
"swh:1:rev:0000000000000000000000000000000000000003", | "swh:1:rev:0000000000000000000000000000000000000003", | ||||
"swh:1:dir:0000000000000000000000000000000000000002", | "swh:1:dir:0000000000000000000000000000000000000002", | ||||
), | ), | ||||
] | ] | ||||
assert set(actual) == set(expected) | assert set(actual) == set(expected) | ||||
def test_visit_edges_limited(graph_client): | @pytest.mark.parametrize("max_edges", [1, 2, 3, 4, 5]) | ||||
@pytest.mark.parametrize("edges", ["*", "rel:rev,rev:rev,rev:dir"]) | |||||
def test_visit_edges_limited(graph_client, max_edges, edges): | |||||
actual = list( | actual = list( | ||||
graph_client.visit_edges( | graph_client.visit_edges( | ||||
"swh:1:rel:0000000000000000000000000000000000000010", | "swh:1:rel:0000000000000000000000000000000000000010", max_edges=max_edges, | ||||
max_edges=4, | |||||
edges="rel:rev,rev:rev,rev:dir", | |||||
vlorentz: It would be nice to test both with and without the `edges` argument, to test whether it's… | |||||
Done Inline ActionsI don't know if it makes sense to test both at the same time, because the edges are filtered before counting them, so if the number of edges returned is less than max_edges, because of the edges filter, the test will not pass. Hakimb: I don't know if it makes sense to test both at the same time, because the edges are filtered… | |||||
Not Done Inline ActionsOk. You can test with an inequality then. (assert 1 <= len(actual) <= max_edges) vlorentz: Ok. You can test with an inequality then. (`assert 1 <= len(actual) <= max_edges`) | |||||
) | ) | ||||
) | ) | ||||
expected = [ | expected = [ | ||||
( | ( | ||||
"swh:1:rel:0000000000000000000000000000000000000010", | "swh:1:rel:0000000000000000000000000000000000000010", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
), | ), | ||||
( | ( | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:rev:0000000000000000000000000000000000000003", | "swh:1:rev:0000000000000000000000000000000000000003", | ||||
), | ), | ||||
( | ( | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
), | ), | ||||
( | ( | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | |||||
"swh:1:dir:0000000000000000000000000000000000000006", | |||||
), | |||||
( | |||||
"swh:1:dir:0000000000000000000000000000000000000008", | |||||
"swh:1:cnt:0000000000000000000000000000000000000007", | |||||
), | |||||
( | |||||
"swh:1:dir:0000000000000000000000000000000000000008", | |||||
"swh:1:cnt:0000000000000000000000000000000000000001", | |||||
), | |||||
( | |||||
"swh:1:dir:0000000000000000000000000000000000000006", | |||||
"swh:1:cnt:0000000000000000000000000000000000000005", | |||||
), | |||||
( | |||||
"swh:1:dir:0000000000000000000000000000000000000006", | |||||
"swh:1:cnt:0000000000000000000000000000000000000004", | |||||
), | |||||
( | |||||
"swh:1:rev:0000000000000000000000000000000000000003", | "swh:1:rev:0000000000000000000000000000000000000003", | ||||
"swh:1:dir:0000000000000000000000000000000000000002", | "swh:1:dir:0000000000000000000000000000000000000002", | ||||
), | ), | ||||
( | |||||
"swh:1:dir:0000000000000000000000000000000000000002", | |||||
"swh:1:cnt:0000000000000000000000000000000000000001", | |||||
), | |||||
] | ] | ||||
# As there are four valid answers (up to reordering), we cannot check for | # As there are multiple valid answers for every value of max_edges (<= 3), | ||||
# equality. Instead, we check the client returned all edges but one. | # we cannot check for equality. | ||||
# Instead, we check the client returned all edges but one. | |||||
assert set(actual).issubset(set(expected)) | assert set(actual).issubset(set(expected)) | ||||
assert len(actual) == 3 | assert 1 <= len(actual) <= max_edges | ||||
def test_visit_edges_diamond_pattern(graph_client): | def test_visit_edges_diamond_pattern(graph_client): | ||||
actual = list( | actual = list( | ||||
graph_client.visit_edges( | graph_client.visit_edges( | ||||
"swh:1:rev:0000000000000000000000000000000000000009", edges="*", | "swh:1:rev:0000000000000000000000000000000000000009", edges="*", | ||||
) | ) | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 196 Lines • Show Last 20 Lines |
It would be nice to test both with and without the edges argument, to test whether it's counter before or after the filtering. (whichever you think makes the most sense)