Skip to content

Commit ec76d77

Browse files
committed
Update unit tests for _run to mock submission
1 parent d199ed2 commit ec76d77

File tree

1 file changed

+17
-68
lines changed

1 file changed

+17
-68
lines changed

tests/unit/test_command.py

Lines changed: 17 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,27 @@
66

77
class RunTests(TestCase):
88

9-
@patch("os.path.abspath")
10-
@patch("nextflow.command.make_nextflow_command")
11-
@patch("subprocess.Popen")
9+
@patch("nextflow.command.submit_execution")
1210
@patch("time.sleep")
1311
@patch("nextflow.command.get_execution")
14-
def test_can_run_with_default_values(self, mock_ex, mock_sleep, mock_run, mock_nc, mock_abs):
12+
def test_can_run_with_default_values(self, mock_ex, mock_sleep, mock_submit):
1513
execution = Mock()
14+
submission = Mock()
15+
mock_submit.return_value = submission
1616
mock_ex.return_value = execution, 20
1717
executions = list(_run("main.nf"))
18-
mock_nc.assert_called_with(mock_abs.return_value, mock_abs.return_value, mock_abs.return_value, "main.nf", False, None, None, None, None, None, None, None, None, None, None)
19-
mock_abs.assert_called_once_with(".")
20-
mock_run.assert_called_with(
21-
mock_nc.return_value,
22-
universal_newlines=True, shell=True
23-
)
2418
mock_sleep.assert_called_with(1)
25-
mock_ex.assert_called_with(mock_abs.return_value, mock_abs.return_value, mock_nc.return_value, None, 0, None, None)
19+
mock_ex.assert_called_with(submission.output_path, submission.log_path, submission.nextflow_command, None, 0, None, None)
2620
self.assertEqual(executions, [execution])
2721

2822

29-
@patch("nextflow.command.make_nextflow_command")
30-
@patch("subprocess.Popen")
31-
@patch("nextflow.command.wait_for_log_creation")
23+
@patch("nextflow.command.submit_execution")
3224
@patch("time.sleep")
3325
@patch("nextflow.command.get_execution")
3426
@freeze_time("2025-01-01")
35-
def test_can_run_with_custom_values(self, mock_ex, mock_sleep, mock_wait, mock_run, mock_nc):
27+
def test_can_run_with_custom_values(self, mock_ex, mock_sleep, mock_submit):
28+
submission = Mock()
29+
mock_submit.return_value = submission
3630
mock_executions = [Mock(return_code=""), Mock(return_code="0")]
3731
mock_ex.side_effect = [[None, 0], [mock_executions[0], 40], [mock_executions[1], 20]]
3832
io = Mock()
@@ -41,76 +35,31 @@ def test_can_run_with_custom_values(self, mock_ex, mock_sleep, mock_wait, mock_r
4135
params={"param": "2"}, profiles=["docker"], timezone="UTC", report="report.html",
4236
timeline="time.html", dag="dag.html", trace="trace.html", sleep=4, io=io
4337
))
44-
mock_nc.assert_called_with("/exdir", "/out", "/log", "main.nf", "a_b", "21.10", ["conf1"], {"param": "2"}, ["docker"], "UTC", "report.html", "time.html", "dag.html", "trace.html", io)
45-
mock_run.assert_called_with(
46-
mock_nc.return_value,
47-
universal_newlines=True, shell=True
48-
)
49-
mock_wait.assert_called_with("/log", datetime(2025, 1, 1), io)
5038
mock_sleep.assert_called_with(4)
5139
self.assertEqual(mock_sleep.call_count, 3)
52-
mock_ex.assert_called_with("/out", "/log", mock_nc.return_value, mock_executions[0], 40, "UTC", io)
40+
mock_ex.assert_called_with(submission.output_path, submission.log_path, submission.nextflow_command, mock_executions[0], 40, "UTC", io)
5341
self.assertEqual(mock_ex.call_count, 3)
5442
self.assertEqual(executions, [mock_executions[1]])
55-
56-
57-
@patch("nextflow.command.make_nextflow_command")
58-
@patch("subprocess.Popen")
59-
@patch("time.sleep")
60-
@patch("nextflow.command.get_execution")
61-
def test_can_run_with_custom_io(self, mock_ex, mock_sleep, mock_run, mock_nc):
62-
execution = Mock()
63-
mock_ex.return_value = execution, 20
64-
io = Mock()
65-
executions = list(_run("main.nf", io=io))
66-
mock_nc.assert_called_with(io.abspath.return_value, io.abspath.return_value, io.abspath.return_value, "main.nf", False, None, None, None, None, None, None, None, None, None, io)
67-
io.abspath.assert_called_once_with(".")
68-
mock_run.assert_called_with(
69-
mock_nc.return_value,
70-
universal_newlines=True, shell=True
71-
)
72-
mock_sleep.assert_called_with(1)
73-
mock_ex.assert_called_with(io.abspath.return_value, io.abspath.return_value, mock_nc.return_value, None, 0, None, io)
74-
self.assertEqual(executions, [execution])
7543

