diff options
author | Patrik Teivonen <patrik.teivonen@qt.io> | 2022-08-29 13:57:31 +0300 |
---|---|---|
committer | Patrik Teivonen <patrik.teivonen@qt.io> | 2022-09-07 08:24:49 +0000 |
commit | a35e03258a371b6ff83497186a9ba3266bc45cf4 (patch) | |
tree | 5fad72ca09363d808a63bd3cf8a9ac0a56b7c0c8 /packaging-tools/tests | |
parent | 1dca0360d131d6910fe40d8707fdbbfcbe779ef5 (diff) |
Add unit test: bldinstallercommon.calculate_relpathv6.3.2-packaging
Change-Id: Ic2d340d97da28608cbdaa95a01ab9200c8d04096
Reviewed-by: Iikka Eklund <iikka.eklund@qt.io>
Diffstat (limited to 'packaging-tools/tests')
-rw-r--r-- | packaging-tools/tests/test_bldinstallercommon.py | 32 |
1 files changed, 32 insertions, 0 deletions
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() |