Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dvc/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def env2bool(var, undefined=False):
def resolve_output(inp, out):
from urllib.parse import urlparse

name = os.path.basename(urlparse(inp).path)
name = os.path.basename(os.path.normpath(urlparse(inp).path))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ€” hard to know that it was originally wrong (before normpath). Wondering if there's a better way to handle this cases without thinking too much about correctness.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, @pared πŸ‘

if not out:
return name
if os.path.isdir(out):
Expand Down
27 changes: 26 additions & 1 deletion tests/unit/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from dvc.path_info import PathInfo
from dvc.utils import file_md5
from dvc.utils import file_md5, resolve_output
from dvc.utils import fix_env
from dvc.utils import relpath
from dvc.utils import to_chunks
Expand Down Expand Up @@ -104,3 +104,28 @@ def test_relpath():
path_info = PathInfo(path)

assert relpath(path) == relpath(path_info)


@pytest.mark.parametrize(
"inp,out,is_dir,expected",
[
["target", None, False, "target"],
["target", "dir", True, os.path.join("dir", "target")],
["target", "file_target", False, "file_target"],
[
"target",
os.path.join("dir", "subdir"),
True,
os.path.join("dir", "subdir", "target"),
],
["dir/", None, False, "dir"],
["dir", None, False, "dir"],
["dir", "other_dir", False, "other_dir"],
["dir", "other_dir", True, os.path.join("other_dir", "dir")],
],
)
def test_resolve_output(inp, out, is_dir, expected, mocker):
with mocker.patch("os.path.isdir", return_value=is_dir):
result = resolve_output(inp, out)

assert result == expected