Skip to content

Commit

Permalink
Fix empty paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Himura2la committed Jul 19, 2019
1 parent 3887c1f commit 3ac135d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/os_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
3 changes: 3 additions & 0 deletions test/test_os_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 3ac135d

Please sign in to comment.