From a27910d71d655d6f803763f4f070c9bac8f6434c Mon Sep 17 00:00:00 2001 From: Saugat Pachhai Date: Tue, 14 Jan 2020 00:17:45 +0545 Subject: [PATCH] test: merge local related function in Local helper class --- tests/func/test_data_cloud.py | 16 ++++++++-------- tests/func/test_remote.py | 4 ++-- tests/remotes.py | 25 ++++++++++++------------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/tests/func/test_data_cloud.py b/tests/func/test_data_cloud.py index 7b2e349c82..cfe0febfc9 100644 --- a/tests/func/test_data_cloud.py +++ b/tests/func/test_data_cloud.py @@ -35,6 +35,7 @@ GCP, GDrive, HDFS, + Local, S3, SSHMocked, OSS, @@ -44,7 +45,6 @@ TEST_GDRIVE_CLIENT_ID, TEST_GDRIVE_CLIENT_SECRET, TEST_REMOTE, - get_local_url, ) @@ -278,10 +278,10 @@ def _get_cloud_class(self): class TestRemoteLOCAL(TestDataCloudBase): def _should_test(self): - return True + return Local.should_test() def _get_url(self): - self.dname = get_local_url() + self.dname = Local.get_url() return self.dname def _get_cloud_class(self): @@ -420,7 +420,7 @@ def test(self): class TestRemoteLOCALCLI(TestDataCloudCLIBase): def _test(self): - url = get_local_url() + url = Local.get_url() self.main(["remote", "add", TEST_REMOTE, url]) @@ -545,7 +545,7 @@ def main(self, args): self.assertEqual(ret, 0) def _test(self): - url = get_local_url() + url = Local.get_url() self.main(["remote", "add", "-d", TEST_REMOTE, url]) stage = self.dvc.run(outs=["bar"], cmd="echo bar > bar") @@ -577,11 +577,11 @@ def main(self, args): self.assertEqual(ret, 0) def _get_url(self): - self.dname = get_local_url() + self.dname = Local.get_url() return self.dname def _should_test(self): - return True + return Local.should_test() def _get_cloud_class(self): return RemoteLOCAL @@ -659,7 +659,7 @@ def test(self): with patch.object( RemoteLOCAL, "get_file_checksum", test_get_file_checksum ): - url = get_local_url() + url = Local.get_url() ret = main(["remote", "add", "-d", TEST_REMOTE, url]) self.assertEqual(ret, 0) ret = main(["config", "cache.type", "hardlink"]) diff --git a/tests/func/test_remote.py b/tests/func/test_remote.py index 777666bd96..99e8e248c5 100644 --- a/tests/func/test_remote.py +++ b/tests/func/test_remote.py @@ -14,7 +14,7 @@ from dvc.remote.base import RemoteBASE from dvc.compat import fspath from tests.basic_env import TestDvc -from tests.remotes import get_local_storagepath +from tests.remotes import Local class TestRemote(TestDvc): @@ -159,7 +159,7 @@ class TestRemoteShouldHandleUppercaseRemoteName(TestDvc): upper_case_remote_name = "UPPERCASEREMOTE" def test(self): - remote_url = get_local_storagepath() + remote_url = Local.get_storagepath() ret = main(["remote", "add", self.upper_case_remote_name, remote_url]) self.assertEqual(ret, 0) diff --git a/tests/remotes.py b/tests/remotes.py index 4623c7606d..cf80fd1605 100644 --- a/tests/remotes.py +++ b/tests/remotes.py @@ -43,17 +43,16 @@ TEST_GDRIVE_CLIENT_SECRET = "2fy_HyzSwkxkGzEken7hThXb" -def get_local_storagepath(): - return TestDvc.mkdtemp() - - -def get_local_url(): - return get_local_storagepath() - - class Local: should_test = lambda: True # noqa: E731 - get_url = get_local_url + + @staticmethod + def get_storagepath(): + return TestDvc.mkdtemp() + + @staticmethod + def get_url(): + return Local.get_storagepath() class S3: @@ -215,7 +214,7 @@ def should_test(): @staticmethod def get_url(): return "ssh://{}@127.0.0.1:22{}".format( - getpass.getuser(), get_local_storagepath() + getpass.getuser(), Local.get_storagepath() ) @@ -224,9 +223,9 @@ class SSHMocked: @staticmethod def get_url(user, port): - path = get_local_storagepath() + path = Local.get_storagepath() if os.name == "nt": - # NOTE: On Windows get_local_storagepath() will return an + # NOTE: On Windows Local.get_storagepath() will return an # ntpath that looks something like `C:\some\path`, which is not # compatible with SFTP paths [1], so we need to convert it to # a proper posixpath. @@ -273,5 +272,5 @@ def should_test(): @staticmethod def get_url(): return "hdfs://{}@127.0.0.1{}".format( - getpass.getuser(), get_local_storagepath() + getpass.getuser(), Local.get_storagepath() )