Integrate IGNORE into cache
This commit is contained in:
4 files changed
+27
-3
No files matched your search
@@ -41,6 +41,7 @@ class Cache(dict):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
print(self)
|
||||||
f = open(self.filename, 'wb')
|
f = open(self.filename, 'wb')
|
||||||
pickle.dump(self, f, 2)
|
pickle.dump(self, f, 2)
|
||||||
f.close()
|
f.close()
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ class MigrationLinter(object):
|
|||||||
|
|
||||||
if analysis_result['ignored']:
|
if analysis_result['ignored']:
|
||||||
print('IGNORE')
|
print('IGNORE')
|
||||||
|
self.new_cache[md5hash] = {'result': 'IGNORE'}
|
||||||
self.nb_ignored += 1
|
self.nb_ignored += 1
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ else:
|
|||||||
import mock
|
import mock
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CacheTest(unittest.TestCase):
|
class CacheTest(unittest.TestCase):
|
||||||
MIGRATION_FILE = os.path.join(fixtures.ALTER_COLUMN_PROJECT, 'test_app', 'migrations', '0001_initial.py')
|
MIGRATION_FILE = os.path.join(fixtures.ALTER_COLUMN_PROJECT, 'test_app', 'migrations', '0001_initial.py')
|
||||||
fd, temp_path = tempfile.mkstemp()
|
fd, temp_path = tempfile.mkstemp()
|
||||||
@@ -73,7 +72,30 @@ class CacheTest(unittest.TestCase):
|
|||||||
self.assertTrue(linter.has_errors)
|
self.assertTrue(linter.has_errors)
|
||||||
|
|
||||||
def test_cache_ignored(self):
|
def test_cache_ignored(self):
|
||||||
pass
|
cache_file = os.path.join(DEFAULT_CACHE_PATH, 'test_project_ignore_migration.pickle')
|
||||||
|
if os.path.exists(cache_file):
|
||||||
|
os.remove(cache_file)
|
||||||
|
linter = MigrationLinter(fixtures.IGNORE_MIGRATION_PROJECT)
|
||||||
|
|
||||||
|
with mock.patch.object(MigrationLinter, 'get_sql', wraps=linter.get_sql)as sql_mock:
|
||||||
|
linter.lint_all_migrations()
|
||||||
|
sql_mock.assert_called()
|
||||||
|
|
||||||
|
cache = Cache(
|
||||||
|
fixtures.IGNORE_MIGRATION_PROJECT,
|
||||||
|
DEFAULT_CACHE_PATH
|
||||||
|
)
|
||||||
|
cache.load()
|
||||||
|
|
||||||
|
self.assertEqual(cache['63230606af0eccaef7f1f78c537c624c']['result'], 'OK')
|
||||||
|
self.assertEqual(cache['5c5ca1780a9f28439c1defc1f32af894']['result'], 'IGNORE')
|
||||||
|
|
||||||
|
# Start the Linter again -> should use cache now.
|
||||||
|
linter = MigrationLinter(fixtures.IGNORE_MIGRATION_PROJECT)
|
||||||
|
|
||||||
|
with mock.patch.object(MigrationLinter, 'get_sql', wraps=linter.get_sql)as sql_mock:
|
||||||
|
linter.lint_all_migrations()
|
||||||
|
sql_mock.assert_not_called()
|
||||||
|
|
||||||
def test_cache_modified(self):
|
def test_cache_modified(self):
|
||||||
cache_file = os.path.join(DEFAULT_CACHE_PATH, 'test_project_alter_column.pickle')
|
cache_file = os.path.join(DEFAULT_CACHE_PATH, 'test_project_alter_column.pickle')
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
|
|||||||
fixtures.CORRECT_PROJECT)
|
fixtures.CORRECT_PROJECT)
|
||||||
|
|
||||||
process = Popen(
|
process = Popen(
|
||||||
cmd, shell=True, stdout=PIPE, stderr=sys.stderr)
|
cmd, shell=True, stdout=PIPE, stderr=PIPE)
|
||||||
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()))
|
||||||
|
|||||||
Reference in new issue
Block a user