6
6
7
7
class RunTests (TestCase ):
8
8
9
- @patch ("os.path.abspath" )
10
- @patch ("nextflow.command.make_nextflow_command" )
11
- @patch ("subprocess.Popen" )
9
+ @patch ("nextflow.command.submit_execution" )
12
10
@patch ("time.sleep" )
13
11
@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 ):
15
13
execution = Mock ()
14
+ submission = Mock ()
15
+ mock_submit .return_value = submission
16
16
mock_ex .return_value = execution , 20
17
17
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
- )
24
18
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 )
26
20
self .assertEqual (executions , [execution ])
27
21
28
22
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" )
32
24
@patch ("time.sleep" )
33
25
@patch ("nextflow.command.get_execution" )
34
26
@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
36
30
mock_executions = [Mock (return_code = "" ), Mock (return_code = "0" )]
37
31
mock_ex .side_effect = [[None , 0 ], [mock_executions [0 ], 40 ], [mock_executions [1 ], 20 ]]
38
32
io = Mock ()
@@ -41,76 +35,31 @@ def test_can_run_with_custom_values(self, mock_ex, mock_sleep, mock_wait, mock_r
41
35
params = {"param" : "2" }, profiles = ["docker" ], timezone = "UTC" , report = "report.html" ,
42
36
timeline = "time.html" , dag = "dag.html" , trace = "trace.html" , sleep = 4 , io = io
43
37
))
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 )
50
38
mock_sleep .assert_called_with (4 )
51
39
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 )
53
41
self .assertEqual (mock_ex .call_count , 3 )
54
42
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 ])
75
43
76
44
77
- @patch ("nextflow.command.make_nextflow_command" )
78
- @patch ("subprocess.Popen" )
45
+ @patch ("nextflow.command.submit_execution" )
79
46
@patch ("time.sleep" )
80
47
@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
83
53
mock_executions = [Mock (finished = False ), Mock (finished = True )]
84
54
mock_ex .side_effect = [[None , 20 ], [mock_executions [0 ], 40 ], [mock_executions [1 ], 20 ]]
85
55
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
- )
91
56
mock_sleep .assert_called_with (1 )
92
57
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 )
94
59
self .assertEqual (mock_ex .call_count , 3 )
95
60
self .assertEqual (executions , mock_executions )
96
61
97
62
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
-
114
63
@patch ("nextflow.command._run" )
115
64
def test_can_run_without_poll (self , mock_run ):
116
65
mock_run .return_value = [Mock (finished = True )]
0 commit comments