diff --git a/tests/unit/test_frequency_detection.py b/tests/unit/test_frequency_detection.py index ba4fba0b..672c7d3c 100644 --- a/tests/unit/test_frequency_detection.py +++ b/tests/unit/test_frequency_detection.py @@ -881,6 +881,30 @@ def test_accepts_a_single_path_as_a_string(self): assert detected == pd.Timedelta(days=31) + def test_warns_when_a_readable_file_has_no_detectable_frequency(self): + """A file that opens fine but carries a single timestep. + + This is the other arm of ``if freq is not None`` -- distinct from a + file that fails to open, and the one that produces the "Could not + detect frequency for file" warning rather than "Error processing". + """ + with tempfile.TemporaryDirectory() as tmpdir: + good = Path(tmpdir) / "daily.nc" + self._write(good, [0.0, 1.0, 2.0]) + single = Path(tmpdir) / "one_step.nc" + self._write(single, [0.0]) + + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always") + detected = _detect_frequency_from_individual_files( + [str(good), str(single)] + ) + + assert detected == pd.Timedelta(days=1) + messages = [str(w.message) for w in caught] + assert any("Could not detect frequency for file" in m for m in messages) + assert not any("Error processing file" in m for m in messages) + def test_raises_when_no_file_yields_a_frequency(self): with tempfile.TemporaryDirectory() as tmpdir: path = Path(tmpdir) / "not_netcdf.nc" diff --git a/tests/unit/test_qc_plots.py b/tests/unit/test_qc_plots.py index 1e64c2ec..71593db7 100644 --- a/tests/unit/test_qc_plots.py +++ b/tests/unit/test_qc_plots.py @@ -281,6 +281,37 @@ def _fake(path, *, qc_dir=None, comparison_store=None, preferred_member=None): assert called_with == [nc_path] + def test_combined_overlay_loaded_when_comparison_store_given(self, temp_dir): + """The split-files path forwards its own open dataset to _load_overlay. + + `generate_qc_plots` has an equivalent branch that is covered; this one + was not, so the `comparison_store` arm of + `generate_qc_plots_for_split_files` had never been executed. + """ + paths = _write_split_cmip_files(temp_dir, "tas_Amon", n_chunks=2) + qc_dir = temp_dir / "qc" + from access_moppy.qc import plots as plots_module + + with patch.object( + plots_module, "_load_overlay", return_value=None + ) as mock_overlay: + result = plots_module.generate_qc_plots_for_split_files( + paths, + qc_dir=qc_dir, + comparison_store=temp_dir / "comparison", + preferred_member="r1i1p1f1", + ) + + assert result == qc_dir + assert (qc_dir / "tas_Amon_timeseries.png").exists() + mock_overlay.assert_called_once() + kwargs = mock_overlay.call_args.kwargs + assert kwargs["var_name"] == "tas" + assert kwargs["store_path"] == temp_dir / "comparison" + assert kwargs["preferred_member"] == "r1i1p1f1" + # the dataset handed to the overlay is the combined one, not a single split + assert kwargs["ds"].sizes["time"] == 8 + def test_combined_timeseries_written(self, temp_dir): paths = _write_split_cmip_files(temp_dir, "tas_Amon", n_chunks=2) qc_dir = temp_dir / "qc"