From 02eebd48eb9afa4579bf7e0be423a4208f25afc0 Mon Sep 17 00:00:00 2001 From: khamutov Date: Mon, 6 May 2019 21:47:58 +0300 Subject: [PATCH] test: ssh: add windows support for ssh config --- dvc/remote/ssh/__init__.py | 6 +++++- tests/unit/remote/ssh/test_ssh.py | 16 ++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/dvc/remote/ssh/__init__.py b/dvc/remote/ssh/__init__.py index 557d5cff7..0ef060efc 100644 --- a/dvc/remote/ssh/__init__.py +++ b/dvc/remote/ssh/__init__.py @@ -72,9 +72,13 @@ class RemoteSSH(RemoteBase): "port": self.port, } + @staticmethod + def ssh_config_filename(): + return os.path.expanduser(os.path.join("~", ".ssh", "config")) + @staticmethod def _load_user_ssh_config(hostname): - user_config_file = os.path.expanduser("~/.ssh/config") + user_config_file = RemoteSSH.ssh_config_filename() user_ssh_config = dict() if hostname and os.path.exists(user_config_file): with open(user_config_file) as f: diff --git a/tests/unit/remote/ssh/test_ssh.py b/tests/unit/remote/ssh/test_ssh.py index 6193e4422..462c490cd 100644 --- a/tests/unit/remote/ssh/test_ssh.py +++ b/tests/unit/remote/ssh/test_ssh.py @@ -96,8 +96,8 @@ def test_ssh_host_override_from_config( ): remote = RemoteSSH(None, config) - mock_exists.assert_called_with(os.path.expanduser("~/.ssh/config")) - mock_file.assert_called_with(os.path.expanduser("~/.ssh/config")) + mock_exists.assert_called_with(RemoteSSH.ssh_config_filename()) + mock_file.assert_called_with(RemoteSSH.ssh_config_filename()) assert remote.host == expected_host @@ -124,8 +124,8 @@ def test_ssh_host_override_from_config( def test_ssh_user(mock_file, mock_exists, config, expected_user): remote = RemoteSSH(None, config) - mock_exists.assert_called_with(os.path.expanduser("~/.ssh/config")) - mock_file.assert_called_with(os.path.expanduser("~/.ssh/config")) + mock_exists.assert_called_with(RemoteSSH.ssh_config_filename()) + mock_file.assert_called_with(RemoteSSH.ssh_config_filename()) assert remote.user == expected_user @@ -149,8 +149,8 @@ def test_ssh_user(mock_file, mock_exists, config, expected_user): def test_ssh_port(mock_file, mock_exists, config, expected_port): remote = RemoteSSH(None, config) - mock_exists.assert_called_with(os.path.expanduser("~/.ssh/config")) - mock_file.assert_called_with(os.path.expanduser("~/.ssh/config")) + mock_exists.assert_called_with(RemoteSSH.ssh_config_filename()) + mock_file.assert_called_with(RemoteSSH.ssh_config_filename()) assert remote.port == expected_port @@ -184,6 +184,6 @@ def test_ssh_port(mock_file, mock_exists, config, expected_port): def test_ssh_keyfile(mock_file, mock_exists, config, expected_keyfile): remote = RemoteSSH(None, config) - mock_exists.assert_called_with(os.path.expanduser("~/.ssh/config")) - mock_file.assert_called_with(os.path.expanduser("~/.ssh/config")) + mock_exists.assert_called_with(RemoteSSH.ssh_config_filename()) + mock_file.assert_called_with(RemoteSSH.ssh_config_filename()) assert remote.keyfile == expected_keyfile