Skip to content

Commit fafe096

Browse files
jan-janssengoogle-labs-jules[bot]pyiron-runner
authored
feat: Increase test coverage for pysqa/base/remote.py (#448)
* feat: Increase test coverage for pysqa/base/remote.py - Add tests for get_job_from_remote - Add tests for authentication methods in _open_ssh_connection - Increase coverage of pysqa/base/remote.py from 72% to 80% * Format black * Update _version.py * Update queue.yaml * Update queue.yaml * Update queue.yaml * Update test_remote_auth.py --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: pyiron-runner <[email protected]>
1 parent 0a7b083 commit fafe096

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

tests/config/remote_rebex/queue.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ ssh_continous_connection: False
1111
ssh_port: 22
1212
python_executable: python3
1313
queues:
14-
remote: {cores_max: 100, cores_min: 10, run_time_max: 259200}
14+
remote: {cores_max: 100, cores_min: 10, run_time_max: 259200}

tests/test_remote.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,23 @@ def test_get_transport(self):
176176
remote = QueueAdapter(directory=os.path.join(path, "config/remote_rebex"))
177177
self.assertIsNotNone(get_transport(remote._adapter._open_ssh_connection()))
178178
with self.assertRaises(ValueError):
179-
get_transport(ssh=FakeSSH())
179+
get_transport(ssh=FakeSSH())
180+
181+
def test_get_job_from_remote(self):
182+
path = os.path.dirname(os.path.abspath(__file__))
183+
remote = QueueAdapter(directory=os.path.join(path, "config/remote_rebex"))
184+
remote._adapter._ssh_remote_path = path
185+
remote._adapter._ssh_local_path = path
186+
remote._adapter._ssh_delete_file_on_remote = True
187+
with unittest.mock.patch(
188+
"pysqa.base.remote.RemoteQueueAdapter._execute_remote_command"
189+
) as mock_execute:
190+
mock_execute.return_value = '{"dirs": [], "files": ["test.txt"]}'
191+
with unittest.mock.patch(
192+
"pysqa.base.remote.RemoteQueueAdapter._transfer_files"
193+
) as mock_transfer:
194+
remote._adapter.get_job_from_remote(
195+
working_directory=os.path.join(path, "config/empty")
196+
)
197+
self.assertEqual(mock_transfer.call_count, 1)
198+
self.assertEqual(mock_execute.call_count, 2)

tests/test_remote_auth.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
import unittest
3+
from pysqa import QueueAdapter
4+
5+
try:
6+
import paramiko
7+
from tqdm import tqdm
8+
from pysqa.base.remote import get_transport
9+
10+
skip_remote_test = False
11+
except ImportError:
12+
skip_remote_test = True
13+
14+
15+
@unittest.skipIf(
16+
skip_remote_test,
17+
"Either paramiko or tqdm are not installed, so the remote queue adapter tests are skipped.",
18+
)
19+
class TestRemoteQueueAdapterAuth(unittest.TestCase):
20+
def test_password_auth(self):
21+
path = os.path.dirname(os.path.abspath(__file__))
22+
remote = QueueAdapter(directory=os.path.join(path, "config/remote_rebex"))
23+
remote._adapter._ssh_ask_for_password = False
24+
remote._adapter._ssh_key = None
25+
self.assertIsNotNone(remote._adapter._open_ssh_connection())
26+
27+
def test_key_auth(self):
28+
path = os.path.dirname(os.path.abspath(__file__))
29+
remote = QueueAdapter(directory=os.path.join(path, "config/remote_rebex"))
30+
remote._adapter._ssh_password = None
31+
with self.assertRaises(ValueError):
32+
remote._adapter._open_ssh_connection()
33+
34+
def test_two_factor_auth(self):
35+
path = os.path.dirname(os.path.abspath(__file__))
36+
remote = QueueAdapter(directory=os.path.join(path, "config/remote_rebex"))
37+
remote._adapter._ssh_two_factor_authentication = True
38+
with self.assertRaises(paramiko.ssh_exception.AuthenticationException):
39+
remote._adapter._open_ssh_connection()

0 commit comments

Comments
 (0)