]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
print out more if file comparison fails
authorBob Halley <halley@dnspython.org>
Mon, 15 Jun 2020 23:52:46 +0000 (16:52 -0700)
committerBob Halley <halley@dnspython.org>
Mon, 15 Jun 2020 23:52:53 +0000 (16:52 -0700)
tests/test_zone.py

index 3f77f4afa47a4865fe770b248f98402cd9e06423..4f6b58c3bfbee6930db0d5d2c29bbf5001152efc 100644 (file)
 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 from io import BytesIO, StringIO
+import difflib
 import filecmp
 import os
+import sys
 import unittest
 from typing import cast
 
@@ -167,6 +169,12 @@ def make_xfr(zone):
     add_rdataset(msg, soa_name, soa)
     return [msg]
 
+def print_differences(a_name, b_name):
+    with open(a_name, 'r') as a:
+        with open(b_name, 'r') as b:
+            differ = difflib.Differ()
+            sys.stdout.writelines(differ.compare(a.readlines(), b.readlines()))
+
 class ZoneTestCase(unittest.TestCase):
 
     def testFromFile1(self): # type: () -> None
@@ -176,6 +184,9 @@ class ZoneTestCase(unittest.TestCase):
             z.to_file(here('example1.out'), nl=b'\x0a')
             ok = filecmp.cmp(here('example1.out'),
                              here('example1.good'))
+            if not ok:
+                print_differences(here('example1.out'),
+                                  here('example1.good'))
         finally:
             if not _keep_output:
                 os.unlink(here('example1.out'))