Skip to content

Commit 5b85db3

Browse files
authored
Merge pull request #3104 from efiop/ssh_dir_out
tests: remove redundant native ssh tests
2 parents 0110358 + bc619f1 commit 5b85db3

File tree

10 files changed

+45
-109
lines changed

10 files changed

+45
-109
lines changed

dvc/remote/ssh/connection.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,12 @@ def _remove_file(self, path):
156156
def _remove_dir(self, path):
157157
for root, dirs, files in self.walk(path, topdown=False):
158158
for fname in files:
159-
path = posixpath.join(root, fname)
160159
with suppress(FileNotFoundError):
161-
self._remove_file(path)
160+
self._remove_file(posixpath.join(root, fname))
162161

163162
for dname in dirs:
164-
path = posixpath.join(root, dname)
165163
with suppress(FileNotFoundError):
166-
self.sftp.rmdir(dname)
164+
self.sftp.rmdir(posixpath.join(root, dname))
167165

168166
with suppress(FileNotFoundError):
169167
self.sftp.rmdir(path)

scripts/build-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PyInstaller==3.5
2+
psutil

scripts/build_posix.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ install_dependencies()
9595
pip install --upgrade pip
9696

9797
print_info "Installing requirements..."
98-
pip install .[all] psutil
99-
100-
print_info "Installing pyinstaller..."
101-
pip install pyinstaller
98+
pip install .[all]
99+
pip install -r scripts/build-requirements.txt
102100
}
103101

104102
build_dvc()

