Adapt tests so that not relying on undefined

behaviour.
The app directories can appear in any order, we need to allow that
in tests.
This commit is contained in:
Felix authored and David Wobrock committed 2018-12-23 12:25:41 +01:00
1 parent 395379178b
commit 357f0aebf4
3 files changed
+50 -23

No files matched your search

+2 -1
View File
@@ -18,6 +18,7 @@ import os
import re
from subprocess import Popen, PIPE
import sys
from . import utils
from .sql_analyser import analyse_sql_statements
@@ -186,7 +187,7 @@ class MigrationLinter(object):
def _gather_all_migrations(self):
migrations = []
for root, dirs, files in os.walk(self.django_path):
for file_name in files:
for file_name in sorted(files):
if os.path.basename(root) == self.MIGRATION_FOLDER_NAME and \
file_name.endswith('.py') and \
file_name != '__init__.py':
+40 -16
View File
@@ -35,9 +35,14 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
self.assertEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 5)
self.assertTrue(lines[0].endswith('OK'))
self.assertTrue(lines[1].endswith('OK'))
self.assertTrue(lines[2].endswith('OK'))
self.assertEqual(
sorted(lines[:3]),
sorted([
"(test_app1, 0001_initial)... OK",
"(test_app1, 0002_a_new_null_field)... OK",
"(test_app2, 0001_foo)... OK",
])
)
def test_call_linter_cmd_line_errors(self):
cmd = '{0} {1}'.format(
@@ -50,7 +55,6 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
self.assertNotEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 5)
print(lines)
self.assertTrue(lines[0].endswith('OK'))
self.assertTrue(lines[1].endswith('ERR'))
self.assertTrue('RENAMING tables' in lines[2])
@@ -66,9 +70,14 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
self.assertEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 5)
self.assertTrue(lines[0].endswith('OK'))
self.assertTrue(lines[1].endswith('OK'))
self.assertTrue(lines[2].endswith('IGNORE'))
self.assertEqual(
sorted(lines[:3]),
sorted([
"(test_app1, 0001_initial)... OK",
"(test_app1, 0002_a_new_null_field)... OK",
"(test_app2, 0001_foo)... IGNORE",
])
)
def test_call_linter_cmd_line_include_apps(self):
cmd = '{0} {1} --include-apps test_app2'.format(
@@ -81,9 +90,14 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
self.assertEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 5)
self.assertTrue(lines[0].endswith('IGNORE'))
self.assertTrue(lines[1].endswith('IGNORE'))
self.assertTrue(lines[2].endswith('OK'))
self.assertEqual(
sorted(lines[:3]),
sorted([
"(test_app1, 0001_initial)... IGNORE",
"(test_app1, 0002_a_new_null_field)... IGNORE",
"(test_app2, 0001_foo)... OK",
])
)
def test_call_linter_cmd_line_ignore_name(self):
cmd = '{0} {1} --ignore-name 0001_initial'.format(
@@ -96,9 +110,14 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
self.assertEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 5)
self.assertTrue(lines[0].endswith('IGNORE'))
self.assertTrue(lines[1].endswith('OK'))
self.assertTrue(lines[2].endswith('OK'))
self.assertEqual(
sorted(lines[:3]),
sorted([
"(test_app1, 0001_initial)... IGNORE",
"(test_app1, 0002_a_new_null_field)... OK",
"(test_app2, 0001_foo)... OK",
])
)
def test_call_linter_cmd_line_ignore_name_contains(self):
cmd = '{0} {1} --ignore-name-contains 0001'.format(
@@ -111,9 +130,14 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
self.assertEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 5)
self.assertTrue(lines[0].endswith('IGNORE'))
self.assertTrue(lines[1].endswith('OK'))
self.assertTrue(lines[2].endswith('IGNORE'))
self.assertEqual(
sorted(lines[:3]),
sorted([
"(test_app1, 0001_initial)... IGNORE",
"(test_app1, 0002_a_new_null_field)... OK",
"(test_app2, 0001_foo)... IGNORE",
])
)
def test_call_linter_cmd_line_git_id(self):
cmd = '{0} {1} d7125d5f4f0cc9623f670a66c54f131acc50032d'.format(
+8 -6
View File
@@ -99,9 +99,11 @@ class TestLinterFunctions(unittest.TestCase):
linter = MigrationLinter(fixtures.CORRECT_PROJECT)
migrations = linter._gather_all_migrations()
self.assertEqual(len(migrations), 3)
self.assertEqual(migrations[0][0], 'test_app1')
self.assertEqual(migrations[0][1], '0001_initial')
self.assertEqual(migrations[1][0], 'test_app1')
self.assertEqual(migrations[1][1], '0002_a_new_null_field')
self.assertEqual(migrations[2][0], 'test_app2')
self.assertEqual(migrations[2][1], '0001_foo')
self.assertEqual(
sorted(migrations),
sorted([
("test_app1", "0001_initial"),
("test_app1", "0002_a_new_null_field"),
("test_app2", "0001_foo"),
])
)