11from __future__ import unicode_literals
22
33import os
4+ import boto3
45import filecmp
56
67import pytest
78
9+ from moto import mock_s3
10+
11+ from dvc .remote import RemoteS3
812from dvc .repo import Repo
913from dvc .utils import makedirs
1014
15+ from tests .func .test_data_cloud import get_aws_url
16+
1117
1218def 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