From 78c9fc198734ea83e35847705a702bfefacdee65 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Sun, 23 Jun 2013 20:36:05 -0700 Subject: [PATCH] Fixing header comparison. --- django_mailbox/tests/__init__.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/django_mailbox/tests/__init__.py b/django_mailbox/tests/__init__.py index 42a69b5..0bba4da 100644 --- a/django_mailbox/tests/__init__.py +++ b/django_mailbox/tests/__init__.py @@ -37,12 +37,28 @@ class EmailMessageTestCase(TestCase): f.read() ) + def _headers_identical(self, left, right): + """ Check if headers are identical. + + This is particularly tricky because Python 2.6, Python 2.7 and Python 3 + each handle this slightly differently. This should mash away all + of the differences, though. + + """ + left = left.replace('\n\t', ' ').replace('\n ', ' ') + right = right.replace('\n\t', ' ').replace('\n ', ' ') + if right != left: + print(repr(left)) + print(repr(right)) + return False + return True + def compare_email_objects(self, left, right): # Compare headers for key, value in left.items(): if not right[key]: raise AssertionError("Extra header '%s'" % key) - if right[key].replace('\n\t', ' ') != value.replace('\n\t', ' '): + if not self._headers_identical(right[key], value): raise AssertionError( "Header '%s' unequal:\n%s\n%s" % ( key, @@ -53,7 +69,7 @@ class EmailMessageTestCase(TestCase): for key, value in right.items(): if not left[key]: raise AssertionError("Extra header '%s'" % key) - if left[key].replace('\n\t', ' ') != value.replace('\n\t', ' '): + if not self._headers_identical(left[key], value): raise AssertionError( "Header '%s' unequal:\n%s\n%s" % ( key,