Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/tests/test_api_client.py
Show All 26 Lines | def test_stats(graph_client): | ||||
assert stats['indegree']['min'] == 0 | assert stats['indegree']['min'] == 0 | ||||
assert stats['indegree']['max'] == 3 | assert stats['indegree']['max'] == 3 | ||||
assert isinstance(stats['indegree']['avg'], float) | assert isinstance(stats['indegree']['avg'], float) | ||||
assert stats['outdegree']['min'] == 0 | assert stats['outdegree']['min'] == 0 | ||||
assert stats['outdegree']['max'] == 3 | assert stats['outdegree']['max'] == 3 | ||||
assert isinstance(stats['outdegree']['avg'], float) | assert isinstance(stats['outdegree']['avg'], float) | ||||
def test_node(graph_client): | |||||
existing_nodes = [ | |||||
'swh:1:cnt:0000000000000000000000000000000000000005', | |||||
'swh:1:dir:0000000000000000000000000000000000000017', | |||||
'swh:1:ori:0000000000000000000000000000000000000021', | |||||
'swh:1:rel:0000000000000000000000000000000000000019', | |||||
'swh:1:rev:0000000000000000000000000000000000000018', | |||||
'swh:1:snp:0000000000000000000000000000000000000020', | |||||
] | |||||
non_existing_nodes = [ | |||||
'swh:1:cnt:00f0000000000000000000000000000000000005', | |||||
'swh:1:dir:000f000000000000000000000000000000000017', | |||||
'swh:1:ori:0000f00000000000000000000000000000000021', | |||||
'swh:1:rel:00000f0000000000000000000000000000000019', | |||||
'swh:1:rev:000000f000000000000000000000000000000018', | |||||
'swh:1:snp:0000000f00000000000000000000000000000020', | |||||
'swh:2:inv:00invalidpidbwawaaaaaaa00000000000000020', | |||||
] | |||||
for node in existing_nodes: | |||||
assert graph_client.node(node) | |||||
for node in non_existing_nodes: | |||||
assert not(graph_client.node(node)) | |||||
def test_edge(graph_client): | |||||
existing_edges = [ | |||||
('swh:1:dir:0000000000000000000000000000000000000002', | |||||
'swh:1:cnt:0000000000000000000000000000000000000001'), | |||||
('swh:1:rev:0000000000000000000000000000000000000003', | |||||
'swh:1:dir:0000000000000000000000000000000000000002'), | |||||
('swh:1:rev:0000000000000000000000000000000000000009', | |||||
'swh:1:dir:0000000000000000000000000000000000000008'), | |||||
('swh:1:snp:0000000000000000000000000000000000000020', | |||||
'swh:1:rel:0000000000000000000000000000000000000010'), | |||||
('swh:1:ori:0000000000000000000000000000000000000021', | |||||
'swh:1:snp:0000000000000000000000000000000000000020'), | |||||
] | |||||
non_existing_edges = [ | |||||
('swh:1:dir:0000000000000000000000000000000000000002', | |||||
'swh:1:ori:0000000000000000000000000000000000000021'), | |||||
('swh:1:rev:0000000000000000000000000000000000000018', | |||||
'swh:1:cnt:0000000000000000000000000000000000000001'), | |||||
('swh:1:ori:0000000000000000000000000000000000000021', | |||||
'swh:2:inv:00invalidpidbwawaaaaaaa00000000000000020'), | |||||
] | |||||
for (src, dst) in existing_edges: | |||||
assert graph_client.edge(src, dst) | |||||
for (src, dst) in non_existing_edges: | |||||
assert not(graph_client.edge(src, dst)) | |||||
def test_leaves(graph_client): | def test_leaves(graph_client): | ||||
actual = list(graph_client.leaves( | actual = list(graph_client.leaves( | ||||
'swh:1:ori:0000000000000000000000000000000000000021' | 'swh:1:ori:0000000000000000000000000000000000000021' | ||||
)) | )) | ||||
expected = [ | expected = [ | ||||
'swh:1:cnt:0000000000000000000000000000000000000001', | 'swh:1:cnt:0000000000000000000000000000000000000001', | ||||
'swh:1:cnt:0000000000000000000000000000000000000004', | 'swh:1:cnt:0000000000000000000000000000000000000004', | ||||
'swh:1:cnt:0000000000000000000000000000000000000005', | 'swh:1:cnt:0000000000000000000000000000000000000005', | ||||
▲ Show 20 Lines • Show All 159 Lines • Show Last 20 Lines |