[meld/pathlabel] test: Add test coverage for PathLabel's path formatting



commit afe42e883add750c0d068b8609616b6ed022e483
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Thu Jan 14 07:05:49 2021 +1000

    test: Add test coverage for PathLabel's path formatting

 test/test_iohelpers.py | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)
---
diff --git a/test/test_iohelpers.py b/test/test_iohelpers.py
index db540e79..5171253e 100644
--- a/test/test_iohelpers.py
+++ b/test/test_iohelpers.py
@@ -2,7 +2,7 @@
 import pytest
 from gi.repository import Gio
 
-from meld.iohelpers import find_shared_parent_path
+from meld.iohelpers import find_shared_parent_path, format_parent_relative_path
 
 
 @pytest.mark.parametrize(
@@ -34,3 +34,47 @@ def test_find_shared_parent_path(paths, expected_parent):
     else:
         print(f'Parent: {parent.get_path()}; expected {expected_parent}')
         assert parent.equal(Gio.File.new_for_path(expected_parent))
+
+
+@pytest.mark.parametrize(
+    'parent, child, expected_label',
+    [
+        # Child is a direct child of parent
+        (
+            '/home/hey/',
+            '/home/hey/foo.txt',
+            '…/foo.txt',
+        ),
+        # Child is a 2-depth child of parent
+        (
+            '/home/hey/',
+            '/home/hey/project/foo.txt',
+            '…/project/foo.txt',
+        ),
+        # Child is a more-than-2-depth child of parent
+        (
+            '/home/hey/',
+            '/home/hey/project/hey/hey/foo.txt',
+            '…/project/…/foo.txt',
+        ),
+    ],
+)
+def test_format_parent_relative_path(
+    parent: str,
+    child: str,
+    expected_label: str,
+):
+    parent_gfile = Gio.File.new_for_path(parent)
+    child_gfile = Gio.File.new_for_path(child)
+
+    label = format_parent_relative_path(parent_gfile, child_gfile)
+
+    assert label == expected_label
+
+
+def test_format_parent_relative_path_no_parent():
+    parent_gfile = Gio.File.new_for_path('/')
+    child_gfile = Gio.File.new_for_path('/')
+
+    with pytest.raises(ValueError, match='has no parent'):
+        format_parent_relative_path(parent_gfile, child_gfile)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]