[Reproducible-commits] [debbindiff] 03/03: Handle when only the encoding is different when comparing text files
Jérémy Bobbio
lunar at moszumanska.debian.org
Sat Aug 1 22:42:23 UTC 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository debbindiff.
commit 9bf4cc03ec0cc7203a659224ff6810e5090a4b9d
Author: Jérémy Bobbio <lunar at debian.org>
Date: Sat Aug 1 22:39:00 2015 +0000
Handle when only the encoding is different when comparing text files
Closes: #794347
---
debbindiff/comparators/text.py | 2 ++
tests/comparators/test_text.py | 9 +++++++++
2 files changed, 11 insertions(+)
diff --git a/debbindiff/comparators/text.py b/debbindiff/comparators/text.py
index 00ad6c9..14f0f00 100644
--- a/debbindiff/comparators/text.py
+++ b/debbindiff/comparators/text.py
@@ -47,6 +47,8 @@ class TextFile(File):
codecs.open(other.path, 'r', encoding=other_encoding) as other_content:
difference = Difference.from_file(my_content, other_content, self.name, other.name, source)
if my_encoding != other_encoding:
+ if difference is None:
+ difference = Difference(None, self.path, other.path, source)
difference.add_details([Difference.from_unicode(my_encoding, other_encoding, None, None, source='encoding')])
return difference
except (LookupError, UnicodeDecodeError):
diff --git a/tests/comparators/test_text.py b/tests/comparators/test_text.py
index df9ab94..bd349e5 100644
--- a/tests/comparators/test_text.py
+++ b/tests/comparators/test_text.py
@@ -66,3 +66,12 @@ def test_difference_between_iso88591_and_unicode(iso8859, unicode1):
difference = iso8859.compare(unicode1)
expected_diff = codecs.open(os.path.join(os.path.dirname(__file__), '../data/text_iso8859_expected_diff'), encoding='utf-8').read()
assert difference.unified_diff == expected_diff
+
+def test_difference_between_iso88591_and_unicode_only(iso8859, tmpdir):
+ utf8_path = str(tmpdir.join('utf8'))
+ with open(utf8_path, 'w') as f:
+ f.write(codecs.open(os.path.join(os.path.dirname(__file__), '../data/text_iso8859'), encoding='iso8859-1').read().encode('utf-8'))
+ utf8 = specialize(FilesystemFile(utf8_path))
+ difference = iso8859.compare(utf8)
+ assert difference.unified_diff is None
+ assert difference.details[0].source1 == 'encoding'
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/debbindiff.git
More information about the Reproducible-commits
mailing list