fre.cmor.tests.test_cmor_yamler_subtool module
tests for fre.cmor.cmor_yamler.cmor_yaml_subtool
- Covers:
full end-to-end run (dry_run_mode=False) via mocked consolidate_yamls
every documented exception path in the function
- fre.cmor.tests.test_cmor_yamler_subtool.test_cmip6_freq_none_derivation_exception_caught(mock_consolidate, tmp_path)
When mip_era=CMIP6, freq is None, and get_bronx_freq_from_mip_table raises a KeyError (e.g. the MIP table JSON has no variable_entry key), the except (KeyError, TypeError) branch catches it, sets freq = None, and the subsequent check raises ValueError. Covers the except branch around get_bronx_freq_from_mip_table.
- fre.cmor.tests.test_cmor_yamler_subtool.test_cmip6_freq_none_derivation_succeeds(mock_consolidate, tmp_path)
When mip_era=CMIP6 and freq is None, but the MIP table carries a derivable frequency (e.g. Omon → “mon” → “monthly”), the function should successfully derive freq and continue (dry-run mode). Covers the successful get_bronx_freq_from_mip_table path.
- fre.cmor.tests.test_cmor_yamler_subtool.test_cmip6_freq_none_no_derivation_raises(mock_consolidate, tmp_path)
ValueError when mip_era=CMIP6, freq is None, and the MIP table frequency cannot be derived (e.g. fx table).
- fre.cmor.tests.test_cmor_yamler_subtool.test_cmip7_freq_none_raises(mock_consolidate, tmp_path)
ValueError when mip_era=CMIP7 and freq is None
- fre.cmor.tests.test_cmor_yamler_subtool.test_cmor_yaml_subtool_dry_run_false(mock_consolidate, yamler_env)
Full end-to-end: cmor_yaml_subtool with dry_run_mode=False should call cmor_run_subtool and produce at least one CMOR-ised .nc file.
- fre.cmor.tests.test_cmor_yamler_subtool.test_dry_run_prints_cli_call(mock_consolidate, tmp_path)
dry_run_mode=True with print_cli_call=True should log the CLI invocation and never call cmor_run_subtool.
- fre.cmor.tests.test_cmor_yamler_subtool.test_dry_run_prints_python_call(mock_consolidate, tmp_path)
dry_run_mode=True with print_cli_call=False should log the Python cmor_run_subtool(…) invocation.
- fre.cmor.tests.test_cmor_yamler_subtool.test_exp_json_does_not_exist(mock_consolidate, tmp_path)
FileNotFoundError when exp_json path does not exist
- fre.cmor.tests.test_cmor_yamler_subtool.test_gridding_dict_has_none_value_raises(mock_consolidate, tmp_path)
ValueError when a gridding field is None
- fre.cmor.tests.test_cmor_yamler_subtool.test_mip_table_file_does_not_exist(mock_consolidate, tmp_path)
FileNotFoundError when the derived json_mip_table_config does not exist
- fre.cmor.tests.test_cmor_yamler_subtool.test_outdir_creation_failure_raises_oserror(mock_consolidate, tmp_path)
OSError when cmorized_outdir does not exist and Path.mkdir fails. Covers the except branch in the outdir-creation block.
- fre.cmor.tests.test_cmor_yamler_subtool.test_outdir_creation_when_missing(mock_consolidate, tmp_path)
When cmorized_outdir does not exist, the function should create it (rather than raising). Verify with a dry-run so we only test the path-creation logic without running CMOR.
- fre.cmor.tests.test_cmor_yamler_subtool.test_pp_dir_does_not_exist(mock_consolidate, tmp_path)
FileNotFoundError when pp_dir does not exist
- fre.cmor.tests.test_cmor_yamler_subtool.test_start_stop_calendar_missing_from_yaml(mock_consolidate, tmp_path)
When start, stop, and calendar_type are None on the CLI AND absent from the YAML dict, the function should log warnings and continue (dry-run mode). Covers the KeyError branches for start/stop/calendar_type.
- fre.cmor.tests.test_cmor_yamler_subtool.test_table_dir_does_not_exist(mock_consolidate, tmp_path)
FileNotFoundError when cmip_cmor_table_dir does not exist
- fre.cmor.tests.test_cmor_yamler_subtool.test_yamlfile_does_not_exist()
FileNotFoundError when yamlfile path does not exist
- fre.cmor.tests.test_cmor_yamler_subtool.yamler_env(tmp_path)
Set up a temporary pp directory tree and output directory that cmor_yaml_subtool can use for a real (non-dry-run) CMIP6 Omon/sos test.