Fixed database typo and removed unnecessary class identifier.
This commit is contained in:
parent
00ad49a143
commit
45fb349a7d
5098 changed files with 952558 additions and 85 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,58 @@
|
|||
import json
|
||||
import pytest
|
||||
import networkx as nx
|
||||
from networkx.readwrite.json_graph import adjacency_data, adjacency_graph
|
||||
|
||||
|
||||
class TestAdjacency:
|
||||
def test_graph(self):
|
||||
G = nx.path_graph(4)
|
||||
H = adjacency_graph(adjacency_data(G))
|
||||
nx.is_isomorphic(G, H)
|
||||
|
||||
def test_graph_attributes(self):
|
||||
G = nx.path_graph(4)
|
||||
G.add_node(1, color="red")
|
||||
G.add_edge(1, 2, width=7)
|
||||
G.graph["foo"] = "bar"
|
||||
G.graph[1] = "one"
|
||||
|
||||
H = adjacency_graph(adjacency_data(G))
|
||||
assert H.graph["foo"] == "bar"
|
||||
assert H.nodes[1]["color"] == "red"
|
||||
assert H[1][2]["width"] == 7
|
||||
|
||||
d = json.dumps(adjacency_data(G))
|
||||
H = adjacency_graph(json.loads(d))
|
||||
assert H.graph["foo"] == "bar"
|
||||
assert H.graph[1] == "one"
|
||||
assert H.nodes[1]["color"] == "red"
|
||||
assert H[1][2]["width"] == 7
|
||||
|
||||
def test_digraph(self):
|
||||
G = nx.DiGraph()
|
||||
nx.add_path(G, [1, 2, 3])
|
||||
H = adjacency_graph(adjacency_data(G))
|
||||
assert H.is_directed()
|
||||
nx.is_isomorphic(G, H)
|
||||
|
||||
def test_multidigraph(self):
|
||||
G = nx.MultiDiGraph()
|
||||
nx.add_path(G, [1, 2, 3])
|
||||
H = adjacency_graph(adjacency_data(G))
|
||||
assert H.is_directed()
|
||||
assert H.is_multigraph()
|
||||
|
||||
def test_multigraph(self):
|
||||
G = nx.MultiGraph()
|
||||
G.add_edge(1, 2, key="first")
|
||||
G.add_edge(1, 2, key="second", color="blue")
|
||||
H = adjacency_graph(adjacency_data(G))
|
||||
nx.is_isomorphic(G, H)
|
||||
assert H[1][2]["second"]["color"] == "blue"
|
||||
|
||||
def test_exception(self):
|
||||
with pytest.raises(nx.NetworkXError):
|
||||
G = nx.MultiDiGraph()
|
||||
attrs = dict(id="node", key="node")
|
||||
adjacency_data(G, attrs)
|
|
@ -0,0 +1,63 @@
|
|||
import json
|
||||
import pytest
|
||||
import networkx as nx
|
||||
from networkx.readwrite.json_graph import cytoscape_data, cytoscape_graph
|
||||
|
||||
|
||||
class TestCytoscape:
|
||||
def test_graph(self):
|
||||
G = nx.path_graph(4)
|
||||
H = cytoscape_graph(cytoscape_data(G))
|
||||
nx.is_isomorphic(G, H)
|
||||
|
||||
def test_graph_attributes(self):
|
||||
G = nx.path_graph(4)
|
||||
G.add_node(1, color="red")
|
||||
G.add_edge(1, 2, width=7)
|
||||
G.graph["foo"] = "bar"
|
||||
G.graph[1] = "one"
|
||||
G.add_node(3, name="node", id="123")
|
||||
|
||||
H = cytoscape_graph(cytoscape_data(G))
|
||||
assert H.graph["foo"] == "bar"
|
||||
assert H.nodes[1]["color"] == "red"
|
||||
assert H[1][2]["width"] == 7
|
||||
assert H.nodes[3]["name"] == "node"
|
||||
assert H.nodes[3]["id"] == "123"
|
||||
|
||||
d = json.dumps(cytoscape_data(G))
|
||||
H = cytoscape_graph(json.loads(d))
|
||||
assert H.graph["foo"] == "bar"
|
||||
assert H.graph[1] == "one"
|
||||
assert H.nodes[1]["color"] == "red"
|
||||
assert H[1][2]["width"] == 7
|
||||
assert H.nodes[3]["name"] == "node"
|
||||
assert H.nodes[3]["id"] == "123"
|
||||
|
||||
def test_digraph(self):
|
||||
G = nx.DiGraph()
|
||||
nx.add_path(G, [1, 2, 3])
|
||||
H = cytoscape_graph(cytoscape_data(G))
|
||||
assert H.is_directed()
|
||||
nx.is_isomorphic(G, H)
|
||||
|
||||
def test_multidigraph(self):
|
||||
G = nx.MultiDiGraph()
|
||||
nx.add_path(G, [1, 2, 3])
|
||||
H = cytoscape_graph(cytoscape_data(G))
|
||||
assert H.is_directed()
|
||||
assert H.is_multigraph()
|
||||
|
||||
def test_multigraph(self):
|
||||
G = nx.MultiGraph()
|
||||
G.add_edge(1, 2, key="first")
|
||||
G.add_edge(1, 2, key="second", color="blue")
|
||||
H = cytoscape_graph(cytoscape_data(G))
|
||||
assert nx.is_isomorphic(G, H)
|
||||
assert H[1][2]["second"]["color"] == "blue"
|
||||
|
||||
def test_exception(self):
|
||||
with pytest.raises(nx.NetworkXError):
|
||||
G = nx.MultiDiGraph()
|
||||
attrs = dict(name="node", ident="node")
|
||||
cytoscape_data(G, attrs)
|
|
@ -0,0 +1,64 @@
|
|||
import json
|
||||
import pytest
|
||||
import networkx as nx
|
||||
from networkx.readwrite.json_graph import jit_data, jit_graph
|
||||
|
||||
|
||||
class TestJIT:
|
||||
def test_jit(self):
|
||||
G = nx.Graph()
|
||||
G.add_node("Node1", node_data="foobar")
|
||||
G.add_node("Node3", node_data="bar")
|
||||
G.add_node("Node4")
|
||||
G.add_edge("Node1", "Node2", weight=9, something="isSomething")
|
||||
G.add_edge("Node2", "Node3", weight=4, something="isNotSomething")
|
||||
G.add_edge("Node1", "Node2")
|
||||
d = jit_data(G)
|
||||
K = jit_graph(json.loads(d))
|
||||
assert nx.is_isomorphic(G, K)
|
||||
|
||||
def test_jit_2(self):
|
||||
G = nx.Graph()
|
||||
G.add_node(1, node_data=3)
|
||||
G.add_node(3, node_data=0)
|
||||
G.add_edge(1, 2, weight=9, something=0)
|
||||
G.add_edge(2, 3, weight=4, something=3)
|
||||
G.add_edge(1, 2)
|
||||
d = jit_data(G)
|
||||
K = jit_graph(json.loads(d))
|
||||
assert nx.is_isomorphic(G, K)
|
||||
|
||||
def test_jit_directed(self):
|
||||
G = nx.DiGraph()
|
||||
G.add_node(1, node_data=3)
|
||||
G.add_node(3, node_data=0)
|
||||
G.add_edge(1, 2, weight=9, something=0)
|
||||
G.add_edge(2, 3, weight=4, something=3)
|
||||
G.add_edge(1, 2)
|
||||
d = jit_data(G)
|
||||
K = jit_graph(json.loads(d), create_using=nx.DiGraph())
|
||||
assert nx.is_isomorphic(G, K)
|
||||
|
||||
def test_jit_multi_directed(self):
|
||||
G = nx.MultiDiGraph()
|
||||
G.add_node(1, node_data=3)
|
||||
G.add_node(3, node_data=0)
|
||||
G.add_edge(1, 2, weight=9, something=0)
|
||||
G.add_edge(2, 3, weight=4, something=3)
|
||||
G.add_edge(1, 2)
|
||||
pytest.raises(nx.NetworkXNotImplemented, jit_data, G)
|
||||
|
||||
H = nx.DiGraph(G)
|
||||
d = jit_data(H)
|
||||
K = jit_graph(json.loads(d), create_using=nx.MultiDiGraph())
|
||||
assert nx.is_isomorphic(H, K)
|
||||
K.add_edge(1, 2)
|
||||
assert not nx.is_isomorphic(H, K)
|
||||
assert nx.is_isomorphic(G, K)
|
||||
|
||||
def test_jit_round_trip(self):
|
||||
G = nx.Graph()
|
||||
d = nx.jit_data(G)
|
||||
H = jit_graph(json.loads(d))
|
||||
K = jit_graph(d)
|
||||
assert nx.is_isomorphic(H, K)
|
|
@ -0,0 +1,104 @@
|
|||
import json
|
||||
import pytest
|
||||
import networkx as nx
|
||||
from networkx.readwrite.json_graph import node_link_data, node_link_graph
|
||||
|
||||
|
||||
class TestNodeLink:
|
||||
def test_graph(self):
|
||||
G = nx.path_graph(4)
|
||||
H = node_link_graph(node_link_data(G))
|
||||
assert nx.is_isomorphic(G, H)
|
||||
|
||||
def test_graph_attributes(self):
|
||||
G = nx.path_graph(4)
|
||||
G.add_node(1, color="red")
|
||||
G.add_edge(1, 2, width=7)
|
||||
G.graph[1] = "one"
|
||||
G.graph["foo"] = "bar"
|
||||
|
||||
H = node_link_graph(node_link_data(G))
|
||||
assert H.graph["foo"] == "bar"
|
||||
assert H.nodes[1]["color"] == "red"
|
||||
assert H[1][2]["width"] == 7
|
||||
|
||||
d = json.dumps(node_link_data(G))
|
||||
H = node_link_graph(json.loads(d))
|
||||
assert H.graph["foo"] == "bar"
|
||||
assert H.graph["1"] == "one"
|
||||
assert H.nodes[1]["color"] == "red"
|
||||
assert H[1][2]["width"] == 7
|
||||
|
||||
def test_digraph(self):
|
||||
G = nx.DiGraph()
|
||||
H = node_link_graph(node_link_data(G))
|
||||
assert H.is_directed()
|
||||
|
||||
def test_multigraph(self):
|
||||
G = nx.MultiGraph()
|
||||
G.add_edge(1, 2, key="first")
|
||||
G.add_edge(1, 2, key="second", color="blue")
|
||||
H = node_link_graph(node_link_data(G))
|
||||
nx.is_isomorphic(G, H)
|
||||
assert H[1][2]["second"]["color"] == "blue"
|
||||
|
||||
def test_graph_with_tuple_nodes(self):
|
||||
G = nx.Graph()
|
||||
G.add_edge((0, 0), (1, 0), color=[255, 255, 0])
|
||||
d = node_link_data(G)
|
||||
dumped_d = json.dumps(d)
|
||||
dd = json.loads(dumped_d)
|
||||
H = node_link_graph(dd)
|
||||
assert H.nodes[(0, 0)] == G.nodes[(0, 0)]
|
||||
assert H[(0, 0)][(1, 0)]["color"] == [255, 255, 0]
|
||||
|
||||
def test_unicode_keys(self):
|
||||
q = "qualité"
|
||||
G = nx.Graph()
|
||||
G.add_node(1, **{q: q})
|
||||
s = node_link_data(G)
|
||||
output = json.dumps(s, ensure_ascii=False)
|
||||
data = json.loads(output)
|
||||
H = node_link_graph(data)
|
||||
assert H.nodes[1][q] == q
|
||||
|
||||
def test_exception(self):
|
||||
with pytest.raises(nx.NetworkXError):
|
||||
G = nx.MultiDiGraph()
|
||||
attrs = dict(name="node", source="node", target="node", key="node")
|
||||
node_link_data(G, attrs)
|
||||
|
||||
def test_string_ids(self):
|
||||
q = "qualité"
|
||||
G = nx.DiGraph()
|
||||
G.add_node("A")
|
||||
G.add_node(q)
|
||||
G.add_edge("A", q)
|
||||
data = node_link_data(G)
|
||||
assert data["links"][0]["source"] == "A"
|
||||
assert data["links"][0]["target"] == q
|
||||
H = node_link_graph(data)
|
||||
assert nx.is_isomorphic(G, H)
|
||||
|
||||
def test_custom_attrs(self):
|
||||
G = nx.path_graph(4)
|
||||
G.add_node(1, color="red")
|
||||
G.add_edge(1, 2, width=7)
|
||||
G.graph[1] = "one"
|
||||
G.graph["foo"] = "bar"
|
||||
|
||||
attrs = dict(
|
||||
source="c_source",
|
||||
target="c_target",
|
||||
name="c_id",
|
||||
key="c_key",
|
||||
link="c_links",
|
||||
)
|
||||
|
||||
H = node_link_graph(
|
||||
node_link_data(G, attrs=attrs), multigraph=False, attrs=attrs
|
||||
)
|
||||
assert nx.is_isomorphic(G, H)
|
||||
assert H.graph["foo"] == "bar"
|
||||
assert H.nodes[1]["color"] == "red"
|
||||
assert H[1][2]["width"] == 7
|
|
@ -0,0 +1,35 @@
|
|||
import json
|
||||
import pytest
|
||||
import networkx as nx
|
||||
from networkx.readwrite.json_graph import tree_data, tree_graph
|
||||
|
||||
|
||||
class TestTree:
|
||||
def test_graph(self):
|
||||
G = nx.DiGraph()
|
||||
G.add_nodes_from([1, 2, 3], color="red")
|
||||
G.add_edge(1, 2, foo=7)
|
||||
G.add_edge(1, 3, foo=10)
|
||||
G.add_edge(3, 4, foo=10)
|
||||
H = tree_graph(tree_data(G, 1))
|
||||
nx.is_isomorphic(G, H)
|
||||
|
||||
def test_graph_attributes(self):
|
||||
G = nx.DiGraph()
|
||||
G.add_nodes_from([1, 2, 3], color="red")
|
||||
G.add_edge(1, 2, foo=7)
|
||||
G.add_edge(1, 3, foo=10)
|
||||
G.add_edge(3, 4, foo=10)
|
||||
H = tree_graph(tree_data(G, 1))
|
||||
assert H.nodes[1]["color"] == "red"
|
||||
|
||||
d = json.dumps(tree_data(G, 1))
|
||||
H = tree_graph(json.loads(d))
|
||||
assert H.nodes[1]["color"] == "red"
|
||||
|
||||
def test_exception(self):
|
||||
with pytest.raises(nx.NetworkXError):
|
||||
G = nx.MultiDiGraph()
|
||||
G.add_node(0)
|
||||
attrs = dict(id="node", children="node")
|
||||
tree_data(G, 0, attrs)
|
Loading…
Add table
Add a link
Reference in a new issue