From 3ac135d8bffe9501d34cf53440dc72fb645f7d09 Mon Sep 17 00:00:00 2001 From: Himura Kazuto Date: Fri, 19 Jul 2019 19:16:35 +0300 Subject: [PATCH] Fix empty paths --- src/os_tools.py | 5 ++++- test/test_os_tools.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/os_tools.py b/src/os_tools.py index ea2201d..2bd7bc7 100644 --- a/src/os_tools.py +++ b/src/os_tools.py @@ -29,12 +29,15 @@ def fest_file(self, fest_file): self._fest_file = str(Path(fest_file).resolve()) def make_abs(self, path, anchor=None): + if not path: + return path path, anchor = self._prepare_paths(path, anchor) return str(Path(os.path.join(str(anchor), str(path))).resolve()) def make_rel(self, path, anchor=None): + if not path: + return path path, anchor = self._prepare_paths(path, anchor) - if self._can_make_rel(path, anchor): # Path().relative_to() have differ semantic with os.path.relpath() return str(os.path.relpath(str(path.resolve()), str(anchor))) diff --git a/test/test_os_tools.py b/test/test_os_tools.py index 44c6c2e..6d03970 100644 --- a/test/test_os_tools.py +++ b/test/test_os_tools.py @@ -53,6 +53,9 @@ def test_relative_path(self): self.assertEqual(t.make_rel(self.fest1_path, t.fest_file), "..\\test1.fest") # TODO test workdir relative path (need stable workdir path) + # Test empty path + self.assertEqual(t.make_rel(""), "") + # TODO test abs paths (need stable enviroment) def tearDown(self):