Commits

Greg Ward committed 24feb20

Make all lines < 80 columns (more PEP 8 conformance)

  • Participants
  • Parent commits 5f0c676

Comments (0)

Files changed (2)

File src/eximunit/smtp.py

         if failMsg:
             raise AssertionError(failMsg)
         else:
-            raise AssertionError('Expected match for %s but got %s' % (regex, msg))
+            raise AssertionError('Expected match for %s but got %s' %
+                                 (regex, msg))
 
 
 class SMTPTestingSession(object):
-    """A single SMTP session with methods for performing commands and making
-       assertions about the results. This class should not contain anything Exim-specific."""
+    """A single SMTP session with methods for performing commands and
+    making assertions about the results. This class should not contain
+    anything Exim-specific."""
     def __init__(self, fromIP, debug=False):
         self.fromIP = fromIP
         self.debug = debug
         self._openConnection()
 
     def _openConnection(self):
-        """open the connection and say HELO (implicit for now)
-           Theoretically you could override this method to sort out a Python SMTP session to
-           any server, not just Exim."""
+        """Open the connection and say HELO (implicit for now).
+        Theoretically you could override this method to sort out a Python
+        SMTP session to any server, not just Exim."""
         self.smtp = EximDebugSMTP(fromHost=self.fromIP, debug=self.debug)
         self.smtp.helo()        # TODO optional support for ESMTP?
 
         code, resp = self.smtp.rcpt(rcpt)
         _assertResponse(MAILBOX_UNAVAILABLE, code, resp)
         if expectedMessage:
-            assertMatches(expectedMessage, resp, "Response message did not match expectation")
+            assertMatches(expectedMessage, resp,
+                          "Response message did not match expectation")
         return self
 
     def randomData(self):
-        """Sends a 'random' message as the DATA and asserts that it's accepted"""
+        """Send a 'random' message as the DATA and assert that it's
+        accepted."""
         msg = """From: Fred Smith <fred@example.com>
 To: Bob Jones <bob@example.com>
 Subject: Testing
         return result
 
     def _getData(self, fileName):
-        dataFile = os.path.join(os.path.abspath(os.path.dirname(__file__)), fileName)
+        dataFile = os.path.join(
+            os.path.abspath(os.path.dirname(__file__)), fileName)
         with open(dataFile, 'r') as f:
             return f.read()
 
     def data(self, data):
-        """Sends an SMTP DATA command with the given data, and asserts that it worked"""
+        """Send an SMTP DATA command with the given data and assert that it
+        worked."""
         code, resp = self.smtp.data(data)
         assert ACCEPTED == code, resp
         return self
 
 
 class EximDebugSMTP(SMTP):
-    """Extension of smtplb's SMTP which is backed by an Exim fake SMTP sesion"""
+    """SMTP client which is backed by a fake Exim SMTP session."""
 
     def __init__(self, fromHost, debug, *args, **kwargs):
         kwargs['host'] = 'localhost'
 
     def _get_socket(self, host, port, timeout):
         if host != 'localhost':
-            raise Exception('Exim sessions are only supported to localhost, not %s' % host)
+            raise Exception('Exim sessions are only supported to localhost, '
+                            'not %s' % host)
         return self._get_exim_socket()
 
     def _get_exim_socket(self):
         # first, spawn nc wrapping the exim debug session on a spare local port
         # TODO redirect exim stderr to a file we can fish it out of
         port = findFreePorts()[0]
+        eximCmd = '/usr/sbin/exim4 -bhc %s 2>exim-debug.log' % self.fromHost
         ncCmd = ['nc', '-l', '-p', str(port), '-s', '127.0.0.1',
-                 '-c', '/usr/sbin/exim4 -bhc %s 2>exim-debug.log' % self.fromHost]
+                 '-c', eximCmd]
         if self.debuglevel > 0:
-            print "Spawning exim on port %s with incoming address %s" % (port, self.fromHost)
+            print("Spawning exim on port %s with incoming address %s" %
+                  (port, self.fromHost))
         ncProcess = Popen(ncCmd, stdout=PIPE)
          # TODO maybe just fork nc?
         threading.Thread(target=ncProcess.communicate).start()

File src/eximunit/test.py

         self.fromIP = ipAddress
 
     def setDebug(self, debug):
-        """Debug is off by default. Set to True to print the raw SMTP session"""
+        """Pass true to print the raw SMTP session (False by default)."""
         self.debug = debug
 
     def newSession(self):
         if not hasattr(self, 'fromIP'):
-            raise Exception('You must specify the from IP address before starting a session')
+            raise Exception('You must specify the from IP address before '
+                            'starting a session')
         session = SMTPTestingSession(self.fromIP, self.debug)
         self.sessions.append(session)
         return session