From c9a27da877158dc6098c425d4dff34612e2c0d8e Mon Sep 17 00:00:00 2001 From: Vaclav Rehak Date: Fri, 3 May 2019 16:33:16 +0200 Subject: [PATCH 1/5] Allow BooleanField(null=True) on Django >= 2.1 as this now recommened instead of using NullBooleanField. --- flake8_django/checkers/model_fields.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/flake8_django/checkers/model_fields.py b/flake8_django/checkers/model_fields.py index 87374c5..2aecef1 100644 --- a/flake8_django/checkers/model_fields.py +++ b/flake8_django/checkers/model_fields.py @@ -1,13 +1,19 @@ +import django from .checker import Checker from .issue import Issue +ALLOW_NULL_BOOLEAN = django.VERSION >= (2, 1) + NOT_NULL_TRUE_FIELDS = [ - 'CharField', 'TextField', 'SlugField', - 'EmailField', 'UUIDField', 'ImageField', - 'FileField', 'FilePathField', 'URLField' + 'CharField', 'TextField', 'SlugField', 'EmailField', 'Field', + 'UUIDField', 'ImageField', 'FileField' ] -NOT_BLANK_TRUE_FIELDS = ['BooleanField'] +NOT_BLANK_TRUE_FIELDS = [] + +if not ALLOW_NULL_BOOLEAN: + NOT_NULL_TRUE_FIELDS.append('BooleanField') + NOT_BLANK_TRUE_FIELDS.append('BooleanField') class DJ01(Issue): From 16958453935fe4594447696f1242355064c334e6 Mon Sep 17 00:00:00 2001 From: Vaclav Rehak Date: Fri, 22 Nov 2019 08:16:54 +0100 Subject: [PATCH 2/5] Add Django to tox dependencies so tests importing Django do not fail. --- tox.ini | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index e4bf517..0b3aa4f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,24 @@ [tox] -envlist = py34,py35,py36,py37 +envlist = + django22-py{37,36} + django21-py{37,36,35} + django20-py{36,35,34} + [flake8] max-line-length = 120 exclude = tests/fixtures/* + [testenv] -deps = pytest +deps = + pytest + django20: {[django]2.0.x} + django21: {[django]2.1.x} + django22: {[django]2.2.x} + commands = pytest + +[django] +2.0.x = Django>=2.0,<2.1 +2.1.x = Django>=2.1,<2.2 +2.2.x = Django>=2.2,<2.3 From abc09563f76e192a1cf72ceab4b35106b535626d Mon Sep 17 00:00:00 2001 From: Vaclav Rehak Date: Fri, 22 Nov 2019 09:01:06 +0100 Subject: [PATCH 3/5] Run coverage test from tox --- .circleci/config.yml | 6 ------ setup.py | 2 +- tox.ini | 3 ++- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 366c67d..a832bc4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,12 +22,6 @@ jobs: command: | . venv/bin/activate git diff HEAD $(git merge-base HEAD origin/master) | flake8 --diff - - run: - name: run coverage - command: | - . venv/bin/activate - pip install -e . - py.test --cov=. --cov-fail-under=100 - run: name: upload coverage report command: | diff --git a/setup.py b/setup.py index 4fdeb1f..24592db 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ ], }, install_requires=['flake8'], - tests_require=['pytest'], + tests_require=['pytest','pytest-cov'], classifiers=[ 'Framework :: Flake8', 'License :: OSI Approved :: MIT License', diff --git a/tox.ini b/tox.ini index 0b3aa4f..48edb93 100644 --- a/tox.ini +++ b/tox.ini @@ -11,12 +11,13 @@ exclude = tests/fixtures/* [testenv] deps = pytest + pytest-cov django20: {[django]2.0.x} django21: {[django]2.1.x} django22: {[django]2.2.x} commands = - pytest + py.test --cov=./flake8_django [django] 2.0.x = Django>=2.0,<2.1 From 686cba58ec4d338081c6d3c033795a31bdc53609 Mon Sep 17 00:00:00 2001 From: Vaclav Rehak Date: Fri, 22 Nov 2019 09:06:08 +0100 Subject: [PATCH 4/5] Revert unintended change in setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 24592db..4fdeb1f 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ ], }, install_requires=['flake8'], - tests_require=['pytest','pytest-cov'], + tests_require=['pytest'], classifiers=[ 'Framework :: Flake8', 'License :: OSI Approved :: MIT License', From afcb5b4ca9989cec41b9c22207b1f5fa7856c02f Mon Sep 17 00:00:00 2001 From: Vaclav Rehak Date: Fri, 22 Nov 2019 09:55:32 +0100 Subject: [PATCH 5/5] Configure pytest-cov to append results as recommended in pytest-cov doc. --- flake8_django/checkers/model_fields.py | 1 - tox.ini | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/flake8_django/checkers/model_fields.py b/flake8_django/checkers/model_fields.py index 2aecef1..f1f02da 100644 --- a/flake8_django/checkers/model_fields.py +++ b/flake8_django/checkers/model_fields.py @@ -2,7 +2,6 @@ from .checker import Checker from .issue import Issue - ALLOW_NULL_BOOLEAN = django.VERSION >= (2, 1) NOT_NULL_TRUE_FIELDS = [ diff --git a/tox.ini b/tox.ini index 48edb93..cc32a57 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,10 @@ [tox] envlist = + clean django22-py{37,36} django21-py{37,36,35} django20-py{36,35,34} + report [flake8] max-line-length = 120 @@ -17,7 +19,18 @@ deps = django22: {[django]2.2.x} commands = - py.test --cov=./flake8_django + py.test --cov=./flake8_django --cov-append + +[testenv:clean] +deps = coverage +skip_install = true +commands = coverage erase + +[testenv:report] +skip_install = true +deps = coverage +commands = + coverage report --fail-under=100 [django] 2.0.x = Django>=2.0,<2.1