Skip to content

Commit 78dd489

Browse files
committed
test: merge _should_test_aws and _get_aws_url inside S3 test helper
1 parent 8041d70 commit 78dd489

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

tests/func/test_data_cloud.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,19 @@
3131
from tests.utils import spy
3232

3333
from tests.remotes import (
34-
_should_test_aws,
3534
_should_test_gcp,
3635
_should_test_hdfs,
3736
_should_test_oss,
3837
_should_test_ssh,
3938
Azure,
4039
GDrive,
40+
S3,
4141
TEST_CONFIG,
4242
TEST_SECTION,
4343
TEST_GCP_CREDS_FILE,
4444
TEST_GDRIVE_CLIENT_ID,
4545
TEST_GDRIVE_CLIENT_SECRET,
4646
TEST_REMOTE,
47-
get_aws_url,
4847
get_gcp_url,
4948
get_hdfs_url,
5049
get_local_url,
@@ -196,10 +195,10 @@ def test(self):
196195

197196
class TestRemoteS3(TestDataCloudBase):
198197
def _should_test(self):
199-
return _should_test_aws()
198+
return S3.should_test()
200199

201200
def _get_url(self):
202-
return get_aws_url()
201+
return S3.get_url()
203202

204203
def _get_cloud_class(self):
205204
return RemoteS3
@@ -470,10 +469,10 @@ def _test(self):
470469

471470
class TestRemoteS3CLI(TestDataCloudCLIBase):
472471
def _should_test(self):
473-
return _should_test_aws()
472+
return S3.should_test()
474473

475474
def _test(self):
476-
url = get_aws_url()
475+
url = S3.get_url()
477476

478477
self.main(["remote", "add", TEST_REMOTE, url])
479478

tests/func/test_repro.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
from dvc.utils.stage import load_stage_file
3535
from tests.basic_env import TestDvc
3636
from tests.remotes import (
37-
_should_test_aws,
3837
_should_test_gcp,
3938
_should_test_hdfs,
4039
_should_test_ssh,
4140
get_ssh_url,
41+
S3,
4242
TEST_AWS_REPO_BUCKET,
4343
TEST_GCP_REPO_BUCKET,
4444
)
@@ -954,7 +954,7 @@ def test(self, mock_prompt):
954954
@pytest.mark.skipif(os.name == "nt", reason="temporarily disabled on windows")
955955
class TestReproExternalS3(TestReproExternalBase):
956956
def should_test(self):
957-
return _should_test_aws()
957+
return S3.should_test()
958958

959959
@property
960960
def scheme(self):

tests/func/test_s3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from moto import mock_s3
66

77
from dvc.remote.s3 import RemoteS3
8-
from tests.remotes import get_aws_url
8+
from tests.remotes import S3
99

1010

1111
# from https://github.com/spulec/moto/blob/v1.3.5/tests/test_s3/test_s3.py#L40
@@ -30,7 +30,7 @@ def wrapped(*args, **kwargs):
3030

3131

3232
def _get_src_dst():
33-
base_info = RemoteS3.path_cls(get_aws_url())
33+
base_info = RemoteS3.path_cls(S3.get_url())
3434
return base_info / "from", base_info / "to"
3535

3636

tests/remotes.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@
4343
TEST_GDRIVE_CLIENT_SECRET = "2fy_HyzSwkxkGzEken7hThXb"
4444

4545

46-
def _should_test_aws():
47-
do_test = env2bool("DVC_TEST_AWS", undefined=None)
48-
if do_test is not None:
49-
return do_test
50-
51-
if os.getenv("AWS_ACCESS_KEY_ID") and os.getenv("AWS_SECRET_ACCESS_KEY"):
52-
return True
53-
54-
return False
55-
56-
5746
def _should_test_gcp():
5847
do_test = env2bool("DVC_TEST_GCP", undefined=None)
5948
if do_test is not None:
@@ -168,14 +157,6 @@ def get_hdfs_url():
168157
)
169158

170159

171-
def get_aws_storagepath():
172-
return TEST_AWS_REPO_BUCKET + "/" + str(uuid.uuid4())
173-
174-
175-
def get_aws_url():
176-
return "s3://" + get_aws_storagepath()
177-
178-
179160
def get_gcp_storagepath():
180161
return TEST_GCP_REPO_BUCKET + "/" + str(uuid.uuid4())
181162

@@ -199,13 +180,30 @@ class Local:
199180

200181

201182
class S3:
202-
should_test = staticmethod(_should_test_aws)
203-
get_url = staticmethod(get_aws_url)
183+
@staticmethod
184+
def should_test():
185+
do_test = env2bool("DVC_TEST_AWS", undefined=None)
186+
if do_test is not None:
187+
return do_test
188+
189+
if os.getenv("AWS_ACCESS_KEY_ID") and os.getenv(
190+
"AWS_SECRET_ACCESS_KEY"
191+
):
192+
return True
193+
194+
return False
195+
196+
@staticmethod
197+
def get_storagepath():
198+
return TEST_AWS_REPO_BUCKET + "/" + str(uuid.uuid4())
199+
200+
@staticmethod
201+
def get_url():
202+
return "s3://" + S3.get_storagepath()
204203

205204

206-
class S3Mocked:
205+
class S3Mocked(S3):
207206
should_test = staticmethod(lambda: True)
208-
get_url = staticmethod(get_aws_url)
209207

210208
@classmethod
211209
@contextmanager

0 commit comments

Comments
 (0)