From f09f8c195520d1e5b665abb6f7c6b4478e4d15f5 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Sun, 29 Nov 2015 21:08:44 +0000 Subject: [PATCH] pep8: Manually resolve remaining issues The 'autopep8' tool can't do everything, and it is necessary to resolve some final issues. Most of these issues fall under the following categories: E501 line too long E241 multiple spaces after ',' F401 'module' imported but unused F841 local variable 'name' is assigned to but never used It is also necessary to insert '# noqa' comments to hide some F403 errors ('unable to detect undefined names') where 'import *' is useful. Signed-off-by: Stephen Finucane --- patchwork/bin/pwclient | 25 ++++++++-------- patchwork/filters.py | 27 ++++++++--------- patchwork/forms.py | 9 +++--- patchwork/paginator.py | 35 +++++++++++----------- patchwork/parser.py | 4 +-- patchwork/requestcontext.py | 1 - patchwork/settings/dev.py | 2 +- patchwork/settings/production.example.py | 2 +- patchwork/templatetags/person.py | 2 -- patchwork/tests/test_bundles.py | 29 +++++++++--------- patchwork/tests/test_checks.py | 10 +++---- patchwork/tests/test_encodings.py | 4 --- patchwork/tests/test_expiry.py | 6 ++-- patchwork/tests/test_filters.py | 5 +--- patchwork/tests/test_list.py | 6 +--- patchwork/tests/test_mboxviews.py | 6 ++-- patchwork/tests/test_patchparser.py | 19 ++++++------ patchwork/tests/test_person.py | 5 +--- patchwork/tests/test_registration.py | 7 ++--- patchwork/tests/test_tags.py | 2 -- patchwork/tests/test_updates.py | 4 +-- patchwork/tests/test_user.py | 4 +-- patchwork/tests/test_xmlrpc.py | 5 ++-- patchwork/tests/utils.py | 1 - patchwork/urls.py | 7 ++--- patchwork/utils.py | 38 ++++++++++-------------- patchwork/views/__init__.py | 12 ++++---- patchwork/views/base.py | 9 +++--- patchwork/views/bundle.py | 20 ++++++++----- patchwork/views/mail.py | 6 ++-- patchwork/views/user.py | 5 ++-- 31 files changed, 146 insertions(+), 171 deletions(-) diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient index be147e5a..58f23387 100755 --- a/patchwork/bin/pwclient +++ b/patchwork/bin/pwclient @@ -31,7 +31,6 @@ except ImportError: import xmlrpc.client as xmlrpclib import argparse import string -import tempfile import subprocess import base64 try: @@ -90,7 +89,7 @@ class Filter(object): else: self.d['state_id'] = id - if self.project != None: + if self.project is not None: id = project_id_by_name(rpc, self.project) if id == 0: sys.stderr.write("Note: No Project found matching %s, " @@ -112,7 +111,7 @@ class BasicHTTPAuthTransport(xmlrpclib.SafeTransport): xmlrpclib.SafeTransport.__init__(self) def authenticated(self): - return self.username != None and self.password != None + return self.username is not None and self.password is not None def send_host(self, connection, host): xmlrpclib.Transport.send_host(self, connection, host) @@ -190,7 +189,7 @@ def list_patches(patches, format_str=None): def action_list(rpc, filter, submitter_str, delegate_str, format_str=None): filter.resolve_ids(rpc) - if submitter_str != None: + if submitter_str is not None: ids = person_ids_by_name(rpc, submitter_str) if len(ids) == 0: sys.stderr.write("Note: Nobody found matching *%s*\n" % @@ -207,7 +206,7 @@ def action_list(rpc, filter, submitter_str, delegate_str, format_str=None): list_patches(patches, format_str) return - if delegate_str != None: + if delegate_str is not None: ids = person_ids_by_name(rpc, delegate_str) if len(ids) == 0: sys.stderr.write("Note: Nobody found matching *%s*\n" % @@ -551,7 +550,7 @@ def main(): update_parser.error( 'Must specify one or more update options (-a or -s)') - if args.get('n') != None: + if args.get('n') is not None: try: filt.add("max_count", args.get('n')) except: @@ -631,8 +630,8 @@ def main(): use_https) else: - sys.stderr.write(("The %s action requires authentication, " - "but no username or password\nis configured\n") % action) + sys.stderr.write("The %s action requires authentication, but no " + "username or password\nis configured\n" % action) sys.exit(1) if project_str: @@ -654,7 +653,7 @@ def main(): sys.exit(1) # It should be safe to assume hash_str is not zero, but who knows.. - if hash_str != None: + if hash_str is not None: patch_ids = [patch_id_from_hash(rpc, project_str, hash_str)] # helper for non_empty() to print correct helptext @@ -663,16 +662,16 @@ def main(): # Require either hash_str or IDs for def non_empty(h, patch_ids): """Error out if no patch IDs were specified""" - if patch_ids == None or len(patch_ids) < 1: - sys.stderr.write("Error: Missing Argument! " + - "Either [-h HASH] or [ID [ID ...]] are required\n") + if patch_ids is None or len(patch_ids) < 1: + sys.stderr.write("Error: Missing Argument! Either [-h HASH] or " + "[ID [ID ...]] are required\n") if h: h.print_help() sys.exit(1) return patch_ids if action == 'list' or action == 'search': - if args.get('patch_name') != None: + if args.get('patch_name') is not None: filt.add("name__icontains", args.get('patch_name')) action_list(rpc, filt, submitter_str, delegate_str, format_str) diff --git a/patchwork/filters.py b/patchwork/filters.py index 64fc6c31..4ee39982 100644 --- a/patchwork/filters.py +++ b/patchwork/filters.py @@ -68,8 +68,8 @@ class Filter(object): def form(self): if self.forced: - return mark_safe('%s' % (self.param, - self.condition())) + return mark_safe('%s' % ( + self.param, self.condition())) return self.condition() return self._form() @@ -201,18 +201,18 @@ class StateFilter(Filter): str += '' % (selected, self.any_key) selected = '' - if self.applied and self.state == None: + if self.applied and self.state is None: selected = 'selected' - str += '' % \ - (selected, self.action_req_str) + str += '' % ( + selected, self.action_req_str) for state in State.objects.all(): selected = '' if self.state and self.state == state: selected = ' selected="true"' - str += '' % \ - (state.id, selected, state.name) + str += '' % ( + state.id, selected, state.name) str += '' return mark_safe(str) @@ -273,7 +273,7 @@ class ArchiveFilter(Filter): self.param_map = { True: 'true', False: '', - None: 'both' + None: 'both' } self.description_map = { True: 'Yes', @@ -287,11 +287,11 @@ class ArchiveFilter(Filter): for (k, v) in self.param_map.items(): if str == v: self.archive_state = k - if self.archive_state == None: + if self.archive_state is None: self.applied = False def kwargs(self): - if self.archive_state == None: + if self.archive_state is None: return {} return {'archived': self.archive_state} @@ -299,7 +299,7 @@ class ArchiveFilter(Filter): return self.description_map[self.archive_state] def key(self): - if self.archive_state == False: + if not self.archive_state: return None return self.param_map[self.archive_state] @@ -346,7 +346,6 @@ class DelegateFilter(Filter): self.delegate = None return - applied = False try: self.delegate = User.objects.get(id=str) self.applied = True @@ -387,8 +386,8 @@ class DelegateFilter(Filter): if d == self.delegate: selected = ' selected' - str += '' % (selected, - d.id, d.profile.name()) + str += '' % ( + selected, d.id, d.profile.name()) str += '' return mark_safe(str) diff --git a/patchwork/forms.py b/patchwork/forms.py index 3b2caabf..c4eb8c52 100644 --- a/patchwork/forms.py +++ b/patchwork/forms.py @@ -37,7 +37,7 @@ class RegistrationForm(forms.Form): def clean_username(self): value = self.cleaned_data['username'] try: - user = User.objects.get(username__iexact=value) + User.objects.get(username__iexact=value) except User.DoesNotExist: return self.cleaned_data['username'] raise forms.ValidationError('This username is already taken. ' + @@ -62,8 +62,9 @@ class LoginForm(forms.Form): class BundleForm(forms.ModelForm): - name = forms.RegexField(regex=r'^[^/]+$', max_length=50, label=u'Name', - error_messages={'invalid': 'Bundle names can\'t contain slashes'}) + name = forms.RegexField( + regex=r'^[^/]+$', max_length=50, label=u'Name', + error_messages={'invalid': 'Bundle names can\'t contain slashes'}) class Meta: model = Bundle @@ -230,7 +231,7 @@ class MultiplePatchForm(forms.Form): data = self.cleaned_data # Update the instance for f in opts.fields: - if not f.name in data: + if f.name not in data: continue field = self.fields.get(f.name, None) diff --git a/patchwork/paginator.py b/patchwork/paginator.py index b8c43416..0f6d6840 100644 --- a/patchwork/paginator.py +++ b/patchwork/paginator.py @@ -46,10 +46,10 @@ class Paginator(paginator.Paginator): if request.user.is_authenticated(): patches_per_page = request.user.profile.patches_per_page - n = request.META.get('ppp') - if n: + ppp = request.META.get('ppp') + if ppp: try: - patches_per_page = int(n) + patches_per_page = int(ppp) except ValueError: pass @@ -67,28 +67,29 @@ class Paginator(paginator.Paginator): pages = self.num_pages if pages <= LEADING_PAGE_RANGE_DISPLAYED: - self.adjacent_set = [n for n in range(1, pages + 1) - if n > 0 and n <= pages] + adjacent_start = 1 + adjacent_end = pages + 1 elif page_no <= LEADING_PAGE_RANGE: - self.adjacent_set = [n for n in - range(1, LEADING_PAGE_RANGE_DISPLAYED + 1) - if n > 0 and n <= pages] + adjacent_start = 1 + adjacent_end = LEADING_PAGE_RANGE_DISPLAYED + 1 self.leading_set = [n + pages for n in range(0, -NUM_PAGES_OUTSIDE_RANGE, -1)] elif page_no > pages - TRAILING_PAGE_RANGE: - self.adjacent_set = [n for n in - range(pages - TRAILING_PAGE_RANGE_DISPLAYED + 1, - pages + 1) if n > 0 and n <= pages] - self.trailing_set = [n + 1 for n in range(0, - NUM_PAGES_OUTSIDE_RANGE)] + adjacent_start = pages - TRAILING_PAGE_RANGE_DISPLAYED + 1 + adjacent_end = pages + 1 + self.trailing_set = [n + 1 for n in + range(0, NUM_PAGES_OUTSIDE_RANGE)] else: - self.adjacent_set = [n for n in range(page_no - ADJACENT_PAGES, - page_no + ADJACENT_PAGES + 1) if n > 0 and n <= pages] + adjacent_start = page_no - ADJACENT_PAGES + adjacent_end = page_no + ADJACENT_PAGES + 1 self.leading_set = [n + pages for n in range(0, -NUM_PAGES_OUTSIDE_RANGE, -1)] self.trailing_set = [n + 1 for n in range(0, NUM_PAGES_OUTSIDE_RANGE)] + self.adjacent_set = [n for n in range(adjacent_start, adjacent_end) + if n > 0 and n <= pages] + self.leading_set.reverse() - self.long_page = \ - len(self.current_page.object_list) >= LONG_PAGE_THRESHOLD + self.long_page = len( + self.current_page.object_list) >= LONG_PAGE_THRESHOLD diff --git a/patchwork/parser.py b/patchwork/parser.py index b0804ede..453b6e85 100644 --- a/patchwork/parser.py +++ b/patchwork/parser.py @@ -89,7 +89,7 @@ def parse_patch(text): if line.startswith('--- '): state = 2 - if line.startswith('rename from ') or line.startswith('rename to '): + if line.startswith(('rename from ', 'rename to ')): state = 6 elif state == 2: @@ -161,7 +161,7 @@ def parse_patch(text): state = 5 elif state == 6: - if line.startswith('rename to ') or line.startswith('rename from '): + if line.startswith(('rename to ', 'rename from ')): patchbuf += buf + line buf = '' diff --git a/patchwork/requestcontext.py b/patchwork/requestcontext.py index ea327e56..ee26b9ba 100644 --- a/patchwork/requestcontext.py +++ b/patchwork/requestcontext.py @@ -22,7 +22,6 @@ from __future__ import absolute_import from django.conf import settings from django.contrib.sites.models import Site from django.template import RequestContext -from django.utils.html import escape from patchwork.filters import Filters from patchwork.models import Bundle, Project diff --git a/patchwork/settings/dev.py b/patchwork/settings/dev.py index c70d893e..3ecdb066 100644 --- a/patchwork/settings/dev.py +++ b/patchwork/settings/dev.py @@ -11,7 +11,7 @@ from __future__ import absolute_import import django -from .base import * +from .base import * # noqa # # Core settings diff --git a/patchwork/settings/production.example.py b/patchwork/settings/production.example.py index b9fe38a9..5530bf97 100644 --- a/patchwork/settings/production.example.py +++ b/patchwork/settings/production.example.py @@ -9,7 +9,7 @@ Design based on: from __future__ import absolute_import -from .base import * +from .base import * # noqa # # Core settings diff --git a/patchwork/templatetags/person.py b/patchwork/templatetags/person.py index 6ea7bc46..6829019f 100644 --- a/patchwork/templatetags/person.py +++ b/patchwork/templatetags/person.py @@ -19,8 +19,6 @@ from __future__ import absolute_import -import re - from django.core.urlresolvers import reverse from django import template from django.utils.html import escape diff --git a/patchwork/tests/test_bundles.py b/patchwork/tests/test_bundles.py index 4041a2fd..958bb554 100644 --- a/patchwork/tests/test_bundles.py +++ b/patchwork/tests/test_bundles.py @@ -24,7 +24,6 @@ import unittest from django.conf import settings from django.test import TestCase -from django.test.client import Client from django.utils.http import urlencode from patchwork.models import Patch, Bundle, BundlePatch, Person @@ -146,7 +145,7 @@ class BundleUpdateTest(BundleTestBase): def checkPatchformErrors(self, response): formname = 'patchform' - if not formname in response.context: + if formname not in response.context: return form = response.context[formname] if not form: @@ -186,7 +185,6 @@ class BundleUpdateTest(BundleTestBase): self.assertEqual(bundle.public, self.bundle.public) def testUpdatePublic(self): - newname = 'newbundlename' data = { 'form': 'bundle', 'action': 'update', @@ -273,7 +271,7 @@ class BundlePublicModifyTest(BundleTestBase): # first, check that we can modify with the owner self.client.login(username=self.user.username, password=self.user.username) - response = self.client.post(bundle_url(self.bundle), data) + self.client.post(bundle_url(self.bundle), data) self.bundle = Bundle.objects.get(pk=self.bundle.pk) self.assertEqual(self.bundle.name, newname) @@ -284,7 +282,7 @@ class BundlePublicModifyTest(BundleTestBase): # log in with a different user, and check that we can no longer modify self.client.login(username=self.other_user.username, password=self.other_user.username) - response = self.client.post(bundle_url(self.bundle), data) + self.client.post(bundle_url(self.bundle), data) self.bundle = Bundle.objects.get(pk=self.bundle.pk) self.assertNotEqual(self.bundle.name, newname) @@ -327,7 +325,6 @@ class BundleCreateFromListTest(BundleTestBase): self.assertEqual(bundle.patches.all()[0], patch) def testCreateNonEmptyBundleEmptyName(self): - newbundlename = 'testbundle-new' patch = self.patches[0] n_bundles = Bundle.objects.count() @@ -408,10 +405,10 @@ class BundleCreateFromPatchTest(BundleTestBase): response = self.client.post('/patch/%d/' % patch.id, params) - self.assertContains(response, - 'A bundle called %s already exists' % newbundlename) + self.assertContains( + response, + 'A bundle called %s already exists' % newbundlename) - count = Bundle.objects.count() self.assertEqual(Bundle.objects.count(), 1) @@ -514,9 +511,10 @@ class BundleAddFromPatchTest(BundleTestBase): response = self.client.post('/patch/%d/' % patch.id, params) - self.assertContains(response, - 'added to bundle "%s"' % self.bundle.name, - count=1) + self.assertContains( + response, + 'added to bundle "%s"' % self.bundle.name, + count=1) self.assertEqual(self.bundle.patches.count(), 1) self.assertEqual(self.bundle.patches.all()[0], patch) @@ -529,9 +527,10 @@ class BundleAddFromPatchTest(BundleTestBase): response = self.client.post('/patch/%d/' % patch.id, params) - self.assertContains(response, - 'added to bundle "%s"' % self.bundle.name, - count=1) + self.assertContains( + response, + 'added to bundle "%s"' % self.bundle.name, + count=1) self.assertEqual(self.bundle.patches.count(), 2) self.assertIn(self.patches[0], self.bundle.patches.all()) diff --git a/patchwork/tests/test_checks.py b/patchwork/tests/test_checks.py index e75b2581..4711b4ad 100644 --- a/patchwork/tests/test_checks.py +++ b/patchwork/tests/test_checks.py @@ -20,8 +20,6 @@ from datetime import datetime as dt from datetime import timedelta -from django.conf import settings -from django.db import connection from django.test import TransactionTestCase from patchwork.models import Patch, Check @@ -105,13 +103,13 @@ class PatchChecksTest(TransactionTestCase): self.assertChecksEqual(self.patch, [check_a, check_b]) def test_checks__duplicate_checks(self): - check_a = self.create_check(date=(dt.now() - timedelta(days=1))) - check_b = self.create_check() + self.create_check(date=(dt.now() - timedelta(days=1))) + check = self.create_check() # this isn't a realistic scenario (dates shouldn't be set by user so # they will always increment), but it's useful to verify the removal # of older duplicates by the function - check_c = self.create_check(date=(dt.now() - timedelta(days=2))) - self.assertChecksEqual(self.patch, [check_b]) + self.create_check(date=(dt.now() - timedelta(days=2))) + self.assertChecksEqual(self.patch, [check]) def test_check_count__no_checks(self): self.assertCheckCountEqual(self.patch, 0) diff --git a/patchwork/tests/test_encodings.py b/patchwork/tests/test_encodings.py index 575ef354..e39e3194 100644 --- a/patchwork/tests/test_encodings.py +++ b/patchwork/tests/test_encodings.py @@ -17,10 +17,6 @@ # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -import os -import time -import unittest - from django.test.client import Client from django.test import TestCase diff --git a/patchwork/tests/test_expiry.py b/patchwork/tests/test_expiry.py index 2f8758e5..a0596dc2 100644 --- a/patchwork/tests/test_expiry.py +++ b/patchwork/tests/test_expiry.py @@ -18,7 +18,6 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import datetime -import unittest from django.contrib.auth.models import User from django.test import TestCase @@ -95,8 +94,9 @@ class TestRegistrationExpiry(TestCase): date = ((datetime.datetime.now() - EmailConfirmation.validity) - datetime.timedelta(hours=1)) userid = 'test-user' - user = User.objects.create_user(userid, - defaults.patch_author_person.email, userid) + user = User.objects.create_user( + userid, + defaults.patch_author_person.email, userid) user.is_active = False user.date_joined = user.last_login = date user.save() diff --git a/patchwork/tests/test_filters.py b/patchwork/tests/test_filters.py index a4014b6d..72a85ced 100644 --- a/patchwork/tests/test_filters.py +++ b/patchwork/tests/test_filters.py @@ -17,12 +17,9 @@ # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -import unittest - from django.test import TestCase -from django.test.client import Client -from patchwork.tests.utils import defaults, create_user, find_in_context +from patchwork.tests.utils import defaults class FilterQueryStringTest(TestCase): diff --git a/patchwork/tests/test_list.py b/patchwork/tests/test_list.py index a9320dfe..88628580 100644 --- a/patchwork/tests/test_list.py +++ b/patchwork/tests/test_list.py @@ -20,18 +20,14 @@ from __future__ import absolute_import import datetime -import random import re -import string -import unittest from django.core.urlresolvers import reverse -from django.test.client import Client from django.test import TestCase from django.utils.six.moves import zip from patchwork.models import Person, Patch -from patchwork.tests.utils import defaults, create_user, find_in_context +from patchwork.tests.utils import defaults class EmptyPatchListTest(TestCase): diff --git a/patchwork/tests/test_mboxviews.py b/patchwork/tests/test_mboxviews.py index 0e16c0bb..9c825312 100644 --- a/patchwork/tests/test_mboxviews.py +++ b/patchwork/tests/test_mboxviews.py @@ -23,13 +23,11 @@ import datetime import dateutil.parser import dateutil.tz import email -import unittest -from django.test.client import Client from django.test import TestCase -from patchwork.models import Patch, Comment, Person -from patchwork.tests.utils import defaults, create_user, find_in_context +from patchwork.models import Patch, Comment +from patchwork.tests.utils import defaults class MboxPatchResponseTest(TestCase): diff --git a/patchwork/tests/test_patchparser.py b/patchwork/tests/test_patchparser.py index bc3dfdce..e526a79d 100644 --- a/patchwork/tests/test_patchparser.py +++ b/patchwork/tests/test_patchparser.py @@ -20,7 +20,6 @@ from email import message_from_string from email.mime.text import MIMEText from email.utils import make_msgid -import os from django.test import TestCase @@ -308,8 +307,8 @@ class MultipleProjectPatchTest(TestCase): class MultipleProjectPatchCommentTest(MultipleProjectPatchTest): - """ Test that followups to multiple-project patches end up on the - correct patch """ + """Test that followups to multiple-project patches end up on the + correct patch.""" comment_msgid = '<2@example.com>' comment_content = 'test comment' @@ -329,18 +328,19 @@ class MultipleProjectPatchCommentTest(MultipleProjectPatchTest): def testParsedComment(self): for project in [self.p1, self.p2]: patch = Patch.objects.filter(project=project)[0] - # we should see two comments now - the original mail with the patch, - # and the one we parsed in setUp() + # we should see two comments now - the original mail with the + # patch, and the one we parsed in setUp() self.assertEqual(Comment.objects.filter(patch=patch).count(), 2) class ListIdHeaderTest(TestCase): - """ Test that we parse List-Id headers from mails correctly """ + """Test that we parse List-Id headers from mails correctly.""" def setUp(self): self.project = Project(linkname='test-project-1', name='Project 1', - listid='1.example.com', listemail='1@example.com') + listid='1.example.com', + listemail='1@example.com') self.project.save() def testNoListId(self): @@ -411,8 +411,9 @@ class GitPullWithDiffTest(MBoxPatchTest): def testGitPullWithDiff(self): (patch, comment) = find_content(self.project, self.mail) self.assertTrue(patch is not None) - self.assertEqual('git://git.kernel.org/pub/scm/linux/kernel/git/tip/' + - 'linux-2.6-tip.git x86-fixes-for-linus', patch.pull_url) + self.assertEqual('git://git.kernel.org/pub/scm/linux/kernel/git/tip/' + 'linux-2.6-tip.git x86-fixes-for-linus', + patch.pull_url) self.assertTrue( patch.content.startswith( 'diff --git a/arch/x86/include/asm/smp.h'), diff --git a/patchwork/tests/test_person.py b/patchwork/tests/test_person.py index 6ced981b..ba00457d 100644 --- a/patchwork/tests/test_person.py +++ b/patchwork/tests/test_person.py @@ -20,13 +20,10 @@ from __future__ import absolute_import import json -import unittest - -from django.test.client import Client from django.test import TestCase from django.utils.six.moves import map, range -from patchwork.models import EmailConfirmation, Person, Bundle +from patchwork.models import Person class SubmitterCompletionTest(TestCase): diff --git a/patchwork/tests/test_registration.py b/patchwork/tests/test_registration.py index 296d21fe..b5eacef5 100644 --- a/patchwork/tests/test_registration.py +++ b/patchwork/tests/test_registration.py @@ -17,8 +17,6 @@ # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -import unittest - from django.contrib.auth.models import User from django.core import mail from django.core.urlresolvers import reverse @@ -81,7 +79,8 @@ class RegistrationTest(TestCase): response = self.client.post('/register/', data) self.assertEqual(response.status_code, 200) self.assertFormError(response, 'form', 'username', - 'This username is already taken. Please choose another.') + 'This username is already taken. Please choose ' + 'another.') def testExistingEmail(self): user = create_user() @@ -90,7 +89,7 @@ class RegistrationTest(TestCase): response = self.client.post('/register/', data) self.assertEqual(response.status_code, 200) self.assertFormError(response, 'form', 'email', - 'This email address is already in use ' + + 'This email address is already in use ' 'for the account "%s".\n' % user.username) def testValidRegistration(self): diff --git a/patchwork/tests/test_tags.py b/patchwork/tests/test_tags.py index 84eda9c2..70ca43d6 100644 --- a/patchwork/tests/test_tags.py +++ b/patchwork/tests/test_tags.py @@ -18,10 +18,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import datetime -import unittest from django.conf import settings -from django.db import connection from django.test import TestCase, TransactionTestCase from patchwork.models import Project, Patch, Comment, Tag, PatchTag diff --git a/patchwork/tests/test_updates.py b/patchwork/tests/test_updates.py index 819a39f9..a8d9749b 100644 --- a/patchwork/tests/test_updates.py +++ b/patchwork/tests/test_updates.py @@ -112,11 +112,11 @@ class MultipleUpdateTest(TestCase): def testDelegateChangeValid(self): delegate = create_maintainer(defaults.project) - response = self._testDelegateChange(str(delegate.pk)) + self._testDelegateChange(str(delegate.pk)) for p in self.patches: self.assertEqual(Patch.objects.get(pk=p.pk).delegate, delegate) def testDelegateClear(self): - response = self._testDelegateChange('') + self._testDelegateChange('') for p in self.patches: self.assertEqual(Patch.objects.get(pk=p.pk).delegate, None) diff --git a/patchwork/tests/test_user.py b/patchwork/tests/test_user.py index 642781e2..e9d18227 100644 --- a/patchwork/tests/test_user.py +++ b/patchwork/tests/test_user.py @@ -167,7 +167,7 @@ class UserProfileTest(TestCase): old_ppp = user_profile.patches_per_page new_ppp = old_ppp + 1 - response = self.client.post('/user/', {'patches_per_page': new_ppp}) + self.client.post('/user/', {'patches_per_page': new_ppp}) user_profile = UserProfile.objects.get(user=self.user.user.id) self.assertEqual(user_profile.patches_per_page, new_ppp) @@ -177,7 +177,7 @@ class UserProfileTest(TestCase): old_ppp = user_profile.patches_per_page new_ppp = -1 - response = self.client.post('/user/', {'patches_per_page': new_ppp}) + self.client.post('/user/', {'patches_per_page': new_ppp}) user_profile = UserProfile.objects.get(user=self.user.user.id) self.assertEqual(user_profile.patches_per_page, old_ppp) diff --git a/patchwork/tests/test_xmlrpc.py b/patchwork/tests/test_xmlrpc.py index 960b994c..d8c77f06 100644 --- a/patchwork/tests/test_xmlrpc.py +++ b/patchwork/tests/test_xmlrpc.py @@ -24,12 +24,13 @@ from django.core.urlresolvers import reverse from django.test import LiveServerTestCase from django.utils.six.moves import xmlrpc_client -from patchwork.models import Person, Patch +from patchwork.models import Patch from patchwork.tests.utils import defaults @unittest.skipUnless(settings.ENABLE_XMLRPC, - "requires xmlrpc interface (use the ENABLE_XMLRPC setting)") + 'requires xmlrpc interface (use the ENABLE_XMLRPC ' + 'setting)') class XMLRPCTest(LiveServerTestCase): fixtures = ['default_states'] diff --git a/patchwork/tests/utils.py b/patchwork/tests/utils.py index 1f573519..04250a8c 100644 --- a/patchwork/tests/utils.py +++ b/patchwork/tests/utils.py @@ -25,7 +25,6 @@ from email.utils import make_msgid import os from django.contrib.auth.models import User -from django.forms.fields import EmailField from patchwork.models import Project, Person diff --git a/patchwork/urls.py b/patchwork/urls.py index b0cc2997..81a571a1 100644 --- a/patchwork/urls.py +++ b/patchwork/urls.py @@ -43,8 +43,7 @@ urlpatterns = patterns( (r'^user/todo/$', 'patchwork.views.user.todo_lists'), (r'^user/todo/(?P[^/]+)/$', 'patchwork.views.user.todo_list'), - (r'^user/bundles/$', - 'patchwork.views.bundle.bundles'), + (r'^user/bundles/$', 'patchwork.views.bundle.bundles'), (r'^user/link/$', 'patchwork.views.user.link'), (r'^user/unlink/(?P[^/]+)/$', 'patchwork.views.user.unlink'), @@ -111,7 +110,7 @@ if settings.COMPAT_REDIR: urlpatterns += patterns( '', (r'^user/bundle/(?P[^/]+)/$', - 'patchwork.views.bundle.bundle_redir'), + 'patchwork.views.bundle.bundle_redir'), (r'^user/bundle/(?P[^/]+)/mbox/$', - 'patchwork.views.bundle.mbox_redir'), + 'patchwork.views.bundle.mbox_redir'), ) diff --git a/patchwork/utils.py b/patchwork/utils.py index bcb1e8d9..0b6594d4 100644 --- a/patchwork/utils.py +++ b/patchwork/utils.py @@ -27,13 +27,11 @@ from django.contrib.auth.models import User from django.contrib.sites.models import Site from django.core.mail import EmailMessage from django.db.models import Max, Q, F -from django.db.utils import IntegrityError from django.shortcuts import get_object_or_404 from django.template.loader import render_to_string -from patchwork.models import (Bundle, Project, BundlePatch, UserProfile, - PatchChangeNotification, EmailOptout, - EmailConfirmation) +from patchwork.models import (Bundle, BundlePatch, PatchChangeNotification, + EmailOptout, EmailConfirmation) def get_patch_ids(d, prefix='patch_id'): @@ -54,11 +52,11 @@ def get_patch_ids(d, prefix='patch_id'): class Order(object): order_map = { - 'date': 'date', - 'name': 'name', - 'state': 'state__ordering', - 'submitter': 'submitter__name', - 'delegate': 'delegate__username', + 'date': 'date', + 'name': 'name', + 'state': 'state__ordering', + 'submitter': 'submitter__name', + 'delegate': 'delegate__username', } default_order = ('date', True) @@ -180,18 +178,17 @@ def set_bundle(user, project, action, data, patches, context): def send_notifications(): - date_limit = datetime.datetime.now() - \ - datetime.timedelta(minutes=settings.NOTIFICATION_DELAY_MINUTES) + date_limit = datetime.datetime.now() - datetime.timedelta( + minutes=settings.NOTIFICATION_DELAY_MINUTES) # This gets funky: we want to filter out any notifications that should # be grouped with other notifications that aren't ready to go out yet. To # do that, we join back onto PatchChangeNotification (PCN -> Patch -> # Person -> Patch -> max(PCN.last_modified)), filtering out any maxima # that are with the date_limit. - qs = PatchChangeNotification.objects \ - .annotate(m=Max('patch__submitter__patch__patchchangenotification' - '__last_modified')) \ - .filter(m__lt=date_limit) + qs = PatchChangeNotification.objects.annotate( + m=Max('patch__submitter__patch__patchchangenotification' + '__last_modified')).filter(m__lt=date_limit) groups = itertools.groupby(qs.order_by('patch__submitter'), lambda n: n.patch.submitter) @@ -230,7 +227,7 @@ def send_notifications(): try: message.send() - except ex: + except Exception as ex: errors.append((recipient, ex)) continue @@ -247,12 +244,9 @@ def do_expiry(): # expire inactive users with no pending confirmation pending_confs = EmailConfirmation.objects.values('user') - users = User.objects.filter( - is_active=False, - last_login=F('date_joined') - ).exclude( - id__in=pending_confs - ) + users = User.objects.filter(is_active=False, + last_login=F('date_joined')).exclude( + id__in=pending_confs) # delete users users.delete() diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py index 0386a799..bf6cad15 100644 --- a/patchwork/views/__init__.py +++ b/patchwork/views/__init__.py @@ -27,11 +27,11 @@ from email.parser import HeaderParser import email.utils import re -from .base import * +from .base import * # noqa from patchwork.utils import Order, get_patch_ids, bundle_actions, set_bundle from patchwork.paginator import Paginator from patchwork.forms import MultiplePatchForm -from patchwork.models import Comment +from patchwork.models import Comment, Patch def generic_list(request, project, view, @@ -119,10 +119,10 @@ def generic_list(request, project, view, paginator = Paginator(request, patches) context.update({ - 'page': paginator.current_page, - 'patchform': properties_form, - 'project': project, - 'order': order, + 'page': paginator.current_page, + 'patchform': properties_form, + 'project': project, + 'order': order, }) return context diff --git a/patchwork/views/base.py b/patchwork/views/base.py index 14885508..cd9c43f0 100644 --- a/patchwork/views/base.py +++ b/patchwork/views/base.py @@ -28,7 +28,7 @@ from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.shortcuts import render_to_response, get_object_or_404 from django.template.loader import render_to_string -from patchwork.models import Patch, Project, Person, EmailConfirmation +from patchwork.models import Project, Person, EmailConfirmation from patchwork.requestcontext import PatchworkRequestContext @@ -122,8 +122,8 @@ def submitter_complete(request): return HttpResponse(json.dumps(data), content_type="application/json") -help_pages = {'': 'index.html', - 'about/': 'about.html', +help_pages = {'': 'index.html', + 'about/': 'about.html', } if settings.ENABLE_XMLRPC: @@ -133,5 +133,6 @@ if settings.ENABLE_XMLRPC: def help(request, path): context = PatchworkRequestContext(request) if path in help_pages: - return render_to_response('patchwork/help/' + help_pages[path], context) + return render_to_response( + 'patchwork/help/' + help_pages[path], context) raise Http404 diff --git a/patchwork/views/bundle.py b/patchwork/views/bundle.py index 3ae9f6ef..04067ffc 100644 --- a/patchwork/views/bundle.py +++ b/patchwork/views/bundle.py @@ -20,9 +20,9 @@ from __future__ import absolute_import from django.contrib.auth.decorators import login_required -from django.contrib.auth.models import User import django.core.urlresolvers -from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound +from django.http import (HttpResponse, HttpResponseRedirect, + HttpResponseNotFound) from django.shortcuts import render_to_response, get_object_or_404 from patchwork.filters import DelegateFilter @@ -59,7 +59,8 @@ def setbundle(request): bundle.save() elif action == 'add': bundle = get_object_or_404(Bundle, - owner=request.user, id=request.POST['id']) + owner=request.user, + id=request.POST['id']) bundle.save() patch_id = request.get('patch_id', None) @@ -165,14 +166,17 @@ def bundle(request, username, bundlename): else: form = BundleForm(instance=bundle) - if request.method == 'POST' and \ - request.POST.get('form') == 'reorderform': - order = get_object_or_404(BundlePatch, bundle=bundle, - patch__id=request.POST.get('order_start')).order + if (request.method == 'POST' and + request.POST.get('form') == 'reorderform'): + order = get_object_or_404( + BundlePatch, + bundle=bundle, + patch__id=request.POST.get('order_start')).order for patch_id in request.POST.getlist('neworder'): bundlepatch = get_object_or_404(BundlePatch, - bundle=bundle, patch__id=patch_id) + bundle=bundle, + patch__id=patch_id) bundlepatch.order = order bundlepatch.save() order += 1 diff --git a/patchwork/views/mail.py b/patchwork/views/mail.py index 10b842d4..6336af66 100644 --- a/patchwork/views/mail.py +++ b/patchwork/views/mail.py @@ -112,9 +112,9 @@ def optinout(request, action, description): conf_settings.DEFAULT_FROM_EMAIL, [email]) context['email'] = mail context['email_sent'] = True - except Exception as ex: - context['error'] = 'An error occurred during confirmation . ' + \ - 'Please try again later.' + except Exception: + context['error'] = ('An error occurred during confirmation . ' + 'Please try again later.') context['admins'] = conf_settings.ADMINS return render_to_response(html_template, context) diff --git a/patchwork/views/user.py b/patchwork/views/user.py index 443545d1..529a3bd3 100644 --- a/patchwork/views/user.py +++ b/patchwork/views/user.py @@ -62,8 +62,9 @@ def register(request): mail_ctx = {'site': Site.objects.get_current(), 'confirmation': conf} - subject = render_to_string('patchwork/activation_email_subject.txt', - mail_ctx).replace('\n', ' ').strip() + subject = render_to_string( + 'patchwork/activation_email_subject.txt', + mail_ctx).replace('\n', ' ').strip() message = render_to_string('patchwork/activation_email.txt', mail_ctx) -- 2.47.3