• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python testing.assert_graphs_equal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中networkx.testing.assert_graphs_equal函数的典型用法代码示例。如果您正苦于以下问题:Python assert_graphs_equal函数的具体用法?Python assert_graphs_equal怎么用?Python assert_graphs_equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了assert_graphs_equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_exceptions

    def test_exceptions(self):
        # _prep_create_using
        G = {"a": "a"}
        H = nx.to_networkx_graph(G)
        assert_graphs_equal(H, nx.Graph([('a', 'a')]))
        assert_raises(TypeError, to_networkx_graph, G, create_using=0.0)

        # NX graph
        class G(object):
            adj = None

        assert_raises(nx.NetworkXError, to_networkx_graph, G)

        # pygraphviz  agraph
        class G(object):
            is_strict = None

        assert_raises(nx.NetworkXError, to_networkx_graph, G)

        # Dict of [dicts, lists]
        G = {"a": 0}
        assert_raises(TypeError, to_networkx_graph, G)

        # list or generator of edges
        class G(object):
            next = None

        assert_raises(nx.NetworkXError, to_networkx_graph, G)

        # no match
        assert_raises(nx.NetworkXError, to_networkx_graph, "a")
开发者ID:ProgVal,项目名称:networkx,代码行数:31,代码来源:test_convert.py


示例2: test_from_edgelist_int_attr_name

 def test_from_edgelist_int_attr_name(self):
     # note: this also tests that edge_attr can be `source`
     Gtrue = nx.Graph([('E', 'C', {0: 'C'}),
                       ('B', 'A', {0: 'B'}),
                       ('A', 'D', {0: 'A'})])
     G = nx.from_pandas_edgelist(self.df, 0, 'b', 0)
     assert_graphs_equal(G, Gtrue)
开发者ID:jianantian,项目名称:networkx,代码行数:7,代码来源:test_convert_pandas.py


示例3: test_from_edgelist_multidigraph_and_edge_attr

 def test_from_edgelist_multidigraph_and_edge_attr(self):
     # example from issue #2374
     Gtrue = nx.MultiDiGraph([('X1', 'X4', {'Co': 'zA', 'Mi': 0, 'St': 'X1'}),
                              ('X1', 'X4', {'Co': 'zB', 'Mi': 54, 'St': 'X2'}),
                              ('X1', 'X4', {'Co': 'zB', 'Mi': 49, 'St': 'X3'}),
                              ('X1', 'X4', {'Co': 'zB', 'Mi': 44, 'St': 'X4'}),
                              ('Y1', 'Y3', {'Co': 'zC', 'Mi': 0, 'St': 'Y1'}),
                              ('Y1', 'Y3', {'Co': 'zC', 'Mi': 34, 'St': 'Y2'}),
                              ('Y1', 'Y3', {'Co': 'zC', 'Mi': 29, 'St': 'X2'}),
                              ('Y1', 'Y3', {'Co': 'zC', 'Mi': 24, 'St': 'Y3'}),
                              ('Z1', 'Z3', {'Co': 'zD', 'Mi': 0, 'St': 'Z1'}),
                              ('Z1', 'Z3', {'Co': 'zD', 'Mi': 14, 'St': 'X3'}),
                              ('Z1', 'Z3', {'Co': 'zE', 'Mi': 9, 'St': 'Z2'}),
                              ('Z1', 'Z3', {'Co': 'zE', 'Mi': 4, 'St': 'Z3'})])
     df = pd.DataFrame.from_items([
         ('O', ['X1', 'X1', 'X1', 'X1', 'Y1', 'Y1', 'Y1', 'Y1', 'Z1', 'Z1', 'Z1', 'Z1']),
         ('D', ['X4', 'X4', 'X4', 'X4', 'Y3', 'Y3', 'Y3', 'Y3', 'Z3', 'Z3', 'Z3', 'Z3']),
         ('St', ['X1', 'X2', 'X3', 'X4', 'Y1', 'Y2', 'X2', 'Y3', 'Z1', 'X3', 'Z2', 'Z3']),
         ('Co', ['zA', 'zB', 'zB', 'zB', 'zC', 'zC', 'zC', 'zC', 'zD', 'zD', 'zE', 'zE']),
         ('Mi', [0,   54,   49,   44,    0,   34,   29,   24,    0,   14,    9,   4])])
     G1 = nx.from_pandas_edgelist(df, source='O', target='D',
                                  edge_attr=True,
                                  create_using=nx.MultiDiGraph())
     G2 = nx.from_pandas_edgelist(df, source='O', target='D',
                                  edge_attr=['St', 'Co', 'Mi'],
                                  create_using=nx.MultiDiGraph())
     assert_graphs_equal(G1, Gtrue)
     assert_graphs_equal(G2, Gtrue)
开发者ID:ProgVal,项目名称:networkx,代码行数:28,代码来源:test_convert_pandas.py


示例4: pydot_checks

    def pydot_checks(self, G):
        G.add_edge('A','B')
        G.add_edge('A','C')
        G.add_edge('B','C')
        G.add_edge('A','D')
        G.add_node('E')
        P = nx.to_pydot(G)
        G2 = G.__class__(nx.from_pydot(P))
        assert_graphs_equal(G, G2)

        fname = tempfile.mktemp()
        assert_true( P.write_raw(fname) )

        Pin = pydotplus.graph_from_dot_file(fname)

        n1 = sorted([p.get_name() for p in P.get_node_list()])
        n2 = sorted([p.get_name() for p in Pin.get_node_list()])
        assert_true( n1 == n2 )

        e1=[(e.get_source(),e.get_destination()) for e in P.get_edge_list()]
        e2=[(e.get_source(),e.get_destination()) for e in Pin.get_edge_list()]
        assert_true( sorted(e1)==sorted(e2) )

        Hin = nx.drawing.nx_pydot.read_dot(fname)
        Hin = G.__class__(Hin)
        assert_graphs_equal(G, Hin)
开发者ID:argriffing,项目名称:networkx,代码行数:26,代码来源:test_pydot.py


示例5: test_read_write

 def test_read_write(self):
     G = nx.MultiGraph()
     G.graph['name'] = 'G'
     G.add_edge('1', '2', key='0')  # read assumes strings
     fh = StringIO()
     nx.nx_pydot.write_dot(G, fh)
     fh.seek(0)
     H = nx.nx_pydot.read_dot(fh)
     assert_graphs_equal(G, H)
开发者ID:ProgVal,项目名称:networkx,代码行数:9,代码来源:test_pydot.py


示例6: test_connected_components_with_size

    def test_connected_components_with_size(self):
        self.assertEqual(len(self.G.connected_components_with_size(3)),
                         len([self.expected_three1, self.expected_three2]))
        # unfortunately cannot test that two lists of graphs are
        # equal, so only test length of lists here, and then that the
        # graph in the list of len=1 below is equal. Hopefully this is
        # enough.

        returned_four = self.G.connected_components_with_size(4)[0]
        nxt.assert_graphs_equal(returned_four, self.expected_four)
开发者ID:infolab-csail,项目名称:wikimap,代码行数:10,代码来源:test_graph.py


示例7: test_symmetric

    def test_symmetric(self):
        """Tests that a symmetric matrix has edges added only once to an
        undirected multigraph when using
        :func:`networkx.from_scipy_sparse_matrix`.

        """
        A = sparse.csr_matrix([[0, 1], [1, 0]])
        G = nx.from_scipy_sparse_matrix(A, create_using=nx.MultiGraph())
        expected = nx.MultiGraph()
        expected.add_edge(0, 1, weight=1)
        assert_graphs_equal(G, expected)
开发者ID:argriffing,项目名称:networkx,代码行数:11,代码来源:test_convert_scipy.py


示例8: test_roundtrip

 def test_roundtrip(self):
     # edgelist
     Gtrue = nx.Graph([(1, 1), (1, 2)])
     df = nx.to_pandas_edgelist(Gtrue)
     G = nx.from_pandas_edgelist(df)
     assert_graphs_equal(Gtrue, G)
     # adjacency
     Gtrue = nx.Graph(({1: {1: {'weight': 1}, 2: {'weight': 1}}, 2: {1: {'weight': 1}}}))
     df = nx.to_pandas_adjacency(Gtrue, dtype=int)
     G = nx.from_pandas_adjacency(df)
     assert_graphs_equal(Gtrue, G)
开发者ID:ProgVal,项目名称:networkx,代码行数:11,代码来源:test_convert_pandas.py


示例9: test_from_edgelist_all_attr

 def test_from_edgelist_all_attr(self):
     Gtrue = nx.Graph([('E', 'C', {'cost': 9, 'weight': 10}),
                       ('B', 'A', {'cost': 1, 'weight': 7}),
                       ('A', 'D', {'cost': 7, 'weight': 4})])
     G = nx.from_pandas_edgelist(self.df, 0, 'b', True)
     assert_graphs_equal(G, Gtrue)
     # MultiGraph
     MGtrue = nx.MultiGraph(Gtrue)
     MGtrue.add_edge('A', 'D', cost=16, weight=4)
     MG = nx.from_pandas_edgelist(self.mdf, 0, 'b', True, nx.MultiGraph())
     assert_graphs_equal(MG, MGtrue)
开发者ID:ProgVal,项目名称:networkx,代码行数:11,代码来源:test_convert_pandas.py


示例10: test_round_trip

 def test_round_trip(self):
     G = nx.Graph()
     A = nx.nx_agraph.to_agraph(G)
     H = nx.nx_agraph.from_agraph(A)
     #assert_graphs_equal(G, H)
     AA = nx.nx_agraph.to_agraph(H)
     HH = nx.nx_agraph.from_agraph(AA)
     assert_graphs_equal(H, HH)
     G.graph['graph'] = {}
     G.graph['node'] = {}
     G.graph['edge'] = {}
     assert_graphs_equal(G, HH)
开发者ID:jianantian,项目名称:networkx,代码行数:12,代码来源:test_agraph.py


示例11: test_read_multiline_adjlist_1

    def test_read_multiline_adjlist_1(self):
        # Unit test for https://networkx.lanl.gov/trac/ticket/252
        s = b"""# comment line
1 2
# comment line
2
3
"""
        bytesIO = io.BytesIO(s)
        G = nx.read_multiline_adjlist(bytesIO)
        adj = {'1': {'3': {}, '2': {}}, '3': {'1': {}}, '2': {'1': {}}}
        assert_graphs_equal(G, nx.Graph(adj))
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:12,代码来源:test_adjlist.py


示例12: test_from_scipy_sparse_matrix_parallel_edges

    def test_from_scipy_sparse_matrix_parallel_edges(self):
        """Tests that the :func:`networkx.from_scipy_sparse_matrix` function
        interprets integer weights as the number of parallel edges when
        creating a multigraph.

        """
        A = sparse.csr_matrix([[1, 1], [1, 2]])
        # First, with a simple graph, each integer entry in the adjacency
        # matrix is interpreted as the weight of a single edge in the graph.
        expected = nx.DiGraph()
        edges = [(0, 0), (0, 1), (1, 0)]
        expected.add_weighted_edges_from([(u, v, 1) for (u, v) in edges])
        expected.add_edge(1, 1, weight=2)
        actual = nx.from_scipy_sparse_matrix(A, parallel_edges=True,
                                             create_using=nx.DiGraph())
        assert_graphs_equal(actual, expected)
        actual = nx.from_scipy_sparse_matrix(A, parallel_edges=False,
                                             create_using=nx.DiGraph())
        assert_graphs_equal(actual, expected)
        # Now each integer entry in the adjacency matrix is interpreted as the
        # number of parallel edges in the graph if the appropriate keyword
        # argument is specified.
        edges = [(0, 0), (0, 1), (1, 0), (1, 1), (1, 1)]
        expected = nx.MultiDiGraph()
        expected.add_weighted_edges_from([(u, v, 1) for (u, v) in edges])
        actual = nx.from_scipy_sparse_matrix(A, parallel_edges=True,
                                             create_using=nx.MultiDiGraph())
        assert_graphs_equal(actual, expected)
        expected = nx.MultiDiGraph()
        expected.add_edges_from(set(edges), weight=1)
        # The sole self-loop (edge 0) on vertex 1 should have weight 2.
        expected[1][1][0]['weight'] = 2
        actual = nx.from_scipy_sparse_matrix(A, parallel_edges=False,
                                             create_using=nx.MultiDiGraph())
        assert_graphs_equal(actual, expected)
开发者ID:argriffing,项目名称:networkx,代码行数:35,代码来源:test_convert_scipy.py


示例13: test_unicode

 def test_unicode(self):
     G = nx.Graph()
     try:  # Python 3.x
         name1 = chr(2344) + chr(123) + chr(6543)
         name2 = chr(5543) + chr(1543) + chr(324)
     except ValueError:  # Python 2.6+
         name1 = unichr(2344) + unichr(123) + unichr(6543)
         name2 = unichr(5543) + unichr(1543) + unichr(324)
     G.add_edge(name1, 'Radiohead', **{name2: 3})
     fd, fname = tempfile.mkstemp()
     nx.write_multiline_adjlist(G, fname)
     H = nx.read_multiline_adjlist(fname)
     assert_graphs_equal(G, H)
     os.close(fd)
     os.unlink(fname)
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:15,代码来源:test_adjlist.py


示例14: test_latin1

 def test_latin1(self):
     G = nx.Graph()
     try:  # Python 3.x
         blurb = chr(1245)  # just to trigger the exception
         name1 = "Bj" + chr(246) + "rk"
         name2 = chr(220) + "ber"
     except ValueError:  # Python 2.6+
         name1 = "Bj" + unichr(246) + "rk"
         name2 = unichr(220) + "ber"
     G.add_edge(name1, "Radiohead", {name2: 3})
     fd, fname = tempfile.mkstemp()
     nx.write_multiline_adjlist(G, fname, encoding="latin-1")
     H = nx.read_multiline_adjlist(fname, encoding="latin-1")
     assert_graphs_equal(G, H)
     os.close(fd)
     os.unlink(fname)
开发者ID:nishnik,项目名称:networkx,代码行数:16,代码来源:test_adjlist.py


示例15: test_latin1

 def test_latin1(self):
     G = nx.Graph()
     try:  # Python 3.x
         blurb = chr(1245)  # just to trigger the exception
         name1 = 'Bj' + chr(246) + 'rk'
         name2 = chr(220) + 'ber'
     except ValueError:  # Python 2.6+
         name1 = 'Bj' + unichr(246) + 'rk'
         name2 = unichr(220) + 'ber'
     G.add_edge(name1, 'Radiohead', **{name2: 3})
     fd, fname = tempfile.mkstemp()
     nx.write_multiline_adjlist(G, fname, encoding='latin-1')
     H = nx.read_multiline_adjlist(fname, encoding='latin-1')
     assert_graphs_equal(G, H)
     os.close(fd)
     os.unlink(fname)
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:16,代码来源:test_adjlist.py


示例16: test_unicode

 def test_unicode(self):
     G = nx.Graph()
     try: # Python 3.x
         name1 = chr(2344) + chr(123) + chr(6543)
         name2 = chr(5543) + chr(1543) + chr(324)
     except ValueError: # Python 2.6+
         name1 = unichr(2344) + unichr(123) + unichr(6543)
         name2 = unichr(5543) + unichr(1543) + unichr(324)
     G.add_edge(name1, 'Radiohead', attr_dict={name2: 3})
     G.add_node(name1,bipartite=0)
     G.add_node('Radiohead',bipartite=1)
     fd, fname = tempfile.mkstemp()
     bipartite.write_edgelist(G, fname)
     H = bipartite.read_edgelist(fname)
     assert_graphs_equal(G, H)
     os.close(fd)
     os.unlink(fname)
开发者ID:666888,项目名称:networkx,代码行数:17,代码来源:test_edgelist.py


示例17: test_latin1

 def test_latin1(self):
     G = nx.Graph()
     try: # Python 3.x
         blurb = chr(1245) # just to trigger the exception
         name1 = 'Bj' + chr(246) + 'rk'
         name2 = chr(220) + 'ber'
     except ValueError: # Python 2.6+
         name1 = 'Bj' + unichr(246) + 'rk'
         name2 = unichr(220) + 'ber'
     G.add_edge(name1, 'Radiohead', attr_dict={name2: 3})
     G.add_node(name1,bipartite=0)
     G.add_node('Radiohead',bipartite=1)
     fd, fname = tempfile.mkstemp()
     bipartite.write_edgelist(G, fname, encoding = 'latin-1')
     H = bipartite.read_edgelist(fname, encoding = 'latin-1')
     assert_graphs_equal(G, H)
     os.close(fd)
     os.unlink(fname)
开发者ID:666888,项目名称:networkx,代码行数:18,代码来源:test_edgelist.py


示例18: test_connected_component_with_node

    def test_connected_component_with_node(self):
        # "X" is a hub
        returned_three1 = self.G.connected_component_with_node("X")
        nxt.assert_graphs_equal(returned_three1, self.expected_three1)

        # "beta" is not a hub
        returned_three2 = self.G.connected_component_with_node("beta")
        nxt.assert_graphs_equal(returned_three2, self.expected_three2)

        # "A" is a hub
        returned_four = self.G.connected_component_with_node("A")
        nxt.assert_graphs_equal(returned_four, self.expected_four)
开发者ID:infolab-csail,项目名称:wikimap,代码行数:12,代码来源:test_graph.py


示例19: test_simple_graphs

    def test_simple_graphs(self):
        for dest, source in [(to_dict_of_dicts, from_dict_of_dicts),
                             (to_dict_of_lists, from_dict_of_lists)]:
            G = barbell_graph(10, 3)
            G.graph = {}
            dod = dest(G)

            # Dict of [dicts, lists]
            GG = source(dod)
            assert_graphs_equal(G, GG)
            GW = to_networkx_graph(dod)
            assert_graphs_equal(G, GW)
            GI = nx.Graph(dod)
            assert_graphs_equal(G, GI)

            # With nodelist keyword
            P4 = nx.path_graph(4)
            P3 = nx.path_graph(3)
            P4.graph = {}
            P3.graph = {}
            dod = dest(P4, nodelist=[0, 1, 2])
            Gdod = nx.Graph(dod)
            assert_graphs_equal(Gdod, P3)
开发者ID:jklaise,项目名称:networkx,代码行数:23,代码来源:test_convert.py


示例20: test_from_edgelist_no_attr

 def test_from_edgelist_no_attr(self):
     Gtrue = nx.Graph([('E', 'C', {}),
                       ('B', 'A', {}),
                       ('A', 'D', {})])
     G = nx.from_pandas_edgelist(self.df, 0, 'b',)
     assert_graphs_equal(G, Gtrue)
开发者ID:ProgVal,项目名称:networkx,代码行数:6,代码来源:test_convert_pandas.py



注:本文中的networkx.testing.assert_graphs_equal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testing.assert_nodes_equal函数代码示例发布时间:2022-05-27
下一篇:
Python testing.assert_edges_equal函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap