Fix tests and git migration gathering
This commit is contained in:
1 parent
c6df7e53a0
commit
7a34ac9010
5 files changed
+36
-19
No files matched your search
@@ -5,3 +5,8 @@ class Migration(object):
|
|||||||
def __init__(self, abs_path):
|
def __init__(self, abs_path):
|
||||||
self.abs_path = abs_path
|
self.abs_path = abs_path
|
||||||
self.app_name, self.name = split_migration_path(self.abs_path)
|
self.app_name, self.name = split_migration_path(self.abs_path)
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
if not isinstance(other, Migration):
|
||||||
|
return NotImplemented
|
||||||
|
return self.abs_path < other.abs_path
|
||||||
@@ -217,7 +217,7 @@ class MigrationLinter(object):
|
|||||||
re.search(r"\/{0}\/.*\.py".format(MIGRATION_FOLDER_NAME), line)
|
re.search(r"\/{0}\/.*\.py".format(MIGRATION_FOLDER_NAME), line)
|
||||||
and "__init__" not in line
|
and "__init__" not in line
|
||||||
):
|
):
|
||||||
migrations.append(Migration(line))
|
migrations.append(Migration(os.path.join(self.django_path, line)))
|
||||||
diff_process.wait()
|
diff_process.wait()
|
||||||
|
|
||||||
if diff_process.returncode != 0:
|
if diff_process.returncode != 0:
|
||||||
|
|||||||
@@ -36,13 +36,14 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
|
|||||||
process.wait()
|
process.wait()
|
||||||
self.assertEqual(process.returncode, 0)
|
self.assertEqual(process.returncode, 0)
|
||||||
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
|
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
|
||||||
self.assertEqual(len(lines), 5)
|
self.assertEqual(len(lines), 6)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(lines[:3]),
|
sorted(lines[:4]),
|
||||||
sorted([
|
sorted([
|
||||||
"(test_app1, 0001_initial)... OK",
|
"(test_app1, 0001_initial)... OK",
|
||||||
"(test_app1, 0002_a_new_null_field)... OK",
|
"(test_app1, 0002_a_new_null_field)... OK",
|
||||||
"(test_app2, 0001_foo)... OK",
|
"(test_app2, 0001_foo)... OK",
|
||||||
|
"(test_app3, 0001_initial)... OK",
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -71,13 +72,14 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
|
|||||||
process.wait()
|
process.wait()
|
||||||
self.assertEqual(process.returncode, 0)
|
self.assertEqual(process.returncode, 0)
|
||||||
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
|
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
|
||||||
self.assertEqual(len(lines), 5)
|
self.assertEqual(len(lines), 6)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(lines[:3]),
|
sorted(lines[:4]),
|
||||||
sorted([
|
sorted([
|
||||||
"(test_app1, 0001_initial)... OK",
|
"(test_app1, 0001_initial)... OK",
|
||||||
"(test_app1, 0002_a_new_null_field)... OK",
|
"(test_app1, 0002_a_new_null_field)... OK",
|
||||||
"(test_app2, 0001_foo)... IGNORE",
|
"(test_app2, 0001_foo)... IGNORE",
|
||||||
|
"(test_app3, 0001_initial)... OK",
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -91,13 +93,14 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
|
|||||||
process.wait()
|
process.wait()
|
||||||
self.assertEqual(process.returncode, 0)
|
self.assertEqual(process.returncode, 0)
|
||||||
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
|
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
|
||||||
self.assertEqual(len(lines), 5)
|
self.assertEqual(len(lines), 6)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(lines[:3]),
|
sorted(lines[:4]),
|
||||||
sorted([
|
sorted([
|
||||||
"(test_app1, 0001_initial)... IGNORE",
|
"(test_app1, 0001_initial)... IGNORE",
|
||||||
"(test_app1, 0002_a_new_null_field)... IGNORE",
|
"(test_app1, 0002_a_new_null_field)... IGNORE",
|
||||||
"(test_app2, 0001_foo)... OK",
|
"(test_app2, 0001_foo)... OK",
|
||||||
|
"(test_app3, 0001_initial)... IGNORE",
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -111,13 +114,14 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
|
|||||||
process.wait()
|
process.wait()
|
||||||
self.assertEqual(process.returncode, 0)
|
self.assertEqual(process.returncode, 0)
|
||||||
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
|
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
|
||||||
self.assertEqual(len(lines), 5)
|
self.assertEqual(len(lines), 6)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(lines[:3]),
|
sorted(lines[:4]),
|
||||||
sorted([
|
sorted([
|
||||||
"(test_app1, 0001_initial)... IGNORE",
|
"(test_app1, 0001_initial)... IGNORE",
|
||||||
"(test_app1, 0002_a_new_null_field)... OK",
|
"(test_app1, 0002_a_new_null_field)... OK",
|
||||||
"(test_app2, 0001_foo)... OK",
|
"(test_app2, 0001_foo)... OK",
|
||||||
|
"(test_app3, 0001_initial)... IGNORE",
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -131,13 +135,14 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
|
|||||||
process.wait()
|
process.wait()
|
||||||
self.assertEqual(process.returncode, 0)
|
self.assertEqual(process.returncode, 0)
|
||||||
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
|
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
|
||||||
self.assertEqual(len(lines), 5)
|
self.assertEqual(len(lines), 6)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(lines[:3]),
|
sorted(lines[:4]),
|
||||||
sorted([
|
sorted([
|
||||||
"(test_app1, 0001_initial)... IGNORE",
|
"(test_app1, 0001_initial)... IGNORE",
|
||||||
"(test_app1, 0002_a_new_null_field)... OK",
|
"(test_app1, 0002_a_new_null_field)... OK",
|
||||||
"(test_app2, 0001_foo)... IGNORE",
|
"(test_app2, 0001_foo)... IGNORE",
|
||||||
|
"(test_app3, 0001_initial)... IGNORE",
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,10 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import os
|
||||||
|
|
||||||
from django_migration_linter import MigrationLinter
|
from django_migration_linter import MigrationLinter
|
||||||
|
from django_migration_linter.migration import Migration
|
||||||
from tests import fixtures
|
from tests import fixtures
|
||||||
|
|
||||||
|
|
||||||
@@ -24,10 +26,10 @@ class TestMultipleLinters(unittest.TestCase):
|
|||||||
l2 = MigrationLinter(fixtures.RENAME_COLUMN_PROJECT)
|
l2 = MigrationLinter(fixtures.RENAME_COLUMN_PROJECT)
|
||||||
l3 = MigrationLinter(fixtures.CORRECT_PROJECT)
|
l3 = MigrationLinter(fixtures.CORRECT_PROJECT)
|
||||||
|
|
||||||
l1.lint_migration('test_app', '0002_add_new_not_null_field')
|
l1.lint_migration(Migration(os.path.join(fixtures.ADD_NOT_NULL_COLUMN_PROJECT, 'test_app/migrations/0002_add_new_not_null_field.py')))
|
||||||
l2.lint_migration('test_app', '0002_rename_column')
|
l2.lint_migration(Migration(os.path.join(fixtures.RENAME_COLUMN_PROJECT, 'test_app/migrations/0002_rename_column.py')))
|
||||||
l3.lint_migration('test_app1', '0001_initial')
|
l3.lint_migration(Migration(os.path.join(fixtures.CORRECT_PROJECT, 'test_app1/migrations/0001_initial.py')))
|
||||||
l3.lint_migration('test_app1', '0002_a_new_null_field')
|
l3.lint_migration(Migration(os.path.join(fixtures.CORRECT_PROJECT, 'test_app1/migrations/0002_a_new_null_field.py')))
|
||||||
|
|
||||||
self.assertTrue(l1.has_errors)
|
self.assertTrue(l1.has_errors)
|
||||||
self.assertTrue(l2.has_errors)
|
self.assertTrue(l2.has_errors)
|
||||||
|
|||||||
@@ -13,8 +13,10 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import os
|
||||||
|
|
||||||
from django_migration_linter import MigrationLinter
|
from django_migration_linter import MigrationLinter
|
||||||
|
from django_migration_linter.migration import Migration
|
||||||
from tests import fixtures
|
from tests import fixtures
|
||||||
|
|
||||||
|
|
||||||
@@ -32,13 +34,16 @@ class TestLinterFunctions(unittest.TestCase):
|
|||||||
linter = MigrationLinter(project_path)
|
linter = MigrationLinter(project_path)
|
||||||
self.assertFalse(linter.has_errors)
|
self.assertFalse(linter.has_errors)
|
||||||
|
|
||||||
linter.lint_migration('test_app', '0001_create_table')
|
m = Migration(os.path.join(project_path, 'test_app/migrations/0001_create_table.py'))
|
||||||
|
linter.lint_migration(m)
|
||||||
self.assertFalse(linter.has_errors)
|
self.assertFalse(linter.has_errors)
|
||||||
|
|
||||||
linter.lint_migration('test_app', '0002_add_new_not_null_field')
|
m = Migration(os.path.join(project_path, 'test_app/migrations/0002_add_new_not_null_field.py'))
|
||||||
|
linter.lint_migration(m)
|
||||||
self.assertTrue(linter.has_errors)
|
self.assertTrue(linter.has_errors)
|
||||||
|
|
||||||
linter.lint_migration('test_app', '0001_create_table')
|
m = Migration(os.path.join(project_path, 'test_app/migrations/0001_create_table.py'))
|
||||||
|
linter.lint_migration(m)
|
||||||
self.assertTrue(linter.has_errors)
|
self.assertTrue(linter.has_errors)
|
||||||
|
|
||||||
def test_linter_creation(self):
|
def test_linter_creation(self):
|
||||||
@@ -82,7 +87,7 @@ class TestLinterFunctions(unittest.TestCase):
|
|||||||
migrations = linter._gather_all_migrations()
|
migrations = linter._gather_all_migrations()
|
||||||
self.assertEqual(len(migrations), 4)
|
self.assertEqual(len(migrations), 4)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(migrations),
|
sorted([(m.app_name, m.name) for m in migrations]),
|
||||||
sorted([
|
sorted([
|
||||||
("test_app1", "0001_initial"),
|
("test_app1", "0001_initial"),
|
||||||
("test_app1", "0002_a_new_null_field"),
|
("test_app1", "0002_a_new_null_field"),
|
||||||
|
|||||||
Reference in new issue
Block a user