test: refactor hdfs related functions in HDFS test helpers

This commit is contained in:
Saugat Pachhai
2020-01-13 16:30:15 +05:45
parent 028d30e22d
commit d55427dbd9
3 changed files with 37 additions and 39 deletions
+5 -6
View File
@@ -32,9 +32,9 @@ from tests.utils import spy
from tests.remotes import (
_should_test_gcp,
_should_test_hdfs,
Azure,
GDrive,
HDFS,
S3,
SSHMocked,
OSS,
@@ -45,7 +45,6 @@ from tests.remotes import (
TEST_GDRIVE_CLIENT_SECRET,
TEST_REMOTE,
get_gcp_url,
get_hdfs_url,
get_local_url,
)
@@ -332,10 +331,10 @@ class TestRemoteSSHMocked(TestDataCloudBase):
class TestRemoteHDFS(TestDataCloudBase):
def _should_test(self):
return _should_test_hdfs()
return HDFS.should_test()
def _get_url(self):
return get_hdfs_url()
return HDFS.get_url()
def _get_cloud_class(self):
return RemoteHDFS
@@ -431,10 +430,10 @@ class TestRemoteLOCALCLI(TestDataCloudCLIBase):
class TestRemoteHDFSCLI(TestDataCloudCLIBase):
def _should_test(self):
return _should_test_hdfs()
return HDFS.should_test()
def _test(self):
url = get_hdfs_url()
url = HDFS.get_url()
self.main(["remote", "add", TEST_REMOTE, url])
+2 -2
View File
@@ -36,7 +36,7 @@ from dvc.utils.stage import load_stage_file
from tests.basic_env import TestDvc
from tests.remotes import (
_should_test_gcp,
_should_test_hdfs,
HDFS,
S3,
SSH,
SSHMocked,
@@ -996,7 +996,7 @@ class TestReproExternalGS(TestReproExternalBase):
class TestReproExternalHDFS(TestReproExternalBase):
def should_test(self):
return _should_test_hdfs()
return HDFS.should_test()
@property
def scheme(self):
+30 -31
View File
@@ -66,29 +66,6 @@ def _should_test_gcp():
return True
def _should_test_hdfs():
if platform.system() != "Linux":
return False
try:
check_output(
["hadoop", "version"], shell=True, executable=os.getenv("SHELL")
)
except (CalledProcessError, IOError):
return False
p = Popen(
"hadoop fs -ls hdfs://127.0.0.1/",
shell=True,
executable=os.getenv("SHELL"),
)
p.communicate()
if p.returncode != 0:
return False
return True
def get_local_storagepath():
return TestDvc.mkdtemp()
@@ -97,12 +74,6 @@ def get_local_url():
return get_local_storagepath()
def get_hdfs_url():
return "hdfs://{}@127.0.0.1{}".format(
getpass.getuser(), get_local_storagepath()
)
def get_gcp_storagepath():
return TEST_GCP_REPO_BUCKET + "/" + str(uuid.uuid4())
@@ -277,5 +248,33 @@ class SSHMocked:
class HDFS:
should_test = _should_test_hdfs
get_url = get_hdfs_url
@staticmethod
def should_test():
if platform.system() != "Linux":
return False
try:
check_output(
["hadoop", "version"],
shell=True,
executable=os.getenv("SHELL"),
)
except (CalledProcessError, IOError):
return False
p = Popen(
"hadoop fs -ls hdfs://127.0.0.1/",
shell=True,
executable=os.getenv("SHELL"),
)
p.communicate()
if p.returncode != 0:
return False
return True
@staticmethod
def get_url():
return "hdfs://{}@127.0.0.1{}".format(
getpass.getuser(), get_local_storagepath()
)