Greg Ward  committed 34a9ac1

Rename local variables and function params for PEP 8 conformance.

Actually, this conforms to the *spirit* of PEP 8 more than the letter.
PEP 8 says

Function names should be lowercase, with words separated by
underscores as necessary to improve readability.

mixedCase is allowed only in contexts where that's already the
prevailing style (e.g., to retain backwards

but it doesn't say anything about the case of local variables or
parameters. However, this change is fairly safe from a backwards
compatibility perspective, and makes the code look much more Pythonic
(and more consistent with smtplib, FWIW).

  • Participants
  • Parent commits 24feb20
  • Branches default

Comments (0)

Files changed (2)

File src/eximunit/

-def assertMatches(regex, msg, failMsg=None):
+def assertMatches(regex, msg, fail_msg=None):
     if re.compile(regex).match(msg) is None:
-        if failMsg:
-            raise AssertionError(failMsg)
+        if fail_msg:
+            raise AssertionError(fail_msg)
             raise AssertionError('Expected match for %s but got %s' %
                                  (regex, msg))
     """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
+    def __init__(self, from_ip, debug=False):
+        self.from_ip = from_ip
         self.debug = debug
         """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 = EximDebugSMTP(from_host=self.from_ip, debug=self.debug)
         self.smtp.helo()        # TODO optional support for ESMTP?
     def close(self):
         _assertResponse(ACCEPTED, code, resp)
         return self
-    def assertRcptToRejected(self, rcpt, expectedMessage=None):
+    def assertRcptToRejected(self, rcpt, expect_resp=None):
         """Issues an RCPT TO for rcpt and asserts that it worked"""
         code, resp = self.smtp.rcpt(rcpt)
         _assertResponse(MAILBOX_UNAVAILABLE, code, resp)
-        if expectedMessage:
-            assertMatches(expectedMessage, resp,
+        if expect_resp:
+            assertMatches(expect_resp, resp,
                           "Response message did not match expectation")
         return self
         return self
-    def assertSpamRejected(self, expectedMessage=None):
-        self.assertDataRejected('gtube.txt', expectedMessage)
+    def assertSpamRejected(self, expect_resp=None):
+        self.assertDataRejected('gtube.txt', expect_resp)
     def assertSpamAccepted(self):
-    def assertVirusRejected(self, expectedMessage=None):
-        self.assertDataRejected('eicar.txt', expectedMessage)
+    def assertVirusRejected(self, expect_resp=None):
+        self.assertDataRejected('eicar.txt', expect_resp)
     def assertVirusAccepted(self):
-    def assertDataRejected(self, dataFile, expectedMessage=None):
-        data = self._getData(dataFile)
+    def assertDataRejected(self, filename, expect_resp=None):
+        data = self._getData(filename)
         code, resp =
         assert MAILBOX_UNAVAILABLE == code, resp
-        if expectedMessage:
-            assertMatches(expectedMessage, resp)
+        if expect_resp:
+            assertMatches(expect_resp, resp)
     def recursiveExpn(self, addr):
         def expn(a):
         return result
-    def _getData(self, fileName):
-        dataFile = os.path.join(
-            os.path.abspath(os.path.dirname(__file__)), fileName)
-        with open(dataFile, 'r') as f:
+    def _getData(self, filename):
+        infile = os.path.join(
+            os.path.abspath(os.path.dirname(__file__)), filename)
+        with open(infile, 'r') as f:
     def data(self, data):
         return self
-def _assertResponse(expectcode, code, resp):
-    assert expectcode == code, (
+def _assertResponse(expect_code, code, resp):
+    assert expect_code == code, (
         "expected %s but got %s (response: %r)" %
-        (expectcode, code, resp))
+        (expect_code, code, resp))
-def findFreePorts(howMany=1):
+def findFreePorts(how_many=1):
     """Return a list of n free port numbers on localhost"""
     results = []
     sockets = []
-    for x in range(howMany):
+    for x in range(how_many):
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.bind(('localhost', 0))
         addr, port = s.getsockname()
 class EximDebugSMTP(SMTP):
     """SMTP client which is backed by a fake Exim SMTP session."""
-    def __init__(self, fromHost, debug, *args, **kwargs):
+    def __init__(self, from_host, debug, *args, **kwargs):
         kwargs['host'] = 'localhost'
-        self.fromHost = fromHost
+        self.from_host = from_host
         # the super constructor calls _get_socket, so call it last
         SMTP.__init__(self, *args, **kwargs)
         # 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', '',
-                 '-c', eximCmd]
+        exim_cmd = '/usr/sbin/exim4 -bhc %s 2>exim-debug.log' % self.from_host
+        nc_cmd = ['nc', '-l', '-p', str(port), '-s', '',
+                  '-c', exim_cmd]
         if self.debuglevel > 0:
             print("Spawning exim on port %s with incoming address %s" %
-                  (port, self.fromHost))
-        ncProcess = Popen(ncCmd, stdout=PIPE)
+                  (port, self.from_host))
+        child = Popen(nc_cmd, stdout=PIPE)
          # TODO maybe just fork nc?
-        threading.Thread(target=ncProcess.communicate).start()
+        threading.Thread(target=child.communicate).start()
         time.sleep(2)           # give exim a moment to sort itself out
         # now connect and discard the first few lines (the header about

File src/eximunit/

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