7644

77-
@patch("nextflow.command.make_nextflow_command")
78-
@patch("subprocess.Popen")
45+
@patch("nextflow.command.submit_execution")
7946
@patch("time.sleep")
8047
@patch("nextflow.command.get_execution")
81-
def test_can_run_and_poll(self, mock_ex, mock_sleep, mock_run, mock_nc):
82-
mock_run.return_value.poll.side_effect = [None, None, 1]
48+
def test_can_run_and_poll(self, mock_ex, mock_sleep, mock_submit):
49+
submission = Mock()
50+
submission.process.poll = MagicMock()
51+
submission.process.poll.side_effect = [None, None, 1]
52+
mock_submit.return_value = submission
8353
mock_executions = [Mock(finished=False), Mock(finished=True)]
8454
mock_ex.side_effect = [[None, 20], [mock_executions[0], 40], [mock_executions[1], 20]]
8555
executions = list(_run("main.nf", poll=True, output_path="/out"))
86-
mock_nc.assert_called_with(os.path.abspath("."), "/out", "/out", "main.nf", False, None, None, None, None, None, None, None, None, None, None)
87-
mock_run.assert_called_with(
88-
mock_nc.return_value,
89-
universal_newlines=True, shell=True
90-
)
9156
mock_sleep.assert_called_with(1)
9257
self.assertEqual(mock_sleep.call_count, 3)
93-
mock_ex.assert_called_with("/out", "/out", mock_nc.return_value, mock_executions[0], 60, None, None)
58+
mock_ex.assert_called_with(submission.output_path, submission.log_path, submission.nextflow_command, mock_executions[0], 60, None, None)
9459
self.assertEqual(mock_ex.call_count, 3)
9560
self.assertEqual(executions, mock_executions)
9661

9762

98-
@patch("nextflow.command.make_nextflow_command")
99-
@patch("subprocess.Popen")
100-
@patch("time.sleep")
101-
@patch("nextflow.command.get_execution")
102-
def test_can_run_with_custom_runner(self, mock_ex, mock_sleep, mock_run, mock_nc):
103-
runner = MagicMock()
104-
mock_ex.return_value = [Mock(finished=True), 0]
105-
executions = list(_run("main.nf", runner=runner))
106-
mock_nc.assert_called_with(os.path.abspath("."), os.path.abspath("."), os.path.abspath("."), "main.nf", False, None, None, None, None, None, None, None, None, None, None)
107-
self.assertFalse(mock_run.called)
108-
runner.assert_called_with(mock_nc.return_value)
109-
mock_sleep.assert_called_with(1)
110-
mock_ex.assert_called_with(os.path.abspath("."), os.path.abspath("."), mock_nc.return_value, None, 0, None, None)
111-
self.assertEqual(executions, [mock_ex.return_value[0]])
112-
113-
11463
@patch("nextflow.command._run")
11564
def test_can_run_without_poll(self, mock_run):
11665
mock_run.return_value = [Mock(finished=True)]

0 commit comments

Comments
 (0)