Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/tests/test_grpc.py
Show All 15 Lines | |||||
TEST_ORIGIN_ID = "swh:1:ori:{}".format( | TEST_ORIGIN_ID = "swh:1:ori:{}".format( | ||||
hashlib.sha1(b"https://example.com/swh/graph").hexdigest() | hashlib.sha1(b"https://example.com/swh/graph").hexdigest() | ||||
) | ) | ||||
def test_stats(graph_grpc_stub): | def test_stats(graph_grpc_stub): | ||||
stats = graph_grpc_stub.Stats(StatsRequest()) | stats = graph_grpc_stub.Stats(StatsRequest()) | ||||
assert stats.num_nodes == 21 | assert stats.num_nodes == 24 | ||||
assert stats.num_edges == 23 | assert stats.num_edges == 28 | ||||
assert isinstance(stats.compression_ratio, float) | assert isinstance(stats.compression_ratio, float) | ||||
assert isinstance(stats.bits_per_node, float) | assert isinstance(stats.bits_per_node, float) | ||||
assert isinstance(stats.bits_per_edge, float) | assert isinstance(stats.bits_per_edge, float) | ||||
assert isinstance(stats.avg_locality, float) | assert isinstance(stats.avg_locality, float) | ||||
assert stats.indegree_min == 0 | assert stats.indegree_min == 0 | ||||
assert stats.indegree_max == 3 | assert stats.indegree_max == 4 | ||||
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_leaves(graph_grpc_stub): | def test_leaves(graph_grpc_stub): | ||||
request = graph_grpc_stub.Traverse( | request = graph_grpc_stub.Traverse( | ||||
Show All 20 Lines | request = graph_grpc_stub.Traverse( | ||||
direction=GraphDirection.BACKWARD, | direction=GraphDirection.BACKWARD, | ||||
mask=FieldMask(paths=["swhid"]), | mask=FieldMask(paths=["swhid"]), | ||||
min_depth=1, | min_depth=1, | ||||
max_depth=1, | max_depth=1, | ||||
) | ) | ||||
) | ) | ||||
actual = [node.swhid for node in request] | actual = [node.swhid for node in request] | ||||
expected = [ | expected = [ | ||||
"swh:1:snp:0000000000000000000000000000000000000022", | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rel:0000000000000000000000000000000000000010", | "swh:1:rel:0000000000000000000000000000000000000010", | ||||
"swh:1:rev:0000000000000000000000000000000000000013", | "swh:1:rev:0000000000000000000000000000000000000013", | ||||
] | ] | ||||
assert set(actual) == set(expected) | assert set(actual) == set(expected) | ||||
def test_visit_nodes(graph_grpc_stub): | def test_visit_nodes(graph_grpc_stub): | ||||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |