Refs #24366 -- Renamed arguments in MigrationGraph, renamed tests

This commit is contained in:
Marten Kenbeek 2015-02-23 14:29:28 +01:00 committed by Markus Holtermann
parent c7ec3c07e7
commit bc83add04c
2 changed files with 14 additions and 12 deletions

View File

@ -126,33 +126,35 @@ class MigrationGraph(object):
self.node_map[node].__dict__.pop('_descendants', None) self.node_map[node].__dict__.pop('_descendants', None)
self.cached = False self.cached = False
def forwards_plan(self, node): def forwards_plan(self, target):
""" """
Given a node, returns a list of which previous nodes (dependencies) Given a node, returns a list of which previous nodes (dependencies)
must be applied, ending with the node itself. must be applied, ending with the node itself.
This is the list you would follow if applying the migrations to This is the list you would follow if applying the migrations to
a database. a database.
""" """
if node not in self.nodes: if target not in self.nodes:
raise NodeNotFoundError("Node %r not a valid node" % (node, ), node) raise NodeNotFoundError("Node %r not a valid node" % (target, ), target)
# Use parent.key instead of parent to speed up the frequent hashing in ensure_not_cyclic # Use parent.key instead of parent to speed up the frequent hashing in ensure_not_cyclic
self.ensure_not_cyclic(node, lambda x: (parent.key for parent in self.node_map[x].parents)) self.ensure_not_cyclic(target, lambda x: (parent.key for parent in self.node_map[x].parents))
self.cached = True self.cached = True
return self.node_map[node].ancestors() node = self.node_map[target]
return node.ancestors()
def backwards_plan(self, node): def backwards_plan(self, target):
""" """
Given a node, returns a list of which dependent nodes (dependencies) Given a node, returns a list of which dependent nodes (dependencies)
must be unapplied, ending with the node itself. must be unapplied, ending with the node itself.
This is the list you would follow if removing the migrations from This is the list you would follow if removing the migrations from
a database. a database.
""" """
if node not in self.nodes: if target not in self.nodes:
raise NodeNotFoundError("Node %r not a valid node" % (node, ), node) raise NodeNotFoundError("Node %r not a valid node" % (target, ), target)
# Use child.key instead of child to speed up the frequent hashing in ensure_not_cyclic # Use child.key instead of child to speed up the frequent hashing in ensure_not_cyclic
self.ensure_not_cyclic(node, lambda x: (child.key for child in self.node_map[x].children)) self.ensure_not_cyclic(target, lambda x: (child.key for child in self.node_map[x].children))
self.cached = True self.cached = True
return self.node_map[node].descendants() node = self.node_map[target]
return node.descendants()
def root_nodes(self, app=None): def root_nodes(self, app=None):
""" """

View File

@ -153,7 +153,7 @@ class GraphTests(TestCase):
graph.forwards_plan, ('C', '0001') graph.forwards_plan, ('C', '0001')
) )
def test_deep_graph(self): def test_graph_recursive(self):
graph = MigrationGraph() graph = MigrationGraph()
root = ("app_a", "1") root = ("app_a", "1")
graph.add_node(root, None) graph.add_node(root, None)
@ -169,7 +169,7 @@ class GraphTests(TestCase):
self.assertEqual(expected[::-1], actual) self.assertEqual(expected[::-1], actual)
@expectedFailure @expectedFailure
def test_recursion_depth(self): def test_graph_iterative(self):
graph = MigrationGraph() graph = MigrationGraph()
root = ("app_a", "1") root = ("app_a", "1")
graph.add_node(root, None) graph.add_node(root, None)