mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
get-url: fix NPE when src non local and dst not absolute
This commit is contained in:
+2
-1
@@ -26,9 +26,10 @@ class OutputLOCAL(OutputBase):
|
||||
# so we should expect both posix and windows style paths.
|
||||
# PathInfo accepts both, i.e. / works everywhere, \ only on win.
|
||||
#
|
||||
# FIXME: if we have Windows path containig / or posix one with \
|
||||
# FIXME: if we have Windows path containing / or posix one with \
|
||||
# then we have #2059 bug and can't really handle that.
|
||||
p = self.REMOTE.path_cls(path)
|
||||
|
||||
if not p.is_absolute():
|
||||
p = self.stage.wdir / p
|
||||
|
||||
|
||||
+2
-1
@@ -12,7 +12,8 @@ def get_url(url, out=None):
|
||||
|
||||
if os.path.exists(url):
|
||||
url = os.path.abspath(url)
|
||||
out = os.path.abspath(out)
|
||||
|
||||
out = os.path.abspath(out)
|
||||
|
||||
dep, = dependency.loads_from(None, [url])
|
||||
out, = output.loads_from(None, [out], use_cache=False)
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import boto3
|
||||
import filecmp
|
||||
|
||||
import pytest
|
||||
|
||||
from moto import mock_s3
|
||||
|
||||
from dvc.remote import RemoteS3
|
||||
from dvc.repo import Repo
|
||||
from dvc.utils import makedirs
|
||||
|
||||
from tests.func.test_data_cloud import get_aws_url
|
||||
|
||||
|
||||
def test_get_file(repo_dir):
|
||||
src = repo_dir.FOO
|
||||
@@ -32,3 +38,27 @@ def test_get_url_to_dir(dname, repo_dir):
|
||||
|
||||
assert os.path.isdir(dname)
|
||||
assert filecmp.cmp(repo_dir.DATA, dst, shallow=False)
|
||||
|
||||
|
||||
@mock_s3
|
||||
@pytest.mark.parametrize("dst", [".", "./from"])
|
||||
def test_get_url_from_non_local_path_to_dir_and_file(repo_dir, dst):
|
||||
file_name = "from"
|
||||
file_content = "data"
|
||||
base_info = RemoteS3.path_cls(get_aws_url())
|
||||
from_info = base_info / file_name
|
||||
|
||||
s3 = boto3.client("s3")
|
||||
s3.create_bucket(Bucket=from_info.bucket)
|
||||
s3.put_object(
|
||||
Bucket=from_info.bucket, Key=from_info.path, Body=file_content
|
||||
)
|
||||
|
||||
Repo.get_url(from_info.url, dst)
|
||||
|
||||
result_path = os.path.join(dst, file_name) if os.path.isdir(dst) else dst
|
||||
|
||||
assert os.path.exists(result_path)
|
||||
assert os.path.isfile(result_path)
|
||||
with open(result_path, "r") as fd:
|
||||
assert fd.read() == file_content
|
||||
|
||||
Reference in New Issue
Block a user