Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/tests/test_api_client.py
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | def test_visit_nodes(graph_client): | ||||
expected = [ | expected = [ | ||||
"swh:1:rel:0000000000000000000000000000000000000010", | "swh:1:rel:0000000000000000000000000000000000000010", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:rev:0000000000000000000000000000000000000003", | "swh:1:rev:0000000000000000000000000000000000000003", | ||||
] | ] | ||||
assert set(actual) == set(expected) | assert set(actual) == set(expected) | ||||
def test_visit_nodes_filtered(graph_client): | |||||
actual = list( | |||||
graph_client.visit_nodes( | |||||
"swh:1:rel:0000000000000000000000000000000000000010", return_types="dir", | |||||
) | |||||
) | |||||
expected = [ | |||||
"swh:1:dir:0000000000000000000000000000000000000002", | |||||
"swh:1:dir:0000000000000000000000000000000000000008", | |||||
"swh:1:dir:0000000000000000000000000000000000000006", | |||||
] | |||||
assert set(actual) == set(expected) | |||||
def test_visit_nodes_filtered_star(graph_client): | |||||
actual = list( | |||||
graph_client.visit_nodes( | |||||
"swh:1:rel:0000000000000000000000000000000000000010", return_types="*", | |||||
) | |||||
) | |||||
expected = [ | |||||
"swh:1:rel:0000000000000000000000000000000000000010", | |||||
"swh:1:rev:0000000000000000000000000000000000000009", | |||||
"swh:1:rev:0000000000000000000000000000000000000003", | |||||
"swh:1:dir:0000000000000000000000000000000000000002", | |||||
"swh:1:cnt:0000000000000000000000000000000000000001", | |||||
"swh:1:dir:0000000000000000000000000000000000000008", | |||||
"swh:1:cnt:0000000000000000000000000000000000000007", | |||||
"swh:1:dir:0000000000000000000000000000000000000006", | |||||
"swh:1:cnt:0000000000000000000000000000000000000004", | |||||
"swh:1:cnt:0000000000000000000000000000000000000005", | |||||
] | |||||
assert set(actual) == set(expected) | |||||
def test_visit_edges(graph_client): | def test_visit_edges(graph_client): | ||||
actual = list( | actual = list( | ||||
graph_client.visit_edges( | graph_client.visit_edges( | ||||
"swh:1:rel:0000000000000000000000000000000000000010", | "swh:1:rel:0000000000000000000000000000000000000010", | ||||
edges="rel:rev,rev:rev,rev:dir", | edges="rel:rev,rev:rev,rev:dir", | ||||
) | ) | ||||
) | ) | ||||
expected = [ | expected = [ | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | expected = [ | ||||
( | ( | ||||
"swh:1:rev:0000000000000000000000000000000000000003", | "swh:1:rev:0000000000000000000000000000000000000003", | ||||
"swh:1:dir:0000000000000000000000000000000000000002", | "swh:1:dir:0000000000000000000000000000000000000002", | ||||
), | ), | ||||
] | ] | ||||
# As there are four valid answers (up to reordering), we cannot check for | # As there are four valid answers (up to reordering), we cannot check for | ||||
# equality. Instead, we check the client returned all edges but one. | # 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 len(actual) == 4 | ||||
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 95 Lines • ▼ Show 20 Lines | def test_walk(graph_client): | ||||
expected = [ | expected = [ | ||||
"swh:1:dir:0000000000000000000000000000000000000016", | "swh:1:dir:0000000000000000000000000000000000000016", | ||||
"swh:1:dir:0000000000000000000000000000000000000017", | "swh:1:dir:0000000000000000000000000000000000000017", | ||||
] | ] | ||||
assert set(actual) == set(expected) | assert set(actual) == set(expected) | ||||
def test_random_walk(graph_client): | def test_random_walk(graph_client): | ||||
"""as the walk is random, we test a visit from a cnt node to the only origin in | """as the walk is random, we test a visit from a cnt node to the only | ||||
the dataset, and only check the final node of the path (i.e., the origin) | origin in the dataset, and only check the final node of the path | ||||
(i.e., the origin) | |||||
""" | """ | ||||
args = ("swh:1:cnt:0000000000000000000000000000000000000001", "ori") | args = ("swh:1:cnt:0000000000000000000000000000000000000001", "ori") | ||||
kwargs = {"direction": "backward"} | kwargs = {"direction": "backward"} | ||||
expected_root = "swh:1:ori:0000000000000000000000000000000000000021" | expected_root = "swh:1:ori:0000000000000000000000000000000000000021" | ||||
actual = list(graph_client.random_walk(*args, **kwargs)) | actual = list(graph_client.random_walk(*args, **kwargs)) | ||||
assert len(actual) > 1 # no origin directly links to a content | assert len(actual) > 1 # no origin directly links to a content | ||||
assert actual[0] == args[0] | assert actual[0] == args[0] | ||||
▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines |