本文整理汇总了Python中arches.app.models.graph.Graph.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.copy方法的具体用法?Python Graph.copy怎么用?Python Graph.copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arches.app.models.graph.Graph
的用法示例。
在下文中一共展示了Graph.copy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_copy_graph
# 需要导入模块: from arches.app.models.graph import Graph [as 别名]
# 或者: from arches.app.models.graph.Graph import copy [as 别名]
def test_copy_graph(self):
"""
test that a copy of a graph has the same number of nodes and edges and that the primary keys have been changed
and that the actual node references are different
"""
root = models.Node.objects.get(pk=self.HERITAGE_RESOURCE_FIXTURE)
graph = Graph(root)
graph_copy = graph.copy()
self.assertEqual(len(graph.nodes), len(graph_copy.nodes))
self.assertEqual(len(graph.edges), len(graph_copy.edges))
self.assertEqual(len(graph.nodegroups), len(graph_copy.nodegroups))
def findNodeByName(graph, name):
for key, node in graph.nodes.iteritems():
if node.name == name:
return node
return None
for key, node in graph.nodes.iteritems():
node_copy = findNodeByName(graph_copy, node.name)
self.assertIsNotNone(node_copy)
self.assertNotEqual(node.pk, node_copy.pk)
self.assertNotEqual(id(node), id(node_copy))
self.assertEqual(node.is_collector(), node_copy.is_collector())
if node.nodegroup != None:
self.assertNotEqual(node.nodegroup, node_copy.nodegroup)
for key, newedge in graph_copy.edges.iteritems():
self.assertIsNotNone(graph_copy.nodes[newedge.domainnode_id])
self.assertIsNotNone(graph_copy.nodes[newedge.rangenode_id])
self.assertEqual(newedge.domainnode, graph_copy.nodes[newedge.domainnode.pk])
self.assertEqual(newedge.rangenode, graph_copy.nodes[newedge.rangenode.pk])
with self.assertRaises(KeyError):
graph.edges[newedge.pk]