Skip to content

Commit

Permalink
Merge pull request #3071 from skshetry/refactor-remote-oss
Browse files Browse the repository at this point in the history
test: merge _should_test_oss and _get_oss_url inside OSS test helper
  • Loading branch information
efiop authored Jan 6, 2020
2 parents 40449c4 + 96c87d5 commit 0f08b7e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
11 changes: 5 additions & 6 deletions tests/func/test_data_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
_should_test_aws,
_should_test_gcp,
_should_test_hdfs,
_should_test_oss,
_should_test_ssh,
Azure,
GDrive,
OSS,
TEST_CONFIG,
TEST_SECTION,
TEST_GCP_CREDS_FILE,
Expand All @@ -48,7 +48,6 @@
get_gcp_url,
get_hdfs_url,
get_local_url,
get_oss_url,
get_ssh_url,
get_ssh_url_mocked,
)
Expand Down Expand Up @@ -273,10 +272,10 @@ def _get_cloud_class(self):

class TestRemoteOSS(TestDataCloudBase):
def _should_test(self):
return _should_test_oss()
return OSS.should_test()

def _get_url(self):
return get_oss_url()
return OSS.get_url()

def _get_cloud_class(self):
return RemoteOSS
Expand Down Expand Up @@ -545,10 +544,10 @@ def _test(self):

class TestRemoteOSSCLI(TestDataCloudCLIBase):
def _should_test(self):
return _should_test_oss()
return OSS.should_test()

def _test(self):
url = get_oss_url()
url = OSS.get_url()

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

Expand Down
41 changes: 19 additions & 22 deletions tests/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,6 @@ def _should_test_gcp():
return True


def _should_test_oss():
do_test = env2bool("DVC_TEST_OSS", undefined=None)
if do_test is not None:
return do_test

return (
os.getenv("OSS_ENDPOINT")
and os.getenv("OSS_ACCESS_KEY_ID")
and os.getenv("OSS_ACCESS_KEY_SECRET")
)


def _should_test_ssh():
do_test = env2bool("DVC_TEST_SSH", undefined=None)
if do_test is not None:
Expand Down Expand Up @@ -184,14 +172,6 @@ def get_gcp_url():
return "gs://" + get_gcp_storagepath()


def get_oss_storagepath():
return "{}/{}".format(TEST_OSS_REPO_BUCKET, (uuid.uuid4()))


def get_oss_url():
return "oss://{}".format(get_oss_storagepath())


# NOTE: staticmethod is only needed in Python 2
class Local:
should_test = staticmethod(lambda: True)
Expand Down Expand Up @@ -270,8 +250,25 @@ def get_url():


class OSS:
should_test = staticmethod(_should_test_oss)
get_url = staticmethod(get_oss_url)
@staticmethod
def should_test():
do_test = env2bool("DVC_TEST_OSS", undefined=None)
if do_test is not None:
return do_test

return (
os.getenv("OSS_ENDPOINT")
and os.getenv("OSS_ACCESS_KEY_ID")
and os.getenv("OSS_ACCESS_KEY_SECRET")
)

@staticmethod
def get_storagepath():
return "{}/{}".format(TEST_OSS_REPO_BUCKET, (uuid.uuid4()))

@staticmethod
def get_url():
return "oss://{}".format(OSS.get_storagepath())


class SSH:
Expand Down

0 comments on commit 0f08b7e

Please sign in to comment.