[meld] Add test coverage for format_home_relative_path()



commit b352f10335cf841617e79e05dc5f5dfd8cc1b7e6
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Aug 12 09:28:48 2022 +1000

    Add test coverage for format_home_relative_path()

 test/test_iohelpers.py | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/test/test_iohelpers.py b/test/test_iohelpers.py
index da97aa0a..4e2569a5 100644
--- a/test/test_iohelpers.py
+++ b/test/test_iohelpers.py
@@ -1,8 +1,13 @@
+from unittest import mock
 
 import pytest
 from gi.repository import Gio
 
-from meld.iohelpers import find_shared_parent_path, format_parent_relative_path
+from meld.iohelpers import (
+    find_shared_parent_path,
+    format_home_relative_path,
+    format_parent_relative_path,
+)
 
 
 @pytest.mark.parametrize(
@@ -43,6 +48,23 @@ def test_find_shared_parent_path(paths, expected_parent):
             assert parent.equal(Gio.File.new_for_path(expected_parent))
 
 
+@pytest.mark.parametrize(
+    "path, expected_format",
+    [
+        ("/home/hey/foo", "~/foo"),
+        ("/home/hmph/foo", "/home/hmph/foo"),
+    ]
+)
+def test_format_home_relative_path(path, expected_format):
+
+    with mock.patch(
+        "meld.iohelpers.GLib.get_home_dir",
+        return_value="/home/hey/",
+    ):
+        gfile = Gio.File.new_for_path(path)
+        assert format_home_relative_path(gfile) == expected_format
+
+
 @pytest.mark.parametrize(
     'parent, child, expected_label',
     [


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