|
| 1 | +"""Tests for concatenation errors.""" |
| 2 | + |
| 3 | +# pylint: disable=C0116 |
| 4 | + |
| 5 | +import os |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +from concatenator.stitchee import stitchee |
| 10 | + |
| 11 | + |
| 12 | +def test_no_files_to_concatenate(temp_output_dir): |
| 13 | + with pytest.raises(ValueError, match="files_to_concat cannot be empty"): |
| 14 | + stitchee([], output_file=os.path.join(temp_output_dir, "blank.nc")) |
| 15 | + |
| 16 | + |
| 17 | +def test_invalid_concat_method(temp_output_dir, toy_null_dataset): |
| 18 | + with pytest.raises(ValueError, match="Unexpected concatenation method"): |
| 19 | + stitchee( |
| 20 | + [toy_null_dataset], |
| 21 | + output_file=os.path.join(temp_output_dir, "blank.nc"), |
| 22 | + concat_method="unknown-concat", |
| 23 | + ) |
| 24 | + |
| 25 | + |
| 26 | +def test_concat_dim_error_not_supplied_when_required(temp_output_dir, toy_null_dataset): |
| 27 | + with pytest.raises( |
| 28 | + ValueError, match="concat_dim is required when using 'xarray-concat' method" |
| 29 | + ): |
| 30 | + stitchee( |
| 31 | + [toy_null_dataset], |
| 32 | + output_file=os.path.join(temp_output_dir, "blank.nc"), |
| 33 | + concat_method="xarray-concat", |
| 34 | + ) |
| 35 | + |
| 36 | + |
| 37 | +def test_concat_dim_warning_when_supplied_but_not_used(temp_output_dir, toy_null_dataset): |
| 38 | + with pytest.warns(UserWarning, match="'concat_dim' was specified but will not be used"): |
| 39 | + stitchee( |
| 40 | + [toy_null_dataset], |
| 41 | + output_file=os.path.join(temp_output_dir, "blank.nc"), |
| 42 | + concat_method="xarray-combine", |
| 43 | + concat_dim="some_dim", |
| 44 | + ) |
| 45 | + |
| 46 | + |
| 47 | +def test_concat_sorting_variable_not_present_in_data( |
| 48 | + temp_output_dir, ds_3dims_3vars_3coords_1group_part1, ds_3dims_3vars_3coords_1group_part2 |
| 49 | +): |
| 50 | + with pytest.raises(KeyError): |
| 51 | + stitchee( |
| 52 | + [ds_3dims_3vars_3coords_1group_part1, ds_3dims_3vars_3coords_1group_part2], |
| 53 | + output_file=os.path.join(temp_output_dir, "blank.nc"), |
| 54 | + concat_dim="step", |
| 55 | + sorting_variable="unknown_variable", |
| 56 | + ) |
0 commit comments