diff options
| author | Yoong Kang Lim <yoongkang.lim@gmail.com> | 2015-06-01 22:46:45 +1000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-06-01 10:45:52 -0400 |
| commit | 076a63e672370ff1735e7942cd1ae0990bcbd263 (patch) | |
| tree | 744c6dd4079f36345fd06f43678f542648a22adf | |
| parent | bf07ba523a9846fa9820b87321ef4222fed98e8c (diff) | |
Fixed #24883 -- Added MigrationGraph.__repr__()
| -rw-r--r-- | django/db/migrations/graph.py | 12 | ||||
| -rw-r--r-- | tests/migrations/test_graph.py | 1 |
2 files changed, 9 insertions, 4 deletions
diff --git a/django/db/migrations/graph.py b/django/db/migrations/graph.py index 9722189fcb..8d8f41b1eb 100644 --- a/django/db/migrations/graph.py +++ b/django/db/migrations/graph.py @@ -247,10 +247,14 @@ class MigrationGraph(object): node = stack.pop() def __str__(self): - return "Graph: %s nodes, %s edges" % ( - len(self.nodes), - sum(len(node.parents) for node in self.node_map.values()), - ) + return 'Graph: %s nodes, %s edges' % self._nodes_and_edges() + + def __repr__(self): + nodes, edges = self._nodes_and_edges() + return '<%s: nodes=%s, edges=%s>' % (self.__class__.__name__, nodes, edges) + + def _nodes_and_edges(self): + return len(self.nodes), sum(len(node.parents) for node in self.node_map.values()) def make_state(self, nodes=None, at_end=True, real_apps=None): """ diff --git a/tests/migrations/test_graph.py b/tests/migrations/test_graph.py index b4252a94c8..1d517f242d 100644 --- a/tests/migrations/test_graph.py +++ b/tests/migrations/test_graph.py @@ -283,3 +283,4 @@ class GraphTests(SimpleTestCase): graph.add_dependency("app_a.0003", ("app_a", "0003"), ("app_b", "0002")) self.assertEqual(force_text(graph), "Graph: 5 nodes, 3 edges") + self.assertEqual(repr(graph), "<MigrationGraph: nodes=5, edges=3>") |
