Skip to content

Commit ce8e019

Browse files
authored
Merge pull request #2705 from shcheklein/fix-2702
get-url: fix NPE when src non local and dst not absolute
2 parents 7ecbdab + 3660d9e commit ce8e019

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

dvc/output/local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _parse_path(self, remote, path):
2626
# so we should expect both posix and windows style paths.
2727
# PathInfo accepts both, i.e. / works everywhere, \ only on win.
2828
#
29-
# FIXME: if we have Windows path containig / or posix one with \
29+
# FIXME: if we have Windows path containing / or posix one with \
3030
# then we have #2059 bug and can't really handle that.
3131
p = self.REMOTE.path_cls(path)
3232
if not p.is_absolute():

dvc/repo/get_url.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def get_url(url, out=None):
1212

1313
if os.path.exists(url):
1414
url = os.path.abspath(url)
15-
out = os.path.abspath(out)
15+
16+
out = os.path.abspath(out)
1617

1718
dep, = dependency.loads_from(None, [url])
1819
out, = output.loads_from(None, [out], use_cache=False)

tests/func/test_get_url.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
from __future__ import unicode_literals
22

33
import os
4+
import boto3
45
import filecmp
56

67
import pytest
78

9+
from moto import mock_s3
10+
11+
from dvc.remote import RemoteS3
812
from dvc.repo import Repo
913
from dvc.utils import makedirs
1014

15+
from tests.func.test_data_cloud import get_aws_url
16+
1117

1218
def test_get_file(repo_dir):
1319
src = repo_dir.FOO
@@ -32,3 +38,27 @@ def test_get_url_to_dir(dname, repo_dir):
3238

3339
assert os.path.isdir(dname)
3440
assert filecmp.cmp(repo_dir.DATA, dst, shallow=False)
41+
42+
43+
@mock_s3
44+
@pytest.mark.parametrize("dst", [".", "./from"])
45+
def test_get_url_from_non_local_path_to_dir_and_file(repo_dir, dst):
46+
file_name = "from"
47+
file_content = "data"
48+
base_info = RemoteS3.path_cls(get_aws_url())
49+
from_info = base_info / file_name
50+
51+
s3 = boto3.client("s3")
52+
s3.create_bucket(Bucket=from_info.bucket)
53+
s3.put_object(
54+
Bucket=from_info.bucket, Key=from_info.path, Body=file_content
55+
)
56+
57+
Repo.get_url(from_info.url, dst)
58+
59+
result_path = os.path.join(dst, file_name) if os.path.isdir(dst) else dst
60+
61+
assert os.path.exists(result_path)
62+
assert os.path.isfile(result_path)
63+
with open(result_path, "r") as fd:
64+
assert fd.read() == file_content

0 commit comments

Comments
 (0)