From: Bob Halley Date: Mon, 15 Jun 2020 23:52:46 +0000 (-0700) Subject: print out more if file comparison fails X-Git-Tag: v2.0.0rc1~103 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=853c2bacb1ff7e7b81d4948809ca810008d44839;p=thirdparty%2Fdnspython.git print out more if file comparison fails --- diff --git a/tests/test_zone.py b/tests/test_zone.py index 3f77f4af..4f6b58c3 100644 --- a/tests/test_zone.py +++ b/tests/test_zone.py @@ -17,8 +17,10 @@ # 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'))