[meld/pathlabel] test: Add test coverage for `find_shared_parent_path()`
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/pathlabel] test: Add test coverage for `find_shared_parent_path()`
- Date: Wed, 13 Jan 2021 21:06:38 +0000 (UTC)
commit 8d89a898af1fef5777fda53e6a746890bad5c405
Author: Kai Willadsen <kai willadsen gmail com>
Date: Wed Jan 13 07:23:59 2021 +1000
test: Add test coverage for `find_shared_parent_path()`
test/test_iohelpers.py | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
---
diff --git a/test/test_iohelpers.py b/test/test_iohelpers.py
new file mode 100644
index 00000000..db540e79
--- /dev/null
+++ b/test/test_iohelpers.py
@@ -0,0 +1,36 @@
+
+import pytest
+from gi.repository import Gio
+
+from meld.iohelpers import find_shared_parent_path
+
+
+@pytest.mark.parametrize(
+ 'paths, expected_parent',
+ [
+ # No paths, None return
+ ([], None),
+ # One path always returns its own parent
+ (['/foo/a/b/c'], '/foo/a/b'),
+ # Two paths
+ (['/foo/a', '/foo/b'], '/foo'),
+ # Three paths
+ (['/foo/a', '/foo/b', '/foo/c'], '/foo'),
+ # First path is deeper
+ (['/foo/a/asd/asd', '/foo/b'], '/foo'),
+ # Second path is deeper
+ (['/foo/a/', '/foo/b/asd/asd'], '/foo'),
+ # Common parent is the root
+ (['/foo/a/', '/bar/b/'], '/'),
+ ],
+)
+def test_find_shared_parent_path(paths, expected_parent):
+ files = [Gio.File.new_for_path(p) for p in paths]
+ print([f.get_path() for f in files])
+ parent = find_shared_parent_path(files)
+
+ if parent is None:
+ assert expected_parent is None
+ else:
+ print(f'Parent: {parent.get_path()}; expected {expected_parent}')
+ assert parent.equal(Gio.File.new_for_path(expected_parent))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]