diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -210,6 +210,22 @@ # For Windows support wifexited = getattr(os, "WIFEXITED", lambda x: False) +_unified_diff = difflib.unified_diff +if PYTHON3: + import functools + _unified_diff = functools.partial(difflib.diff_bytes, difflib.unified_diff) + +try: + from mercurial import mdiff + # mdiff.new_diff may not be present if the mercurial version installed + # is not up to date hence this try block will throw exception AttributeError + # and if Mercurial itself is not installed in the system then it will throw + # an ImportError + _diff = mdiff.new_diff +except (ImportError, AttributeError): + print("Falling back to unified_diff") + _diff = _unified_diff + # Whether to use IPv6 def checksocketfamily(name, port=20058): """return true if we can listen on localhost using family=name @@ -598,15 +614,10 @@ except OSError: pass -_unified_diff = difflib.unified_diff -if PYTHON3: - import functools - _unified_diff = functools.partial(difflib.diff_bytes, difflib.unified_diff) - def getdiff(expected, output, ref, err): servefail = False lines = [] - for line in _unified_diff(expected, output, ref, err): + for line in _diff(expected, output, ref, err): if line.startswith(b'+++') or line.startswith(b'---'): line = line.replace(b'\\', b'/') if line.endswith(b' \n'):