Commits

Greg Ward committed 832870e

Factor out _assertResponse() to improve failure reporting.

  • Participants
  • Parent commits 8125555

Comments (0)

Files changed (1)

File src/eximunit/smtp.py

     def mailFrom(self, addr):
         """Issues a MAIL FROM command with addr, and asserts that it worked"""
         code, resp = self.smtp.mail(addr)
-        assert ACCEPTED == code, resp
+        _assertResponse(ACCEPTED, code, resp)
         return self
 
     def rcptTo(self, rcpt):
         """Issues an RCPT TO for rcpt and asserts that it worked"""
         code, resp = self.smtp.rcpt(rcpt)
-        assert ACCEPTED == code, resp
+        _assertResponse(ACCEPTED, code, resp)
         return self        
 
     def assertRcptToRejected(self, rcpt, expectedMessage = None):
         """Issues an RCPT TO for rcpt and asserts that it worked"""
         code, resp = self.smtp.rcpt(rcpt)
-        assert MAILBOX_UNAVAILABLE == code, resp
+        _assertResponse(MAILBOX_UNAVAILABLE, code, resp)
         if expectedMessage:
             assertMatches(expectedMessage, resp, "Response message did not match expectation")
         return self     
         assert ACCEPTED == code, resp
         return self
 
+def _assertResponse(expectcode, code, resp):
+    assert expectcode == code, (
+        "expected %s but got %s (response: %r)" %
+        (expectcode, code, resp))
 
 def findFreePorts(howMany=1):
     """Return a list of n free port numbers on localhost"""