Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/tests/test_api_client.py
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | expected = [ | ||||
'swh:1:dir:0000000000000000000000000000000000000016', | 'swh:1:dir:0000000000000000000000000000000000000016', | ||||
'swh:1:dir:0000000000000000000000000000000000000017', | 'swh:1:dir:0000000000000000000000000000000000000017', | ||||
'swh:1:rev:0000000000000000000000000000000000000018', | 'swh:1:rev:0000000000000000000000000000000000000018', | ||||
'swh:1:rel:0000000000000000000000000000000000000019' | 'swh:1:rel:0000000000000000000000000000000000000019' | ||||
] | ] | ||||
assert set(actual) == set(expected) | assert set(actual) == set(expected) | ||||
kwargs2 = kwargs.copy() | kwargs2 = kwargs.copy() | ||||
kwargs2['last'] = True | kwargs2['limit'] = -1 | ||||
actual = list(graph_client.walk(*args, **kwargs2)) | actual = list(graph_client.walk(*args, **kwargs2)) | ||||
expected = [ | expected = [ | ||||
'swh:1:rel:0000000000000000000000000000000000000019' | 'swh:1:rel:0000000000000000000000000000000000000019' | ||||
] | ] | ||||
assert set(actual) == set(expected) | assert set(actual) == set(expected) | ||||
kwargs2 = kwargs.copy() | |||||
kwargs2['limit'] = 2 | |||||
actual = list(graph_client.walk(*args, **kwargs2)) | |||||
expected = [ | |||||
'swh:1:dir:0000000000000000000000000000000000000016', | |||||
'swh:1:dir:0000000000000000000000000000000000000017' | |||||
] | |||||
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 origin in | ||||
the dataset, and only check the final node of the path (i.e., the origin) | 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] | ||||
assert actual[-1] == expected_root | assert actual[-1] == expected_root | ||||
kwargs2 = kwargs.copy() | kwargs2 = kwargs.copy() | ||||
kwargs2['last'] = True | kwargs2['limit'] = -1 | ||||
actual = list(graph_client.random_walk(*args, **kwargs2)) | actual = list(graph_client.random_walk(*args, **kwargs2)) | ||||
assert actual == [expected_root] | 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', | 'swh:1:rel:0000000000000000000000000000000000000010', | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |