mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-09 23:10:24 +01:00
Merge pull request #3170 from pared/3105
utils: resolve_output: normpath before extracting basename
This commit is contained in:
@@ -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))
|
||||
if not out:
|
||||
return name
|
||||
if os.path.isdir(out):
|
||||
|
||||
@@ -4,7 +4,7 @@ import os
|
||||
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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user