comparison env/lib/python3.9/site-packages/networkx/readwrite/tests/test_p2g.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import networkx as nx
2 import io
3 from networkx.readwrite.p2g import read_p2g, write_p2g
4 from networkx.testing import assert_edges_equal
5
6
7 class TestP2G:
8 @classmethod
9 def setup_class(cls):
10 cls.G = nx.Graph(name="test")
11 e = [("a", "b"), ("b", "c"), ("c", "d"), ("d", "e"), ("e", "f"), ("a", "f")]
12 cls.G.add_edges_from(e)
13 cls.G.add_node("g")
14 cls.DG = nx.DiGraph(cls.G)
15
16 def test_read_p2g(self):
17 s = b"""\
18 name
19 3 4
20 a
21 1 2
22 b
23
24 c
25 0 2
26 """
27 bytesIO = io.BytesIO(s)
28 G = read_p2g(bytesIO)
29 assert G.name == "name"
30 assert sorted(G) == ["a", "b", "c"]
31 edges = [(str(u), str(v)) for u, v in G.edges()]
32 assert_edges_equal(G.edges(), [("a", "c"), ("a", "b"), ("c", "a"), ("c", "c")])
33
34 def test_write_p2g(self):
35 s = b"""foo
36 3 2
37 1
38 1
39 2
40 2
41 3
42
43 """
44 fh = io.BytesIO()
45 G = nx.OrderedDiGraph()
46 G.name = "foo"
47 G.add_edges_from([(1, 2), (2, 3)])
48 write_p2g(G, fh)
49 fh.seek(0)
50 r = fh.read()
51 assert r == s
52
53 def test_write_read_p2g(self):
54 fh = io.BytesIO()
55 G = nx.DiGraph()
56 G.name = "foo"
57 G.add_edges_from([("a", "b"), ("b", "c")])
58 write_p2g(G, fh)
59 fh.seek(0)
60 H = read_p2g(fh)
61 assert_edges_equal(G.edges(), H.edges())