FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
async/async/test/test_graph.py at master · gitpython-developers/async · GitHub
This repository was archived by the owner on Apr 14, 2024. It is now read-only.
gitpython-developers
async
Repository navigation
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
async
/
async
/
test
/
test_graph.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
86 lines (73 loc) · 2.88 KB
Breadcrumbs
async
/
async
/
test
/
test_graph.py
Copy path
File metadata and controls
86 lines (73 loc) · 2.88 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
#
# This module is part of async and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
"""Channel testing"""
from
.
lib
import
TestBase
from
async
.
graph
import
(
Node
,
Graph
)
import
sys
class
TestGraph
(
TestBase
):
def
test_base
(
self
):
g
=
Graph
()
nn
=
10
assert
nn
>
2
,
"need at least 3 nodes"
# add unconnected nodes
for
i
in
range
(
nn
):
assert
isinstance
(
g
.
add_node
(
Node
()),
Node
)
# END add nodes
assert
len
(
g
.
nodes
)
==
nn
# delete unconnected nodes
for
n
in
g
.
nodes
[:]:
g
.
remove_node
(
n
)
# END del nodes
# add a chain of connected nodes
last
=
None
for
i
in
range
(
nn
):
n
=
g
.
add_node
(
Node
(
i
))
if
last
:
assert
not
last
.
out_nodes
assert
not
n
.
in_nodes
assert
g
.
add_edge
(
last
,
n
)
is
g
assert
last
.
out_nodes
[
0
]
is
n
assert
n
.
in_nodes
[
0
]
is
last
last
=
n
# END for each node to connect
# try to connect a node with itself
self
.
failUnlessRaises
(
ValueError
,
g
.
add_edge
,
last
,
last
)
# try to create a cycle
self
.
failUnlessRaises
(
ValueError
,
g
.
add_edge
,
g
.
nodes
[
0
],
g
.
nodes
[
-
1
])
self
.
failUnlessRaises
(
ValueError
,
g
.
add_edge
,
g
.
nodes
[
-
1
],
g
.
nodes
[
0
])
# we have undirected edges, readding the same edge, but the other way
# around does not change anything
n1
,
n2
,
n3
=
g
.
nodes
[
0
],
g
.
nodes
[
1
],
g
.
nodes
[
2
]
g
.
add_edge
(
n1
,
n2
)
# already connected
g
.
add_edge
(
n2
,
n1
)
# same thing
assert
len
(
n1
.
out_nodes
)
==
1
assert
len
(
n1
.
in_nodes
)
==
0
assert
len
(
n2
.
in_nodes
)
==
1
assert
len
(
n2
.
out_nodes
)
==
1
# deleting a connected node clears its neighbour connections
assert
n3
.
in_nodes
[
0
]
is
n2
assert
g
.
remove_node
(
n2
)
is
g
assert
g
.
remove_node
(
n2
)
is
g
# multi-deletion okay
assert
len
(
g
.
nodes
)
==
nn
-
1
assert
len
(
n3
.
in_nodes
)
==
0
assert
len
(
n1
.
out_nodes
)
==
0
# check the history from the last node
end
=
g
.
nodes
[
-
1
]
dfirst_nodes
=
g
.
input_inclusive_dfirst_reversed
(
end
)
num_nodes_seen
=
nn
-
2
# deleted second, which leaves first one disconnected
assert
len
(
dfirst_nodes
)
==
num_nodes_seen
assert
dfirst_nodes
[
-
1
]
==
end
and
dfirst_nodes
[
-
2
].
id
==
end
.
id
-
1
# test cleanup
# its at least kept by its graph
assert
sys
.
getrefcount
(
end
)
>
3
del
(
g
)
del
(
n1
);
del
(
n2
);
del
(
n3
)
del
(
dfirst_nodes
)
del
(
last
)
del
(
n
)
assert
sys
.
getrefcount
(
end
)
==
2
Back
|
FazBrowse Home
|
New Git URL