Exemplo n.º 1
0
    def test_specials(self):
        from math import isnan

        inf, nan = float("inf"), float("nan")
        G = eg.Graph()
        G.add_node(1, testattr=inf, strdata="inf", key="a")
        G.add_node(2, testattr=nan, strdata="nan", key="b")
        G.add_node(3, testattr=-inf, strdata="-inf", key="c")

        fh = io.BytesIO()
        eg.write_gexf(G, fh)
        fh.seek(0)
        filetext = fh.read()
        fh.seek(0)
        H = eg.read_gexf(fh, node_type=int)

        assert b"INF" in filetext
        assert b"NaN" in filetext
        assert b"-INF" in filetext

        assert H.nodes[1]["testattr"] == inf
        assert isnan(H.nodes[2]["testattr"])
        assert H.nodes[3]["testattr"] == -inf

        assert H.nodes[1]["strdata"] == "inf"
        assert H.nodes[2]["strdata"] == "nan"
        assert H.nodes[3]["strdata"] == "-inf"

        assert H.nodes[1]["easygraph_key"] == "a"
        assert H.nodes[2]["easygraph_key"] == "b"
        assert H.nodes[3]["easygraph_key"] == "c"
Exemplo n.º 2
0
 def test_bool(self):
     G = eg.Graph()
     G.add_node(1, testattr=True)
     fh = io.BytesIO()
     eg.write_gexf(G, fh)
     fh.seek(0)
     H = eg.read_gexf(fh, node_type=int)
     assert H.nodes[1]["testattr"]
Exemplo n.º 3
0
 def test_simple_list(self):
     G = eg.Graph()
     list_value = [(1, 2, 3), (9, 1, 2)]
     G.add_node(1, key=list_value)
     fh = io.BytesIO()
     eg.write_gexf(G, fh)
     fh.seek(0)
     H = eg.read_gexf(fh, node_type=int)
     assert H.nodes[1]["easygraph_key"] == list_value
Exemplo n.º 4
0
 def test_serialize_ints_to_strings(self):
     G = eg.Graph()
     G.add_node(1, id=7, label=77)
     fh = io.BytesIO()
     eg.write_gexf(G, fh)
     fh.seek(0)
     H = eg.read_gexf(fh, node_type=int)
     assert list(H) == [7]
     assert H.nodes[7]["label"] == "77"
Exemplo n.º 5
0
 def test_write_read_simple_directed_graphml(self):
     G = self.simple_directed_graph
     fh = io.BytesIO()
     eg.write_gexf(G, fh)
     fh.seek(0)
     H = eg.read_gexf(fh)
     assert sorted(G.nodes) == sorted(H.nodes)
     assert sorted(G.edges) == sorted(H.edges)
     self.simple_directed_fh.seek(0)
Exemplo n.º 6
0
 def test_add_parent(self):
     G = eg.Graph()
     G.add_node(0, label="1", color="green", parents=[1, 2])
     fh = io.BytesIO()
     eg.write_gexf(G, fh)
     fh.seek(0)
     H = eg.read_gexf(fh, node_type=int)
     assert sorted(G.nodes) == sorted(H.nodes)
     assert sorted(sorted(e)
                   for e in G.edges) == sorted(sorted(e) for e in H.edges)
Exemplo n.º 7
0
 def test_dynamic_mode(self):
     G = eg.Graph()
     G.add_node(1, label="1", color="green")
     G.graph["mode"] = "dynamic"
     fh = io.BytesIO()
     eg.write_gexf(G, fh)
     fh.seek(0)
     H = eg.read_gexf(fh, node_type=int)
     assert sorted(G.nodes) == sorted(H.nodes)
     assert sorted(sorted(e)
                   for e in G.edges) == sorted(sorted(e) for e in H.edges)
Exemplo n.º 8
0
 def test_default_attribute(self):
     G = eg.Graph()
     G.add_node(1, label="1", color="green")
     eg.add_path(G, [0, 1, 2, 3])
     G.add_edge(1, 2, foo=3)
     G.graph["node_default"] = {"color": "yellow"}
     G.graph["edge_default"] = {"foo": 7}
     fh = io.BytesIO()
     eg.write_gexf(G, fh)
     fh.seek(0)
     H = eg.read_gexf(fh, node_type=int)
     assert sorted(G.nodes) == sorted(H.nodes)
     # Reading a gexf graph always sets mode attribute to either
     # 'static' or 'dynamic'. Remove the mode attribute from the
     # read graph for the sake of comparing remaining attributes.
     del H.graph["mode"]
     assert G.graph == H.graph
Exemplo n.º 9
0
    def test_slice_and_spell(self):
        # Test spell first, so version = 1.2
        G = eg.Graph()
        G.add_node(0, label="1", color="green")
        G.nodes[0]["spells"] = [(1, 2)]
        fh = io.BytesIO()
        eg.write_gexf(G, fh)
        fh.seek(0)
        H = eg.read_gexf(fh, node_type=int)
        assert sorted(G.nodes) == sorted(H.nodes)
        assert sorted(sorted(e)
                      for e in G.edges) == sorted(sorted(e) for e in H.edges)

        G = eg.Graph()
        G.add_node(0, label="1", color="green")
        G.nodes[0]["slices"] = [(1, 2)]
        fh = io.BytesIO()
        eg.write_gexf(G, fh, version="1.1draft")
        fh.seek(0)
        H = eg.read_gexf(fh, node_type=int)
        assert sorted(G.nodes) == sorted(H.nodes)
        assert sorted(sorted(e)
                      for e in G.edges) == sorted(sorted(e) for e in H.edges)