]> granicus.if.org Git - pdns/commitdiff
better assertEqual for dnspython
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Thu, 11 Apr 2019 15:40:20 +0000 (17:40 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 8 Oct 2019 08:39:45 +0000 (10:39 +0200)
before:
AssertionError: <DNS message, ID 38993> != <DNS message, ID 38993>

after:
AssertionError: <DNS message, ID 46818> != <DNS message, ID 46818>:
--- first
+++ second
@@ -1,10 +1,10 @@
 id 46818
-opcode 6
-rcode NOTAUTH
-flags AD CD
+opcode QUERY
+rcode NOERROR
+flags RD
 ;QUESTION
 xpf.tests.powerdns.com. IN A
 ;ANSWER
 ;AUTHORITY
 ;ADDITIONAL
-. 0 IN TYPE65422 \# 14 04117f0000017f000001f8bc14dc
+xpf.tests.powerdns.com. 60 IN TYPE65422 \# 14 04117f0000017f00000100000000

regression-tests.dnsdist/dnsdisttests.py

index f5e0b92ee674c1ea8986b7c7658556b3714abd76..e5aeae8f7660718559ce733b096cf6df9e5bcb53 100644 (file)
@@ -440,6 +440,8 @@ class DNSDistTest(unittest.TestCase):
     def setUp(self):
         # This function is called before every tests
 
+        self.addTypeEqualityFunc(dns.message.Message, self.assertEqualDNSMessage)
+
         # Clear the responses counters
         for key in self._responsesCounter:
             self._responsesCounter[key] = 0
@@ -577,3 +579,26 @@ class DNSDistTest(unittest.TestCase):
 
     def checkResponseNoEDNS(self, expected, received):
         self.checkMessageNoEDNS(expected, received)
+
+    def assertEqualDNSMessage(self, first, second, msg=None):
+        if not first == second:
+            a = str(first).split('\n')
+            b = str(second).split('\n')
+
+            import difflib
+
+            diff = '\n'.join(
+                difflib.unified_diff(
+                    a,
+                    b,
+                    fromfile='first',
+                    tofile='second',
+                    n=max(len(a), len(b)),
+                    lineterm=""
+                )
+            )
+
+            standardMsg = "%s != %s:\n%s" % (repr(first), repr(second), diff)
+            msg = self._formatMessage(msg, standardMsg)
+
+            raise self.failureException(msg)