diff --git a/pyproject.toml b/pyproject.toml index 916346b..dc8c976 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "databudgie" -version = "2.7.4" +version = "2.7.5" packages = [ { include = "databudgie", from = "src" }, ] diff --git a/src/databudgie/utils.py b/src/databudgie/utils.py index 04038a0..3521657 100644 --- a/src/databudgie/utils.py +++ b/src/databudgie/utils.py @@ -82,5 +82,13 @@ def join_paths(*components: Optional[str]) -> str: return real_components[0] first_component, *rest_components = real_components - normalized_components = [S3Location(c).key if is_s3_path(c) else c for c in rest_components] + normalized_components = [] + for c in rest_components: + if is_s3_path(c): + normalized_c = S3Location(c).key + else: + normalized_c = c.strip("/") + + normalized_components.append(normalized_c) + return os.path.join(first_component, *normalized_components) diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..4611e70 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,23 @@ +from databudgie.utils import join_paths + + +class Test_join_paths: + def test_one_component(self): + path = join_paths("/first") + assert path == "/first" + + def test_first_component_absolute_path(self): + path = join_paths("/first", "/2nd") + assert path == "/first/2nd" + + def test_non_first_component_absolute_path(self): + path = join_paths("first", "/2nd/") + assert path == "first/2nd" + + def test_bad_first_component(self): + path = join_paths(None, "/first") + assert path == "/first" + + def test_no_components(self): + path = join_paths(None) + assert path == ""