1
1
import pytest
2
2
from hamcrest import assert_that , equal_to
3
- from unittest .mock import Mock
4
3
5
4
from nodestream .cli .operations .run_pipeline import (
6
5
WARNING_NO_TARGETS_PROVIDED ,
@@ -40,7 +39,7 @@ def test_make_run_request(run_pipeline_operation, mocker):
40
39
"step-outbox-size" : "10001" ,
41
40
"target" : targets ,
42
41
"time-interval-seconds" : None , # No time interval provided
43
- "reporting-frequency" : "10000"
42
+ "reporting-frequency" : "10000" ,
44
43
}
45
44
command .option .side_effect = lambda opt : option_responses .get (opt )
46
45
command .has_json_logging_set = False # Required for create_progress_reporter
@@ -55,41 +54,49 @@ def test_make_run_request(run_pipeline_operation, mocker):
55
54
assert_that (result .progress_reporter .reporting_frequency , equal_to (10000 ))
56
55
57
56
58
- def test_create_progress_reporter_with_time_interval_seconds (run_pipeline_operation , mocker ):
57
+ def test_create_progress_reporter_with_time_interval_seconds (
58
+ run_pipeline_operation , mocker
59
+ ):
59
60
"""Test that time_interval_seconds gets properly converted to float and passed to PipelineProgressReporter"""
60
61
command = mocker .Mock ()
61
62
command .option .side_effect = lambda opt : {
62
63
"time-interval-seconds" : "30.5" ,
63
- "reporting-frequency" : "1000"
64
+ "reporting-frequency" : "1000" ,
64
65
}.get (opt )
65
66
command .has_json_logging_set = False
66
-
67
+
67
68
# Mock PipelineProgressReporter to capture arguments
68
- mock_progress_reporter = mocker .patch ("nodestream.cli.operations.run_pipeline.PipelineProgressReporter" )
69
-
70
- result = run_pipeline_operation .create_progress_reporter (command , "test_pipeline" )
71
-
69
+ mock_progress_reporter = mocker .patch (
70
+ "nodestream.cli.operations.run_pipeline.PipelineProgressReporter"
71
+ )
72
+
73
+ _ = run_pipeline_operation .create_progress_reporter (command , "test_pipeline" )
74
+
72
75
# Verify PipelineProgressReporter was called with correct time_interval_seconds
73
76
mock_progress_reporter .assert_called_once ()
74
77
call_args = mock_progress_reporter .call_args
75
78
assert_that (call_args .kwargs ["time_interval_seconds" ], equal_to (30.5 ))
76
79
assert_that (call_args .kwargs ["reporting_frequency" ], equal_to (1000 ))
77
80
78
81
79
- def test_create_progress_reporter_without_time_interval_seconds (run_pipeline_operation , mocker ):
82
+ def test_create_progress_reporter_without_time_interval_seconds (
83
+ run_pipeline_operation , mocker
84
+ ):
80
85
"""Test that time_interval_seconds is None when not provided"""
81
86
command = mocker .Mock ()
82
87
command .option .side_effect = lambda opt : {
83
88
"time-interval-seconds" : None ,
84
- "reporting-frequency" : "2000"
89
+ "reporting-frequency" : "2000" ,
85
90
}.get (opt )
86
91
command .has_json_logging_set = False
87
-
92
+
88
93
# Mock PipelineProgressReporter to capture arguments
89
- mock_progress_reporter = mocker .patch ("nodestream.cli.operations.run_pipeline.PipelineProgressReporter" )
90
-
91
- result = run_pipeline_operation .create_progress_reporter (command , "test_pipeline" )
92
-
94
+ mock_progress_reporter = mocker .patch (
95
+ "nodestream.cli.operations.run_pipeline.PipelineProgressReporter"
96
+ )
97
+
98
+ _ = run_pipeline_operation .create_progress_reporter (command , "test_pipeline" )
99
+
93
100
# Verify PipelineProgressReporter was called with None for time_interval_seconds
94
101
mock_progress_reporter .assert_called_once ()
95
102
call_args = mock_progress_reporter .call_args
@@ -102,62 +109,68 @@ def test_create_progress_reporter_with_json_indicator(run_pipeline_operation, mo
102
109
command = mocker .Mock ()
103
110
command .option .side_effect = lambda opt : {
104
111
"time-interval-seconds" : "15.0" ,
105
- "reporting-frequency" : "500"
112
+ "reporting-frequency" : "500" ,
106
113
}.get (opt )
107
114
command .has_json_logging_set = True
108
-
115
+
109
116
# Mock PipelineProgressReporter to capture arguments
110
- mock_progress_reporter = mocker .patch ("nodestream.cli.operations.run_pipeline.PipelineProgressReporter" )
111
-
112
- result = run_pipeline_operation .create_progress_reporter (command , "test_pipeline" )
113
-
117
+ mock_progress_reporter = mocker .patch (
118
+ "nodestream.cli.operations.run_pipeline.PipelineProgressReporter"
119
+ )
120
+
121
+ _ = run_pipeline_operation .create_progress_reporter (command , "test_pipeline" )
122
+
114
123
# Verify PipelineProgressReporter was called with correct arguments
115
124
mock_progress_reporter .assert_called_once ()
116
125
call_args = mock_progress_reporter .call_args
117
126
assert_that (call_args .kwargs ["time_interval_seconds" ], equal_to (15.0 ))
118
127
assert_that (call_args .kwargs ["reporting_frequency" ], equal_to (500 ))
119
128
120
129
121
- def test_make_run_request_with_time_interval_seconds_integration (run_pipeline_operation , mocker ):
130
+ def test_make_run_request_with_time_interval_seconds_integration (
131
+ run_pipeline_operation , mocker
132
+ ):
122
133
"""Integration test to ensure make_run_request properly handles time_interval_seconds through create_progress_reporter"""
123
134
annotations = ["annotation1" ]
124
135
targets = ["t1" ]
125
136
pipeline_name = "my_pipeline"
126
137
command = mocker .Mock ()
127
-
138
+
128
139
# Setup command.option to handle all the different option calls made by make_run_request
129
140
option_responses = {
130
141
"storage-backend" : "my-storage" ,
131
142
"annotations" : annotations ,
132
143
"step-outbox-size" : "10001" ,
133
144
"target" : targets ,
134
145
"time-interval-seconds" : "45.0" ,
135
- "reporting-frequency" : "5000"
146
+ "reporting-frequency" : "5000" ,
136
147
}
137
148
command .option .side_effect = lambda opt : option_responses .get (opt )
138
149
command .has_json_logging_set = False
139
150
command .is_very_verbose = False
140
151
command .argument .return_value = [pipeline_name ]
141
-
152
+
142
153
pipeline = mocker .Mock ()
143
154
pipeline .name = pipeline_name
144
155
pipeline .configuration = PipelineConfiguration ()
145
-
156
+
146
157
# Mock the project's get_object_storage_by_name method
147
158
run_pipeline_operation .project .get_object_storage_by_name .return_value = None
148
159
run_pipeline_operation .project .get_target_by_name .return_value = None
149
-
160
+
150
161
# Mock PipelineProgressReporter to capture its arguments
151
- mock_progress_reporter = mocker .patch ("nodestream.cli.operations.run_pipeline.PipelineProgressReporter" )
152
-
162
+ mock_progress_reporter = mocker .patch (
163
+ "nodestream.cli.operations.run_pipeline.PipelineProgressReporter"
164
+ )
165
+
153
166
result = run_pipeline_operation .make_run_request (command , pipeline )
154
-
167
+
155
168
# Verify the progress reporter was created with correct time_interval_seconds
156
169
mock_progress_reporter .assert_called_once ()
157
170
call_args = mock_progress_reporter .call_args
158
171
assert_that (call_args .kwargs ["time_interval_seconds" ], equal_to (45.0 ))
159
172
assert_that (call_args .kwargs ["reporting_frequency" ], equal_to (5000 ))
160
-
173
+
161
174
# Verify other parts of the request are still correct
162
175
assert_that (result .pipeline_name , equal_to (pipeline_name ))
163
176
assert_that (result .initialization_arguments .annotations , equal_to (annotations ))
0 commit comments