[Git][reproducible-builds/diffoscope][master] 3 commits: Move to assert_diff in test_text.py

Chris Lamb (@lamby) gitlab at salsa.debian.org
Fri Jan 17 12:42:47 UTC 2025



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
e20a5055 by Chris Lamb at 2025-01-17T12:35:44+00:00
Move to assert_diff in test_text.py

- - - - -
9fa3171f by Chris Lamb at 2025-01-17T12:40:50+00:00
Don't mangle newlines when opening test fixtures; we want them untouched.

- - - - -
2236701a by Chris Lamb at 2025-01-17T12:41:27+00:00
Correctly identify changes to only the line-endings of files; don't mark them as "Ordering differences only".

- - - - -


6 changed files:

- diffoscope/difference.py
- tests/comparators/test_text.py
- + tests/data/text_endings1
- + tests/data/text_endings2
- + tests/data/text_endings_expected_diff
- tests/utils/data.py


Changes:

=====================================
diffoscope/difference.py
=====================================
@@ -403,7 +403,7 @@ class Difference:
         self._visuals.extend(visuals)
         self._size_cache = None
 
-    def has_ordering_differences_only(self):
+    def check_for_ordering_differences(self):
         """
         Check if difference is only in line ordering.
         """
@@ -420,15 +420,11 @@ class Difference:
 
         # Faster check: does number of lines match?
         if len(added_lines) != len(removed_lines):
-            return False
+            return
 
         if added_lines == removed_lines:
-            return True
-
-        return sorted(added_lines) == sorted(removed_lines)
-
-    def check_for_ordering_differences(self):
-        if self.has_ordering_differences_only():
+            self.add_comment("Line-ending differences only")
+        elif sorted(added_lines) == sorted(removed_lines):
             self.add_comment("Ordering differences only")
 
 


=====================================
tests/comparators/test_text.py
=====================================
@@ -23,7 +23,7 @@ from diffoscope.comparators.binary import FilesystemFile
 from diffoscope.comparators.text import TextFile
 from diffoscope.comparators.utils.specialize import specialize
 
-from ..utils.data import data, load_fixture, get_data
+from ..utils.data import data, load_fixture, assert_diff
 from ..utils.nonexisting import assert_non_existing
 
 
@@ -39,8 +39,7 @@ def test_no_differences(ascii1):
 def test_difference_in_ascii(ascii1, ascii2):
     difference = ascii1.compare(ascii2)
     assert difference is not None
-    expected_diff = get_data("text_ascii_expected_diff")
-    assert difference.unified_diff == expected_diff
+    assert_diff(difference, "text_ascii_expected_diff")
     assert not difference.comments
     assert len(difference.details) == 0
 
@@ -90,12 +89,20 @@ def test_compare_non_existing(monkeypatch, ascii1):
 
 text_order1 = load_fixture("text_order1")
 text_order2 = load_fixture("text_order2")
+text_endings1 = load_fixture("text_endings1")
+text_endings2 = load_fixture("text_endings2")
 
 
 def test_ordering_differences(text_order1, text_order2):
     difference = text_order1.compare(text_order2)
     assert difference.comments == ["Ordering differences only"]
-    assert difference.unified_diff == get_data("text_order_expected_diff")
+    assert_diff(difference, "text_order_expected_diff")
+
+
+def test_ending_differences(text_endings1, text_endings2):
+    difference = text_endings1.compare(text_endings2)
+    assert difference.comments == ["Line-ending differences only"]
+    assert_diff(difference, "text_endings_expected_diff")
 
 
 def test_text_fallback(tmp_path):


=====================================
tests/data/text_endings1
=====================================
@@ -0,0 +1,3 @@
+artifactId=logback-core
+groupId=ch.qos.logback
+version=1.2.13


=====================================
tests/data/text_endings2
=====================================
@@ -0,0 +1,3 @@
+artifactId=logback-core
+groupId=ch.qos.logback
+version=1.2.13


=====================================
tests/data/text_endings_expected_diff
=====================================
@@ -0,0 +1,7 @@
+@@ -1,3 +1,3 @@
+-artifactId=logback-core
+-groupId=ch.qos.logback
+-version=1.2.13
++artifactId=logback-core
++groupId=ch.qos.logback
++version=1.2.13


=====================================
tests/utils/data.py
=====================================
@@ -52,7 +52,7 @@ def data(filename):
 
 
 def get_data(filename):
-    with open(data(filename), encoding="utf-8") as f:
+    with open(data(filename), newline="", encoding="utf-8") as f:
         return f.read()
 
 



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/2dd46bb74ed038c9241d697b4ebd8a935dc12bed...2236701a8c5e27513bfeec14e70ac1df5a78b86c

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/2dd46bb74ed038c9241d697b4ebd8a935dc12bed...2236701a8c5e27513bfeec14e70ac1df5a78b86c
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20250117/735a8b31/attachment.htm>


More information about the rb-commits mailing list