Exclude not critical test (#2)

* Exclude not critical test

* Add exclude-tests option

* Update documentation

* Clean forgotten print

* Improve Readme, with examples
This commit is contained in:
Vladyslav Malynych authored and David Wobrock committed 2019-07-28 12:28:56 +02:00
1 parent e93d4ec4c7
commit 8eede82a38
4 files changed
+59 -4

No files matched your search

@@ -50,6 +50,10 @@ class Command(BaseCommand):
"--project-root-path", type=str, nargs="?", help="django project root path"
)
parser.add_argument(
"--exclude-tests", type=str, nargs="*", help="Specify tests to be ignored (e.g. ALTER_COLUMN)"
)
cache_group = parser.add_mutually_exclusive_group(required=False)
cache_group.add_argument(
"--cache-path",
@@ -107,6 +111,7 @@ class Command(BaseCommand):
ignore_name=options["ignore_name"],
include_apps=options["include_apps"],
exclude_apps=options["exclude_apps"],
exclude_tests=options["exclude_tests"],
database=options["database"],
cache_path=options["cache_path"],
no_cache=options["no_cache"],
+4 -1
View File
@@ -42,6 +42,7 @@ class MigrationLinter(object):
ignore_name=None,
include_apps=None,
exclude_apps=None,
exclude_tests=None,
database=DEFAULT_DB_ALIAS,
cache_path=DEFAULT_CACHE_PATH,
no_cache=False,
@@ -54,6 +55,7 @@ class MigrationLinter(object):
self.ignore_name = ignore_name or tuple()
self.include_apps = include_apps
self.exclude_apps = exclude_apps
self.exclude_tests = exclude_tests
self.database = database or DEFAULT_DB_ALIAS
self.cache_path = cache_path or DEFAULT_CACHE_PATH
self.no_cache = no_cache
@@ -118,7 +120,8 @@ class MigrationLinter(object):
return
sql_statements = self.get_sql(app_label, migration_name)
errors = analyse_sql_statements(sql_statements)
exclude_tests = self.exclude_tests or []
errors = analyse_sql_statements(sql_statements, exclude_tests)
if not errors:
print("OK")
+2 -2
View File
@@ -70,11 +70,11 @@ migration_tests = (
)
def analyse_sql_statements(sql_statements):
def analyse_sql_statements(sql_statements, exclude_tests):
errors = []
for statement in sql_statements:
for test in migration_tests:
if test["fn"](statement, errors=errors):
if test["code"] not in exclude_tests and test["fn"](statement, errors=errors):
logger.debug("Testing {0} -- ERROR".format(statement))
table_search = re.search("TABLE `([^`]*)`", statement, re.IGNORECASE)
col_search = re.search("COLUMN `([^`]*)`", statement, re.IGNORECASE)