From a35e03258a371b6ff83497186a9ba3266bc45cf4 Mon Sep 17 00:00:00 2001 From: Patrik Teivonen Date: Mon, 29 Aug 2022 13:57:31 +0300 Subject: Add unit test: bldinstallercommon.calculate_relpath Change-Id: Ic2d340d97da28608cbdaa95a01ab9200c8d04096 Reviewed-by: Iikka Eklund --- packaging-tools/tests/test_bldinstallercommon.py | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'packaging-tools/tests') diff --git a/packaging-tools/tests/test_bldinstallercommon.py b/packaging-tools/tests/test_bldinstallercommon.py index 1f4a787d5..eac100625 100644 --- a/packaging-tools/tests/test_bldinstallercommon.py +++ b/packaging-tools/tests/test_bldinstallercommon.py @@ -38,6 +38,7 @@ from ddt import data, ddt # type: ignore from bld_utils import is_windows from bldinstallercommon import ( + calculate_relpath, locate_executable, locate_path, locate_paths, @@ -204,6 +205,37 @@ class TestCommon(unittest.TestCase): locate_executable(tmp_base_dir, ["test_file2"]), tmp_base_dir + "/test_file2") + @data( + ("/home/qt/bin/foo/bar", "/home/qt/lib", "../../../lib"), + ("/home/qt/bin/foo/", "/home/qt/lib", "/home/qt/lib"), + ("/home/qt/bin", "/home/qt/lib", "../lib"), + ("/home/qt/bin", "lib", "../../../../lib"), + ("/home/qt/bin", "/lib", "../../../lib"), + ("/home/qt", "./lib", "../../.././lib"), + ("bin", "/home/qt/lib", "/home/qt/lib"), + ("/home/qt/", "/home/qt", "/home/qt"), + ("/home/qt", "/home/qt/", "/home/qt"), + ("/home/qt", "/home/qt/", "/home/qt"), + ("/", "/home/qt", "home/qt"), + ("/home/qt", "", "../../../"), + ("", "/home/qt", "/home/qt"), + ) + def test_calculate_relpath(self, test_data) -> None: + path1, path2, expected = test_data + result = calculate_relpath(path1, path2) + self.assertEqual(result, expected) + + @data( + ("/home/qt", "/home/qt"), + ("/", "/"), + ("lib", "lib"), + ("", ""), + ) + def test_calculate_relpath_invalid(self, test_data) -> None: + path1, path2 = test_data + with self.assertRaises(TypeError): + calculate_relpath(path1, path2) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3