scripts/build_windows.cmd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ if %errorlevel% neq 0 (echo Error: Couldn't find Inno Setup compiler. && goto :e
2323
echo ====== Installing requirements... ======
2424
echo PKG = "exe" > dvc\utils\build.py
2525
call pip install .[all] || goto :error
26-
call pip install psutil || goto :error
26+
call pip install -r scripts\build-requirements.txt || goto :error
2727
call dvc pull || goto :error
28-
call pip install pyinstaller || goto :error
2928

3029
echo ====== Building dvc binary... ======
3130
call pyinstaller --additional-hooks-dir scripts\hooks dvc/__main__.py --name dvc --specpath build

scripts/hooks/hook-Crypto.py

Lines changed: 0 additions & 58 deletions
This file was deleted.

scripts/hooks/hook-aliyunsdkcore.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def run(self):
9999

100100
# Extra dependecies to run tests
101101
tests_requirements = [
102-
"PyInstaller==3.5",
103102
"wheel>=0.31.1",
104103
"pydot>=1.2.4",
105104
# Test requirements:

tests/func/test_data_cloud.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from tests.remotes import (
3434
_should_test_gcp,
3535
_should_test_hdfs,
36-
_should_test_ssh,
3736
Azure,
3837
GDrive,
3938
S3,
@@ -47,7 +46,6 @@
4746
get_gcp_url,
4847
get_hdfs_url,
4948
get_local_url,
50-
get_ssh_url,
5149
get_ssh_url_mocked,
5250
)
5351

@@ -296,17 +294,6 @@ def test(self):
296294
self.assertTrue(os.path.isdir(self.dname))
297295

298296

299-
class TestRemoteSSH(TestDataCloudBase):
300-
def _should_test(self):
301-
return _should_test_ssh()
302-
303-
def _get_url(self):
304-
return get_ssh_url()
305-
306-
def _get_cloud_class(self):
307-
return RemoteSSH
308-
309-
310297
@pytest.mark.usefixtures("ssh_server")
311298
class TestRemoteSSHMocked(TestDataCloudBase):
312299
@pytest.fixture(autouse=True)
@@ -442,18 +429,6 @@ def _test(self):
442429
self._test_cloud(TEST_REMOTE)
443430

444431

445-
class TestRemoteSSHCLI(TestDataCloudCLIBase):
446-
def _should_test(self):
447-
return _should_test_ssh()
448-
449-
def _test(self):
450-
url = get_ssh_url()
451-
452-
self.main(["remote", "add", TEST_REMOTE, url])
453-
454-
self._test_cloud(TEST_REMOTE)
455-
456-
457432
class TestRemoteHDFSCLI(TestDataCloudCLIBase):
458433
def _should_test(self):
459434
return _should_test_hdfs()

tests/func/test_repro.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
_should_test_gcp,
3939
_should_test_hdfs,
4040
_should_test_ssh,
41-
get_ssh_url,
41+
get_ssh_url_mocked,
4242
S3,
4343
TEST_AWS_REPO_BUCKET,
4444
TEST_GCP_REPO_BUCKET,
@@ -1611,30 +1611,46 @@ def test(self):
16111611
assert evaluation[2].relpath == "E.dvc"
16121612

16131613

1614-
def test_ssh_dir_out(tmp_dir, dvc):
1615-
if not _should_test_ssh():
1616-
pytest.skip()
1617-
1614+
@pytest.mark.skipif(
1615+
os.name == "nt",
1616+
reason="external output scenario is not supported on Windows",
1617+
)
1618+
def test_ssh_dir_out(tmp_dir, dvc, ssh_server):
16181619
tmp_dir.gen({"foo": "foo content"})
16191620

16201621
# Set up remote and cache
1621-
remote_url = get_ssh_url()
1622+
user = ssh_server.test_creds["username"]
1623+
port = ssh_server.port
1624+
keyfile = ssh_server.test_creds["key_filename"]
1625+
1626+
remote_url = get_ssh_url_mocked(user, port)
16221627
assert main(["remote", "add", "upstream", remote_url]) == 0
1628+
assert main(["remote", "modify", "upstream", "keyfile", keyfile]) == 0
16231629

1624-
cache_url = get_ssh_url()
1630+
cache_url = get_ssh_url_mocked(user, port)
16251631
assert main(["remote", "add", "sshcache", cache_url]) == 0
16261632
assert main(["config", "cache.ssh", "sshcache"]) == 0
1633+
assert main(["remote", "modify", "sshcache", "keyfile", keyfile]) == 0
16271634

16281635
# Recreating to reread configs
16291636
repo = DvcRepo(dvc.root_dir)
16301637

1638+
# To avoid "WARNING: UNPROTECTED PRIVATE KEY FILE" from ssh
1639+
os.chmod(keyfile, 0o600)
1640+
1641+
(tmp_dir / "script.py").write_text(
1642+
"import sys, pathlib\n"
1643+
"path = pathlib.Path(sys.argv[1])\n"
1644+
"dir_out = path / 'dir-out'\n"
1645+
"dir_out.mkdir()\n"
1646+
"(dir_out / '1.txt').write_text('1')\n"
1647+
"(dir_out / '2.txt').write_text('2')\n"
1648+
)
1649+
16311650
url_info = URLInfo(remote_url)
1632-
mkdir_cmd = "mkdir dir-out;cd dir-out;echo 1 > 1.txt; echo 2 > 2.txt"
16331651
repo.run(
1634-
cmd="ssh {netloc} 'cd {path};{cmd}'".format(
1635-
netloc=url_info.netloc, path=url_info.path, cmd=mkdir_cmd
1636-
),
1637-
outs=[(url_info / "dir-out").url],
1652+
cmd="python {} {}".format(tmp_dir / "script.py", url_info.path),
1653+
outs=["remote://upstream/dir-out"],
16381654
deps=["foo"], # add a fake dep to not consider this a callback
16391655
)
16401656

tests/unit/remote/ssh/test_connection.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ def test_makedirs(tmp_path, ssh):
3535
assert os.path.isdir(path)
3636

3737

38+
def test_remove_dir(tmp_path, ssh):
39+
dpath = tmp_path / "dir"
40+
dpath.mkdir()
41+
(dpath / "file").write_text("file")
42+
(dpath / "subdir").mkdir()
43+
(dpath / "subdir" / "subfile").write_text("subfile")
44+
ssh.remove(dpath.absolute().as_posix())
45+
assert not dpath.exists()
46+
47+
3848
def test_walk(tmp_path, ssh):
3949
root_path = tmp_path
4050
dir_path = root_path / "dir"

0 commit comments

Comments
 (0)