summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Schneier <josh.schneier@gmail.com>2014-12-17 18:41:36 -0500
committerTim Graham <timograham@gmail.com>2014-12-21 16:10:43 -0500
commit9a23470072865b7aa659e6af0b275668c85bb44d (patch)
tree23b05f01699fc591213dcf3cc95dddf57c5202fe
parent653a3a4e18134803bf9cbe8668bcdd678844c995 (diff)
Fixed #24017 -- Added python_2_unicode_compatible in db/migrations
-rw-r--r--django/db/migrations/graph.py5
-rw-r--r--django/db/migrations/migration.py2
-rw-r--r--tests/migrations/test_graph.py18
3 files changed, 22 insertions, 3 deletions
diff --git a/django/db/migrations/graph.py b/django/db/migrations/graph.py
index 9046ec5ed1..0e3c5905d6 100644
--- a/django/db/migrations/graph.py
+++ b/django/db/migrations/graph.py
@@ -3,8 +3,10 @@ from collections import deque
from django.db.migrations.state import ProjectState
from django.utils.datastructures import OrderedSet
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class MigrationGraph(object):
"""
Represents the digraph of all migrations in a project.
@@ -178,6 +180,7 @@ class CircularDependencyError(Exception):
pass
+@python_2_unicode_compatible
class NodeNotFoundError(LookupError):
"""
Raised when an attempt on a node is made that is not available in the graph.
@@ -190,7 +193,5 @@ class NodeNotFoundError(LookupError):
def __str__(self):
return self.message
- __unicode__ = __str__
-
def __repr__(self):
return "NodeNotFoundError(%r)" % self.node
diff --git a/django/db/migrations/migration.py b/django/db/migrations/migration.py
index 80bdb2f126..ff9d526410 100644
--- a/django/db/migrations/migration.py
+++ b/django/db/migrations/migration.py
@@ -1,7 +1,9 @@
from __future__ import unicode_literals
from django.db.transaction import atomic
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Migration(object):
"""
The base class for all migrations.
diff --git a/tests/migrations/test_graph.py b/tests/migrations/test_graph.py
index c5ccdb79db..89ad206897 100644
--- a/tests/migrations/test_graph.py
+++ b/tests/migrations/test_graph.py
@@ -1,5 +1,6 @@
from django.test import TestCase
from django.db.migrations.graph import CircularDependencyError, MigrationGraph, NodeNotFoundError
+from django.utils.encoding import force_text
class GraphTests(TestCase):
@@ -213,7 +214,7 @@ class GraphTests(TestCase):
/ \
app_c: 0001<- <------------- x 0002
- And apply sqashing on app_c.
+ And apply squashing on app_c.
"""
graph = MigrationGraph()
@@ -229,3 +230,18 @@ class GraphTests(TestCase):
with self.assertRaises(CircularDependencyError):
graph.forwards_plan(("app_c", "0001_squashed_0002"))
+
+ def test_stringify(self):
+ graph = MigrationGraph()
+ self.assertEqual(force_text(graph), "Graph: 0 nodes, 0 edges")
+
+ graph.add_node(("app_a", "0001"), None)
+ graph.add_node(("app_a", "0002"), None)
+ graph.add_node(("app_a", "0003"), None)
+ graph.add_node(("app_b", "0001"), None)
+ graph.add_node(("app_b", "0002"), None)
+ graph.add_dependency("app_a.0002", ("app_a", "0002"), ("app_a", "0001"))
+ graph.add_dependency("app_a.0003", ("app_a", "0003"), ("app_a", "0002"))
+ graph.add_dependency("app_a.0003", ("app_a", "0003"), ("app_b", "0002"))
+
+ self.assertEqual(force_text(graph), "Graph: 5 nodes, 3 edges")