Skip to content

Commit

Permalink
Merge pull request #93 from schireson/dc/weird-absolute-path
Browse files Browse the repository at this point in the history
  • Loading branch information
DanCardin authored Apr 21, 2023
2 parents 8ed8cdd + 6d97bce commit 57f43b6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "databudgie"
version = "2.7.4"
version = "2.7.5"
packages = [
{ include = "databudgie", from = "src" },
]
Expand Down
10 changes: 9 additions & 1 deletion src/databudgie/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
23 changes: 23 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -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 == ""

0 comments on commit 57f43b6

Please sign in to comment.