Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/tests/test_http_client.py
Show All 37 Lines | 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", | ||||
"swh:1:cnt:0000000000000000000000000000000000000007", | "swh:1:cnt:0000000000000000000000000000000000000007", | ||||
] | ] | ||||
assert set(actual) == set(expected) | assert set(actual) == set(expected) | ||||
@pytest.mark.parametrize("max_matching_nodes", [0, 1, 2, 3, 4, 5, 10, 1 << 31]) | |||||
def test_leaves_with_limit(graph_client, max_matching_nodes): | |||||
actual = list( | |||||
graph_client.leaves(TEST_ORIGIN_ID, max_matching_nodes=max_matching_nodes) | |||||
) | |||||
expected = [ | |||||
"swh:1:cnt:0000000000000000000000000000000000000001", | |||||
"swh:1:cnt:0000000000000000000000000000000000000004", | |||||
"swh:1:cnt:0000000000000000000000000000000000000005", | |||||
"swh:1:cnt:0000000000000000000000000000000000000007", | |||||
] | |||||
if max_matching_nodes == 0: | |||||
assert set(actual) == set(expected) | |||||
else: | |||||
assert set(actual) <= set(expected) | |||||
assert len(actual) == min(4, max_matching_nodes) | |||||
def test_neighbors(graph_client): | def test_neighbors(graph_client): | ||||
actual = list( | actual = list( | ||||
graph_client.neighbors( | graph_client.neighbors( | ||||
"swh:1:rev:0000000000000000000000000000000000000009", direction="backward" | "swh:1:rev:0000000000000000000000000000000000000009", direction="backward" | ||||
) | ) | ||||
) | ) | ||||
expected = [ | expected = [ | ||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
▲ Show 20 Lines • Show All 267 Lines • ▼ Show 20 Lines | def test_count(graph_client): | ||||
) | ) | ||||
assert actual == 3 | assert actual == 3 | ||||
actual = graph_client.count_neighbors( | actual = graph_client.count_neighbors( | ||||
"swh:1:rev:0000000000000000000000000000000000000009", direction="backward" | "swh:1:rev:0000000000000000000000000000000000000009", direction="backward" | ||||
) | ) | ||||
assert actual == 3 | assert actual == 3 | ||||
@pytest.mark.parametrize("max_matching_nodes", [0, 1, 2, 3, 4, 5, 10, 1 << 31]) | |||||
def test_count_with_limit(graph_client, max_matching_nodes): | |||||
actual = graph_client.count_leaves( | |||||
TEST_ORIGIN_ID, max_matching_nodes=max_matching_nodes | |||||
) | |||||
if max_matching_nodes == 0: | |||||
assert actual == 4 | |||||
else: | |||||
assert actual == min(4, max_matching_nodes) | |||||
def test_param_validation(graph_client): | def test_param_validation(graph_client): | ||||
with raises(GraphArgumentException) as exc_info: # SWHID not found | with raises(GraphArgumentException) as exc_info: # SWHID not found | ||||
list(graph_client.leaves("swh:1:rel:00ffffffff000000000000000000000000000010")) | list(graph_client.leaves("swh:1:rel:00ffffffff000000000000000000000000000010")) | ||||
if exc_info.value.response: | if exc_info.value.response: | ||||
assert exc_info.value.response.status_code == 404 | assert exc_info.value.response.status_code == 404 | ||||
with raises(GraphArgumentException) as exc_info: # malformed SWHID | with raises(GraphArgumentException) as exc_info: # malformed SWHID | ||||
list( | list( | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |