From df67767a9af82cc1f22915bbe8bfc1931f4f9259 Mon Sep 17 00:00:00 2001 From: Jens Kleineheismann Date: Thu, 24 Oct 2019 16:05:53 +0200 Subject: [PATCH 1/4] ADD: support for pylint. --- .buildbot/test/01-requirements.sh | 1 + .buildbot/test/70-pylint.sh | 1 + .pylintrc | 25 +++++++++++++++++++++++++ apps/base/tests/test_templates.py | 6 +++--- apps/base/tests/test_views.py | 26 ++++++++++++-------------- bin/coverage-html.py | 8 ++++---- setup.py | 2 ++ 7 files changed, 48 insertions(+), 21 deletions(-) create mode 100644 .buildbot/test/70-pylint.sh create mode 100644 .pylintrc diff --git a/.buildbot/test/01-requirements.sh b/.buildbot/test/01-requirements.sh index 0704da7..b8a4c71 100644 --- a/.buildbot/test/01-requirements.sh +++ b/.buildbot/test/01-requirements.sh @@ -3,3 +3,4 @@ if test "$python_major_version" = "2" ; then pip install 'django<2' fi pip install -r requirements.txt +pip install pylint diff --git a/.buildbot/test/70-pylint.sh b/.buildbot/test/70-pylint.sh new file mode 100644 index 0000000..4d04efd --- /dev/null +++ b/.buildbot/test/70-pylint.sh @@ -0,0 +1 @@ +pylint apps.base diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..a194153 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,25 @@ +[MASTER] + +load-plugins=pylint_django + + +[MESSAGES CONTROL] + +disable=missing-module-docstring, + missing-class-docstring, + missing-function-docstring, + useless-object-inheritance, + +[BASIC] + +good-names=_, + c, + d, + e, + i, + j, + k, + +[FORMAT] + +max-line-length=120 diff --git a/apps/base/tests/test_templates.py b/apps/base/tests/test_templates.py index 6e38dbf..55c572f 100644 --- a/apps/base/tests/test_templates.py +++ b/apps/base/tests/test_templates.py @@ -6,7 +6,7 @@ from django.test import SimpleTestCase class BaseTemplateTestCase(SimpleTestCase): - def assertInHTML_multi(self, response, needles, format_kwargs=None): + def assertInHTMLMulti(self, response, needles, format_kwargs=None): # pylint: disable=invalid-name content = response.content.decode('utf-8') for needle in needles: if format_kwargs is not None: @@ -35,7 +35,7 @@ class BaseTemplateTestCase(SimpleTestCase): '', ) - self.assertInHTML_multi(response, needles, format_kwargs) + self.assertInHTMLMulti(response, needles, format_kwargs) def test_bootstrap_css_links(self): response = self.response @@ -55,7 +55,7 @@ class BaseTemplateTestCase(SimpleTestCase): '', ) - self.assertInHTML_multi(response, needles, format_kwargs) + self.assertInHTMLMulti(response, needles, format_kwargs) def test_page_footer(self): response = self.response diff --git a/apps/base/tests/test_views.py b/apps/base/tests/test_views.py index dc582ff..ed5a682 100644 --- a/apps/base/tests/test_views.py +++ b/apps/base/tests/test_views.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals import datetime -import mock import re import socket import unittest +import mock from django.test import SimpleTestCase from ..views import RootView @@ -39,20 +39,20 @@ class RootUnitTestCase(unittest.TestCase): expected_color_hex = default_color_hex with mock.patch('socket.gethostname', return_value=hostname): - v = RootView() + view = RootView() if 'kwargs' in test_data: - c = v.get_context_data(**test_data['kwargs']) + ctx = view.get_context_data(**test_data['kwargs']) else: - c = v.get_context_data() + ctx = view.get_context_data() - self.assertIsInstance(c, dict) - self.assertIn('hostname', c) - self.assertEqual(c['hostname'], hostname) - self.assertIn('color_hex', c) - self.assertTrue(re.match('[0-9a-f]{6}', c['color_hex'])) - self.assertEqual(c['color_hex'], expected_color_hex) - self.assertIn('time', c) - self.assertIsInstance(c['time'], datetime.datetime) + self.assertIsInstance(ctx, dict) + self.assertIn('hostname', ctx) + self.assertEqual(ctx['hostname'], hostname) + self.assertIn('color_hex', ctx) + self.assertTrue(re.match('[0-9a-f]{6}', ctx['color_hex'])) + self.assertEqual(ctx['color_hex'], expected_color_hex) + self.assertIn('time', ctx) + self.assertIsInstance(ctx['time'], datetime.datetime) class DjangoAdminDjangoTestCase(SimpleTestCase): @@ -80,5 +80,3 @@ class RootDjangoTestCase(SimpleTestCase): response = self.client.get('/') hostname = socket.gethostname().capitalize() self.assertContains(response, hostname) - - diff --git a/bin/coverage-html.py b/bin/coverage-html.py index 2750291..a7feee4 100755 --- a/bin/coverage-html.py +++ b/bin/coverage-html.py @@ -2,14 +2,14 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals import argparse -import coverage import datetime import os import shutil import sys +import coverage -class Command(object): +class Command(object): # pylint: disable=too-few-public-methods default_browser = 'firefox' @staticmethod @@ -64,9 +64,9 @@ class Command(object): sys.stdout.write('Report directory: {}\n'.format(report_dir)) try: self._create_report(report_dir) - except Exception as e1: + except Exception as e: self._remove_report_directory(report_dir) - raise e1 + raise e exitval = self._show_report(report_dir) return exitval diff --git a/setup.py b/setup.py index 878f559..3c0c190 100644 --- a/setup.py +++ b/setup.py @@ -110,6 +110,8 @@ class SetupDjangoProject(MyCommand): if not os.path.exists(d): os.makedirs(d) + return os.EX_OK + setup( name='django-test', From 077e25e57caf8ab690cd745877973342fc6eb85b Mon Sep 17 00:00:00 2001 From: Jens Kleineheismann Date: Thu, 24 Oct 2019 16:10:40 +0200 Subject: [PATCH 2/4] FIX df67767a9a --- .buildbot/test/01-requirements.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildbot/test/01-requirements.sh b/.buildbot/test/01-requirements.sh index b8a4c71..94ea381 100644 --- a/.buildbot/test/01-requirements.sh +++ b/.buildbot/test/01-requirements.sh @@ -3,4 +3,4 @@ if test "$python_major_version" = "2" ; then pip install 'django<2' fi pip install -r requirements.txt -pip install pylint +pip install pylint-django From e9a43740eeed8934dfa574409799900a01acd403 Mon Sep 17 00:00:00 2001 From: Jens Kleineheismann Date: Thu, 24 Oct 2019 16:33:11 +0200 Subject: [PATCH 3/4] FIX using pylint for python2. --- .buildbot/test/01-requirements.sh | 6 +++++- .pylintrc | 6 ++++-- apps/base/tests/utils.py | 3 ++- apps/base/urls.py | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.buildbot/test/01-requirements.sh b/.buildbot/test/01-requirements.sh index 94ea381..c1beb58 100644 --- a/.buildbot/test/01-requirements.sh +++ b/.buildbot/test/01-requirements.sh @@ -3,4 +3,8 @@ if test "$python_major_version" = "2" ; then pip install 'django<2' fi pip install -r requirements.txt -pip install pylint-django +if test "$python_major_version" = "2" ; then + pip install 'pylint-django<2' +else + pip install pylint-django +fi diff --git a/.pylintrc b/.pylintrc index a194153..bfd1a4a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,11 +1,13 @@ [MASTER] -load-plugins=pylint_django +persistent=no +#load-plugins=pylint_django [MESSAGES CONTROL] -disable=missing-module-docstring, +disable=missing-docstring, + missing-module-docstring, missing-class-docstring, missing-function-docstring, useless-object-inheritance, diff --git a/apps/base/tests/utils.py b/apps/base/tests/utils.py index cd8727b..4f2d087 100644 --- a/apps/base/tests/utils.py +++ b/apps/base/tests/utils.py @@ -8,5 +8,6 @@ def mkdtemp(prefix): dirname = os.path.dirname pkg_base_dir = dirname(dirname(dirname(__file__))) tmp_dir = os.path.join(pkg_base_dir, 'tmp') - os.makedirs(tmp_dir, exist_ok=True) + # os.makedirs(tmp_dir, exist_ok=True) + os.makedirs(tmp_dir) return _mkdtmp(prefix=prefix, dir=tmp_dir) diff --git a/apps/base/urls.py b/apps/base/urls.py index 4a69660..9276107 100644 --- a/apps/base/urls.py +++ b/apps/base/urls.py @@ -5,7 +5,7 @@ from django.conf.urls import url from . import views -urlpatterns = [ +urlpatterns = [ # pylint: disable=invalid-name url(r'^$', views.RootView.as_view(), name='root'), url(r'^djangoadmin/', admin.site.urls), ] From 42ef136bbea1d006ad4d8b19f8ba99eccec0b786 Mon Sep 17 00:00:00 2001 From: Jens Kleineheismann Date: Thu, 24 Oct 2019 16:37:53 +0200 Subject: [PATCH 4/4] UPD: excluded unused function apps.base.tests.utils.mkdtemp from pylint. --- apps/base/tests/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/base/tests/utils.py b/apps/base/tests/utils.py index 4f2d087..7464a0f 100644 --- a/apps/base/tests/utils.py +++ b/apps/base/tests/utils.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: skip-file from __future__ import unicode_literals import os from tempfile import mkdtemp as _mkdtmp @@ -8,6 +9,5 @@ def mkdtemp(prefix): dirname = os.path.dirname pkg_base_dir = dirname(dirname(dirname(__file__))) tmp_dir = os.path.join(pkg_base_dir, 'tmp') - # os.makedirs(tmp_dir, exist_ok=True) - os.makedirs(tmp_dir) + os.makedirs(tmp_dir, exist_ok=True) return _mkdtmp(prefix=prefix, dir=tmp_dir)