Skip to content

Commit

Permalink
test: refactor: use helper remotes in TestCases
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Jan 14, 2020
1 parent 88fb097 commit 37b9d32
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 79 deletions.
97 changes: 21 additions & 76 deletions tests/func/test_data_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,27 @@ class TestDataCloudBase(TestDvc):
def _get_cloud_class(self):
return None

def _should_test(self):
@staticmethod
def should_test():
return False

def _get_url(self):
return ""
@staticmethod
def get_url():
return NotImplementedError

def _get_keyfile(self):
return None

def _ensure_should_run(self):
if not self._should_test():
if not self.should_test():
raise SkipTest(
"Test {} is disabled".format(self.__class__.__name__)
)

def _setup_cloud(self):
self._ensure_should_run()

repo = self._get_url()
repo = self.get_url()
keyfile = self._get_keyfile()

config = copy.deepcopy(TEST_CONFIG)
Expand Down Expand Up @@ -188,25 +190,16 @@ def test(self):
self._test_cloud()


class TestRemoteS3(TestDataCloudBase):
def _should_test(self):
return S3.should_test()

def _get_url(self):
return S3.get_url()

class TestRemoteS3(S3, TestDataCloudBase):
def _get_cloud_class(self):
return RemoteS3


class TestRemoteGDrive(TestDataCloudBase):
def _should_test(self):
return GDrive.should_test()

class TestRemoteGDrive(GDrive, TestDataCloudBase):
def _setup_cloud(self):
self._ensure_should_run()

repo = self._get_url()
repo = self.get_url()

config = copy.deepcopy(TEST_CONFIG)
config[TEST_SECTION][Config.SECTION_REMOTE_URL] = repo
Expand All @@ -221,21 +214,15 @@ def _setup_cloud(self):

self.assertIsInstance(self.cloud.get_remote(), self._get_cloud_class())

def _get_url(self):
return GDrive.get_url()

def _get_cloud_class(self):
return RemoteGDrive


class TestRemoteGS(TestDataCloudBase):
def _should_test(self):
return GCP.should_test()

class TestRemoteGS(GCP, TestDataCloudBase):
def _setup_cloud(self):
self._ensure_should_run()

repo = self._get_url()
repo = self.get_url()

config = copy.deepcopy(TEST_CONFIG)
config[TEST_SECTION][Config.SECTION_REMOTE_URL] = repo
Expand All @@ -247,53 +234,27 @@ def _setup_cloud(self):

self.assertIsInstance(self.cloud.get_remote(), self._get_cloud_class())

def _get_url(self):
return GCP.get_url()

def _get_cloud_class(self):
return RemoteGS


class TestRemoteAZURE(TestDataCloudBase):
def _should_test(self):
return Azure.should_test()

def _get_url(self):
return Azure.get_url()

class TestRemoteAZURE(Azure, TestDataCloudBase):
def _get_cloud_class(self):
return RemoteAZURE


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

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

class TestRemoteOSS(OSS, TestDataCloudBase):
def _get_cloud_class(self):
return RemoteOSS


class TestRemoteLOCAL(TestDataCloudBase):
def _should_test(self):
return Local.should_test()

def _get_url(self):
self.dname = Local.get_url()
return self.dname

class TestRemoteLOCAL(Local, TestDataCloudBase):
def _get_cloud_class(self):
return RemoteLOCAL

def test(self):
super().test()
self.assertTrue(os.path.isdir(self.dname))


@pytest.mark.usefixtures("ssh_server")
class TestRemoteSSHMocked(TestDataCloudBase):
class TestRemoteSSHMocked(SSHMocked, TestDataCloudBase):
@pytest.fixture(autouse=True)
def setup_method_fixture(self, request, ssh_server):
self.ssh_server = ssh_server
Expand All @@ -302,7 +263,7 @@ def setup_method_fixture(self, request, ssh_server):
def _setup_cloud(self):
self._ensure_should_run()

repo = self._get_url()
repo = self.get_url()
keyfile = self._get_keyfile()

config = copy.deepcopy(TEST_CONFIG)
Expand All @@ -314,27 +275,18 @@ def _setup_cloud(self):

self.assertIsInstance(self.cloud.get_remote(), self._get_cloud_class())

def _get_url(self):
def get_url(self):
user = self.ssh_server.test_creds["username"]
return SSHMocked.get_url(user, self.ssh_server.port)
return super().get_url(user, self.ssh_server.port)

def _get_keyfile(self):
return self.ssh_server.test_creds["key_filename"]

def _should_test(self):
return SSHMocked.should_test()

def _get_cloud_class(self):
return RemoteSSH


class TestRemoteHDFS(TestDataCloudBase):
def _should_test(self):
return HDFS.should_test()

def _get_url(self):
return HDFS.get_url()

class TestRemoteHDFS(HDFS, TestDataCloudBase):
def _get_cloud_class(self):
return RemoteHDFS

Expand Down Expand Up @@ -571,18 +523,11 @@ def test(self):
self._test()


class TestRecursiveSyncOperations(TestDataCloudBase):
class TestRecursiveSyncOperations(Local, TestDataCloudBase):
def main(self, args):
ret = main(args)
self.assertEqual(ret, 0)

def _get_url(self):
self.dname = Local.get_url()
return self.dname

def _should_test(self):
return Local.should_test()

def _get_cloud_class(self):
return RemoteLOCAL

Expand Down
8 changes: 5 additions & 3 deletions tests/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
)
TEST_GDRIVE_CLIENT_SECRET = "2fy_HyzSwkxkGzEken7hThXb"

always_test = staticmethod(lambda: True)


class Local:
should_test = lambda: True # noqa: E731
should_test = always_test

@staticmethod
def get_storagepath():
Expand Down Expand Up @@ -79,7 +81,7 @@ def get_url():


class S3Mocked(S3):
should_test = lambda: True # noqa: E731
should_test = always_test

@classmethod
@contextmanager
Expand Down Expand Up @@ -219,7 +221,7 @@ def get_url():


class SSHMocked:
should_test = lambda: True # noqa: E731
should_test = always_test

@staticmethod
def get_url(user, port):
Expand Down

0 comments on commit 37b9d32

Please sign in to comment.