Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/tests/test_api_client.py
import pytest | import pytest | ||||
from pytest import raises | |||||
from swh.core.api import RemoteException | |||||
def test_stats(graph_client): | def test_stats(graph_client): | ||||
stats = graph_client.stats() | stats = graph_client.stats() | ||||
assert set(stats.keys()) == {'counts', 'ratios', 'indegree', | assert set(stats.keys()) == {'counts', 'ratios', 'indegree', | ||||
'outdegree'} | 'outdegree'} | ||||
assert set(stats['counts'].keys()) == {'nodes', 'edges'} | assert set(stats['counts'].keys()) == {'nodes', 'edges'} | ||||
assert set(stats['ratios'].keys()) == {'compression', 'bits_per_node', | assert set(stats['ratios'].keys()) == {'compression', 'bits_per_node', | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | actual = graph_client.count_visit_nodes( | ||||
edges='rel:rev,rev:rev' | edges='rel:rev,rev:rev' | ||||
) | ) | ||||
assert actual == 3 | assert actual == 3 | ||||
actual = graph_client.count_neighbors( | actual = graph_client.count_neighbors( | ||||
'swh:1:rev:0000000000000000000000000000000000000009', | 'swh:1:rev:0000000000000000000000000000000000000009', | ||||
direction='backward' | direction='backward' | ||||
) | ) | ||||
assert actual == 3 | assert actual == 3 | ||||
def test_param_validation(graph_client): | |||||
with raises(RemoteException): # PID not found | |||||
list(graph_client.leaves( | |||||
'swh:1:ori:fff0000000000000000000000000000000000021')) | |||||
with raises(RemoteException): # malformed PID | |||||
list(graph_client.neighbors( | |||||
'swh:1:ori:fff000000zzzzzz0000000000000000000000021')) | |||||
with raises(RemoteException): # malformed edge specificaiton | |||||
list(graph_client.walk( | |||||
'swh:1:dir:0000000000000000000000000000000000000016', 'rel', | |||||
edges='dir:notanodetype,dir:rev,rev:*', | |||||
direction='backward', | |||||
traversal='bfs', | |||||
)) | |||||
with raises(RemoteException): # malformed direction | |||||
list(graph_client.walk( | |||||
'swh:1:dir:0000000000000000000000000000000000000016', 'rel', | |||||
edges='dir:dir,dir:rev,rev:*', | |||||
direction='notadirection', | |||||
traversal='bfs', | |||||
)) | |||||
with raises(RemoteException): # malformed traversal order | |||||
list(graph_client.walk( | |||||
'swh:1:dir:0000000000000000000000000000000000000016', 'rel', | |||||
edges='dir:dir,dir:rev,rev:*', | |||||
direction='backward', | |||||
traversal='notatraversalorder', | |||||
)) |