Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/readwrite/json_graph/tests/test_jit.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 json | |
2 import pytest | |
3 import networkx as nx | |
4 from networkx.readwrite.json_graph import jit_data, jit_graph | |
5 | |
6 | |
7 class TestJIT: | |
8 def test_jit(self): | |
9 G = nx.Graph() | |
10 G.add_node("Node1", node_data="foobar") | |
11 G.add_node("Node3", node_data="bar") | |
12 G.add_node("Node4") | |
13 G.add_edge("Node1", "Node2", weight=9, something="isSomething") | |
14 G.add_edge("Node2", "Node3", weight=4, something="isNotSomething") | |
15 G.add_edge("Node1", "Node2") | |
16 d = jit_data(G) | |
17 K = jit_graph(json.loads(d)) | |
18 assert nx.is_isomorphic(G, K) | |
19 | |
20 def test_jit_2(self): | |
21 G = nx.Graph() | |
22 G.add_node(1, node_data=3) | |
23 G.add_node(3, node_data=0) | |
24 G.add_edge(1, 2, weight=9, something=0) | |
25 G.add_edge(2, 3, weight=4, something=3) | |
26 G.add_edge(1, 2) | |
27 d = jit_data(G) | |
28 K = jit_graph(json.loads(d)) | |
29 assert nx.is_isomorphic(G, K) | |
30 | |
31 def test_jit_directed(self): | |
32 G = nx.DiGraph() | |
33 G.add_node(1, node_data=3) | |
34 G.add_node(3, node_data=0) | |
35 G.add_edge(1, 2, weight=9, something=0) | |
36 G.add_edge(2, 3, weight=4, something=3) | |
37 G.add_edge(1, 2) | |
38 d = jit_data(G) | |
39 K = jit_graph(json.loads(d), create_using=nx.DiGraph()) | |
40 assert nx.is_isomorphic(G, K) | |
41 | |
42 def test_jit_multi_directed(self): | |
43 G = nx.MultiDiGraph() | |
44 G.add_node(1, node_data=3) | |
45 G.add_node(3, node_data=0) | |
46 G.add_edge(1, 2, weight=9, something=0) | |
47 G.add_edge(2, 3, weight=4, something=3) | |
48 G.add_edge(1, 2) | |
49 pytest.raises(nx.NetworkXNotImplemented, jit_data, G) | |
50 | |
51 H = nx.DiGraph(G) | |
52 d = jit_data(H) | |
53 K = jit_graph(json.loads(d), create_using=nx.MultiDiGraph()) | |
54 assert nx.is_isomorphic(H, K) | |
55 K.add_edge(1, 2) | |
56 assert not nx.is_isomorphic(H, K) | |
57 assert nx.is_isomorphic(G, K) | |
58 | |
59 def test_jit_round_trip(self): | |
60 G = nx.Graph() | |
61 d = nx.jit_data(G) | |
62 H = jit_graph(json.loads(d)) | |
63 K = jit_graph(d) | |
64 assert nx.is_isomorphic(H, K) |