diff --git a/pydu/path.py b/pydu/path.py index ceecc5c..272f14d 100644 --- a/pydu/path.py +++ b/pydu/path.py @@ -34,3 +34,8 @@ def is_super_path(path1, path2): parent_path2 = os.path.dirname(parent_path2) return False + + +def normjoin(path, *paths): + """Join one or more path components intelligently and normalize it.""" + return os.path.normpath(os.path.join(path, *paths)) diff --git a/tests/test_path.py b/tests/test_path.py index 0cde505..d2e894c 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -1,7 +1,7 @@ import os import pytest from pydu.platform import WINDOWS -from pydu.path import cd, is_super_path +from pydu.path import cd, is_super_path, normjoin def test_cd(tmpdir): @@ -27,3 +27,9 @@ class TestIsSupoerPath: assert is_super_path('c:/aa/bb', 'c:/aa\\bb/cc') assert is_super_path('c:/aa\\bb', 'c:\\aa/bb/cc') assert is_super_path('c:/', 'c:\\') + + +def test_normjoin(): + assert normjoin('/a', 'b') == '/a/b' + assert normjoin('/a', '/b') == '/b' + assert normjoin('/a', '../b') == '/b'