Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
83 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
Base classes for tests | ||
""" | ||
from django.db.migrations.writer import MigrationWriter | ||
from django.test import TestCase | ||
|
||
|
||
class MigrationTestCase(TestCase): | ||
""" | ||
Based on django.tests.migrations.test_+writer.WriterTests | ||
""" | ||
def safe_exec(self, string, value=None): | ||
d = {} | ||
try: | ||
exec(string, globals(), d) | ||
except Exception as e: | ||
if value: | ||
self.fail("Could not exec %r (from value %r): %s" % (string.strip(), value, e)) | ||
else: | ||
self.fail("Could not exec %r: %s" % (string.strip(), e)) | ||
return d | ||
|
||
def serialize(self, value): | ||
""" | ||
Test a value can be serialised by the MigrationWriter | ||
""" | ||
string, imports = MigrationWriter.serialize(value) | ||
return string, imports | ||
|
||
def serialize_round_trip(self, value): | ||
""" | ||
Test a value can be serialised and deserialised | ||
""" | ||
string, imports = self.serialize(value) | ||
return self.safe_exec("%s\ntest_value_result = %s" % ("\n".join(imports), string), value)['test_value_result'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters