@@ -194,6 +194,16 @@ def test_pipeline_with_config_from_env(self):
194
194
])
195
195
assert result .exit_code == 0
196
196
197
+ def test_postprocess_with_config_from_env (self ):
198
+ """Test postprocess command with config from environment variable."""
199
+ with patch .dict (os .environ , {'ROMPY_CONFIG' : self .config_json }):
200
+ with patch ('rompy.cli.ModelRun' ) as mock_model_run :
201
+ result = self .runner .invoke (cli , [
202
+ 'postprocess' , '--config-from-env' , '--processor' , 'noop'
203
+ ])
204
+ assert result .exit_code == 0
205
+ assert mock_model_run .called
206
+
197
207
def test_config_from_env_missing_variable (self ):
198
208
"""Test error when ROMPY_CONFIG environment variable is missing."""
199
209
with patch .dict (os .environ , {}, clear = True ):
@@ -232,6 +242,24 @@ def setup_method(self):
232
242
"period" : {"start" : "2020-01-01" , "end" : "2020-01-02" }
233
243
}
234
244
245
+ def test_postprocess_error_on_missing_config (self ):
246
+ """Test error when neither config file nor --config-from-env is specified for postprocess."""
247
+ result = self .runner .invoke (cli , ['postprocess' ])
248
+ assert result .exit_code != 0
249
+ assert "Must specify either" in result .output
250
+
251
+ def test_postprocess_error_on_both_config_and_env (self ):
252
+ """Test error when both config file and --config-from-env are specified for postprocess."""
253
+ with tempfile .NamedTemporaryFile (mode = 'w' , suffix = '.json' , delete = False ) as f :
254
+ json .dump (self .config_data , f )
255
+ config_path = f .name
256
+ try :
257
+ result = self .runner .invoke (cli , ['postprocess' , config_path , '--config-from-env' ])
258
+ assert result .exit_code != 0
259
+ assert "Cannot specify both" in result .output
260
+ finally :
261
+ os .unlink (config_path )
262
+
235
263
def test_validate_with_config_file (self ):
236
264
"""Test that validate command still works with config files."""
237
265
with tempfile .NamedTemporaryFile (mode = 'w' , suffix = '.json' , delete = False ) as f :
@@ -283,6 +311,21 @@ def test_run_with_config_file(self):
283
311
os .unlink (config_path )
284
312
os .unlink (backend_path )
285
313
314
+ def test_postprocess_with_config_file (self ):
315
+ """Test that postprocess command works with config files."""
316
+ with tempfile .NamedTemporaryFile (mode = 'w' , suffix = '.json' , delete = False ) as f :
317
+ json .dump (self .config_data , f )
318
+ config_path = f .name
319
+ try :
320
+ with patch ('rompy.cli.ModelRun' ) as mock_model_run :
321
+ result = self .runner .invoke (cli , [
322
+ 'postprocess' , config_path , '--processor' , 'noop'
323
+ ])
324
+ assert result .exit_code == 0
325
+ assert mock_model_run .called
326
+ finally :
327
+ os .unlink (config_path )
328
+
286
329
287
330
class TestCLIHelpOutput :
288
331
"""Test that help output includes information about environment variable option."""
@@ -315,3 +358,9 @@ def test_pipeline_help_includes_config_from_env(self):
315
358
result = self .runner .invoke (cli , ['pipeline' , '--help' ])
316
359
assert result .exit_code == 0
317
360
assert '--config-from-env' in result .output
361
+
362
+ def test_postprocess_help_includes_config_from_env (self ):
363
+ """Test that postprocess command help mentions --config-from-env option."""
364
+ result = self .runner .invoke (cli , ['postprocess' , '--help' ])
365
+ assert result .exit_code == 0
366
+ assert '--config-from-env' in result .output
0 commit comments