From b6b903c0251f27318234388fa39feeab0b9cc934 Mon Sep 17 00:00:00 2001 From: Fleur Dragan Date: Tue, 16 Aug 2022 15:16:25 -0500 Subject: [PATCH] make tox -e flake8 work --- .flake8 | 1 + django_mailbox/models.py | 4 +--- django_mailbox/tests/test_mailbox.py | 16 ++++++++-------- django_mailbox/tests/test_process_email.py | 7 ++----- .../tests/test_processincomingmessage.py | 8 ++++---- django_mailbox/tests/test_transports.py | 2 +- django_mailbox/transports/generic.py | 2 -- 7 files changed, 17 insertions(+), 23 deletions(-) diff --git a/.flake8 b/.flake8 index 1f20aa3..0c14415 100644 --- a/.flake8 +++ b/.flake8 @@ -1,2 +1,3 @@ [flake8] exclude = django_mailbox/migrations, django_mailbox/south_migrations +ignore = E501,W503,W504 # line too long & line break before and after binary operator diff --git a/django_mailbox/models.py b/django_mailbox/models.py index 0f0ac9d..3efb1c2 100644 --- a/django_mailbox/models.py +++ b/django_mailbox/models.py @@ -15,7 +15,6 @@ import email import logging import mimetypes import os.path -import sys import uuid from tempfile import NamedTemporaryFile @@ -416,13 +415,12 @@ class Mailbox(models.Model): def get_new_mail(self, condition=None): """Connect to this transport and fetch new messages.""" - new_mail = [] connection = self.get_connection() if not connection: return for message in connection.get_message(condition): msg = self.process_incoming_message(message) - if not msg is None: + if msg is not None: yield msg self.last_polling = now() if django.VERSION >= (1, 5): # Django 1.5 introduces update_fields diff --git a/django_mailbox/tests/test_mailbox.py b/django_mailbox/tests/test_mailbox.py index e233f75..c9ecfab 100644 --- a/django_mailbox/tests/test_mailbox.py +++ b/django_mailbox/tests/test_mailbox.py @@ -27,20 +27,20 @@ class TestMailbox(TestCase): def test_get_new_mail_update_last_polling(self): mailbox = Mailbox.objects.create(uri="mbox://" + os.path.join( - os.path.dirname(__file__), - 'messages', - 'generic_message.eml', - )) + os.path.dirname(__file__), + 'messages', + 'generic_message.eml', + )) self.assertEqual(mailbox.last_polling, None) list(mailbox.get_new_mail()) self.assertNotEqual(mailbox.last_polling, None) def test_queryset_get_new_mail(self): mailbox = Mailbox.objects.create(uri="mbox://" + os.path.join( - os.path.dirname(__file__), - 'messages', - 'generic_message.eml', - )) + os.path.dirname(__file__), + 'messages', + 'generic_message.eml', + )) Mailbox.objects.filter(pk=mailbox.pk).get_new_mail() mailbox.refresh_from_db() self.assertNotEqual(mailbox.last_polling, None) diff --git a/django_mailbox/tests/test_process_email.py b/django_mailbox/tests/test_process_email.py index a6dbd04..f00e21b 100644 --- a/django_mailbox/tests/test_process_email.py +++ b/django_mailbox/tests/test_process_email.py @@ -1,6 +1,5 @@ import gzip import os.path -import sys import copy from unittest import mock @@ -182,7 +181,7 @@ class TestProcessEmail(EmailMessageTestCase): # it's ok to call as_string() before passing email_object # to _get_dehydrated_message() email_object.as_string() - except: + except Exception: it = 'do not works' success = True @@ -227,7 +226,7 @@ class TestProcessEmail(EmailMessageTestCase): try: # here as_string raises UnicodeEncodeError str_msg = message.as_string() - except: + except Exception: success = False msg.set_body(str_msg) @@ -423,8 +422,6 @@ class TestProcessEmail(EmailMessageTestCase): msg = self.mailbox.process_incoming_message(message) - actual_email_object = msg.get_email_object() - self.assertTrue(msg.eml.name.endswith('.eml.gz')) with gzip.open(msg.eml.name, 'rb') as f: diff --git a/django_mailbox/tests/test_processincomingmessage.py b/django_mailbox/tests/test_processincomingmessage.py index 8ba2fb2..37b3f7a 100644 --- a/django_mailbox/tests/test_processincomingmessage.py +++ b/django_mailbox/tests/test_processincomingmessage.py @@ -5,17 +5,18 @@ from django.core.management import call_command, CommandError from django.test import TestCase import django + class CommandsTestCase(TestCase): def test_processincomingmessage_no_args(self): """Check that processincomingmessage works with no args""" - + mailbox_name = None # Mock handle so that the test doesn't hang waiting for input. Note that we are only testing # the argument parsing here -- functionality should be tested elsewhere with mock.patch('django_mailbox.management.commands.processincomingmessage.Command.handle') as handle: # Don't care about the return value handle.return_value = None - + call_command('processincomingmessage') args, kwargs = handle.call_args @@ -29,7 +30,6 @@ class CommandsTestCase(TestCase): # Thus we expect an empty tuple here self.assertEqual(args, tuple()) - def test_processincomingmessage_with_arg(self): """Check that processincomingmessage works with mailbox_name given""" @@ -37,7 +37,7 @@ class CommandsTestCase(TestCase): with mock.patch('django_mailbox.management.commands.processincomingmessage.Command.handle') as handle: handle.return_value = None - + call_command('processincomingmessage', mailbox_name) args, kwargs = handle.call_args try: diff --git a/django_mailbox/tests/test_transports.py b/django_mailbox/tests/test_transports.py index 403a306..732efbe 100644 --- a/django_mailbox/tests/test_transports.py +++ b/django_mailbox/tests/test_transports.py @@ -8,7 +8,7 @@ from django_mailbox.transports import ImapTransport, Pop3Transport FAKE_UID_SEARCH_ANSWER = ( 'OK', [ - b'18 19 20 21 22 23 24 25 26 27 28 29 ' + + b'18 19 20 21 22 23 24 25 26 27 28 29 ' + b'30 31 32 33 34 35 36 37 38 39 40 41 42 43 44' ] ) diff --git a/django_mailbox/transports/generic.py b/django_mailbox/transports/generic.py index 5832fda..3042508 100644 --- a/django_mailbox/transports/generic.py +++ b/django_mailbox/transports/generic.py @@ -1,5 +1,3 @@ -import sys - from .base import EmailTransport