Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/tests/test_api_client.py
Show First 20 Lines • Show All 212 Lines • ▼ Show 20 Lines | expected = [ | ||||
( | ( | ||||
"swh:1:dir:0000000000000000000000000000000000000006", | "swh:1:dir:0000000000000000000000000000000000000006", | ||||
"swh:1:cnt:0000000000000000000000000000000000000005", | "swh:1:cnt:0000000000000000000000000000000000000005", | ||||
), | ), | ||||
] | ] | ||||
assert set(actual) == set(expected) | assert set(actual) == set(expected) | ||||
def test_visit_paths(graph_client): | |||||
actual = list( | |||||
graph_client.visit_paths( | |||||
"swh:1:snp:0000000000000000000000000000000000000020", edges="snp:*,rev:*" | |||||
) | |||||
) | |||||
actual = [tuple(path) for path in actual] | |||||
expected = [ | |||||
( | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | |||||
"swh:1:rev:0000000000000000000000000000000000000009", | |||||
"swh:1:rev:0000000000000000000000000000000000000003", | |||||
"swh:1:dir:0000000000000000000000000000000000000002", | |||||
), | |||||
( | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | |||||
"swh:1:rev:0000000000000000000000000000000000000009", | |||||
"swh:1:dir:0000000000000000000000000000000000000008", | |||||
), | |||||
( | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | |||||
"swh:1:rel:0000000000000000000000000000000000000010", | |||||
), | |||||
] | |||||
assert set(actual) == set(expected) | |||||
@pytest.mark.skip(reason="currently disabled due to T1969") | @pytest.mark.skip(reason="currently disabled due to T1969") | ||||
def test_walk(graph_client): | def test_walk(graph_client): | ||||
args = ("swh:1:dir:0000000000000000000000000000000000000016", "rel") | args = ("swh:1:dir:0000000000000000000000000000000000000016", "rel") | ||||
kwargs = { | kwargs = { | ||||
"edges": "dir:dir,dir:rev,rev:*", | "edges": "dir:dir,dir:rev,rev:*", | ||||
"direction": "backward", | "direction": "backward", | ||||
"traversal": "bfs", | "traversal": "bfs", | ||||
} | } | ||||
Show All 18 Lines | def test_walk(graph_client): | ||||
actual = list(graph_client.walk(*args, **kwargs2)) | actual = list(graph_client.walk(*args, **kwargs2)) | ||||
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_dst_is_type(graph_client): | ||||
"""as the walk is random, we test a visit from a cnt node to the only | """as the walk is random, we test a visit from a cnt node to the only | ||||
origin in the dataset, and only check the final node of the path | origin in the dataset, and only check the final node of the path | ||||
(i.e., the origin) | (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" | ||||
Show All 12 Lines | def test_random_walk_dst_is_type(graph_client): | ||||
assert len(actual) == 2 | assert len(actual) == 2 | ||||
assert actual[-1] == expected_root | assert actual[-1] == expected_root | ||||
kwargs2["limit"] = 3 | kwargs2["limit"] = 3 | ||||
actual = list(graph_client.random_walk(*args, **kwargs2)) | actual = list(graph_client.random_walk(*args, **kwargs2)) | ||||
assert len(actual) == 3 | assert len(actual) == 3 | ||||
def test_random_walk_dst_is_node(graph_client): | |||||
"""Same as test_random_walk_dst_is_type, but we target the specific origin | |||||
node instead of a type | |||||
""" | |||||
args = ( | |||||
"swh:1:cnt:0000000000000000000000000000000000000001", | |||||
"swh:1:ori:0000000000000000000000000000000000000021", | |||||
) | |||||
kwargs = {"direction": "backward"} | |||||
expected_root = "swh:1:ori:0000000000000000000000000000000000000021" | |||||
actual = list(graph_client.random_walk(*args, **kwargs)) | |||||
assert len(actual) > 1 # no origin directly links to a content | |||||
assert actual[0] == args[0] | |||||
assert actual[-1] == expected_root | |||||
kwargs2 = kwargs.copy() | |||||
kwargs2["limit"] = -1 | |||||
actual = list(graph_client.random_walk(*args, **kwargs2)) | |||||
assert actual == [expected_root] | |||||
kwargs2["limit"] = -2 | |||||
actual = list(graph_client.random_walk(*args, **kwargs2)) | |||||
assert len(actual) == 2 | |||||
assert actual[-1] == expected_root | |||||
kwargs2["limit"] = 3 | |||||
actual = list(graph_client.random_walk(*args, **kwargs2)) | |||||
assert len(actual) == 3 | |||||
def test_count(graph_client): | def test_count(graph_client): | ||||
actual = graph_client.count_leaves( | actual = graph_client.count_leaves( | ||||
"swh:1:ori:0000000000000000000000000000000000000021" | "swh:1:ori:0000000000000000000000000000000000000021" | ||||
) | ) | ||||
assert actual == 4 | assert actual == 4 | ||||
actual = graph_client.count_visit_nodes( | actual = graph_client.count_visit_nodes( | ||||
"swh:1:rel:0000000000000000000000000000000000000010", edges="rel:rev,rev:rev" | "swh:1:rel:0000000000000000000000000000000000000010", edges="rel:rev,rev:rev" | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |