1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
import pytest
from redis.commands.graph import edge, node, path
@pytest.mark.redismod
def test_init():
with pytest.raises(TypeError):
path.Path(None, None)
path.Path([], None)
path.Path(None, [])
assert isinstance(path.Path([], []), path.Path)
@pytest.mark.redismod
def test_new_empty_path():
new_empty_path = path.Path.new_empty_path()
assert isinstance(new_empty_path, path.Path)
assert new_empty_path._nodes == []
assert new_empty_path._edges == []
@pytest.mark.redismod
def test_wrong_flows():
node_1 = node.Node(node_id=1)
node_2 = node.Node(node_id=2)
node_3 = node.Node(node_id=3)
edge_1 = edge.Edge(node_1, None, node_2)
edge_2 = edge.Edge(node_1, None, node_3)
p = path.Path.new_empty_path()
with pytest.raises(AssertionError):
p.add_edge(edge_1)
p.add_node(node_1)
with pytest.raises(AssertionError):
p.add_node(node_2)
p.add_edge(edge_1)
with pytest.raises(AssertionError):
p.add_edge(edge_2)
@pytest.mark.redismod
def test_nodes_and_edges():
node_1 = node.Node(node_id=1)
node_2 = node.Node(node_id=2)
edge_1 = edge.Edge(node_1, None, node_2)
p = path.Path.new_empty_path()
assert p.nodes() == []
p.add_node(node_1)
assert [] == p.edges()
assert 0 == p.edge_count()
assert [node_1] == p.nodes()
assert node_1 == p.get_node(0)
assert node_1 == p.first_node()
assert node_1 == p.last_node()
assert 1 == p.nodes_count()
p.add_edge(edge_1)
assert [edge_1] == p.edges()
assert 1 == p.edge_count()
assert edge_1 == p.get_relationship(0)
p.add_node(node_2)
assert [node_1, node_2] == p.nodes()
assert node_1 == p.first_node()
assert node_2 == p.last_node()
assert 2 == p.nodes_count()
@pytest.mark.redismod
def test_compare():
node_1 = node.Node(node_id=1)
node_2 = node.Node(node_id=2)
edge_1 = edge.Edge(node_1, None, node_2)
assert path.Path.new_empty_path() == path.Path.new_empty_path()
assert path.Path(nodes=[node_1, node_2], edges=[edge_1]) == path.Path(
nodes=[node_1, node_2], edges=[edge_1]
)
assert path.Path(nodes=[node_1], edges=[]) != path.Path(nodes=[], edges=[])
assert path.Path(nodes=[node_1], edges=[]) != path.Path(nodes=[], edges=[])
assert path.Path(nodes=[node_1], edges=[]) != path.Path(nodes=[node_2], edges=[])
assert path.Path(nodes=[node_1], edges=[edge_1]) != path.Path(
nodes=[node_1], edges=[]
)
assert path.Path(nodes=[node_1], edges=[edge_1]) != path.Path(
nodes=[node_2], edges=[edge_1]
)
|