|
| 1 | +import importlib |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +import mplotutils as mpu |
| 6 | + |
| 7 | +DEPRECATED_MODULES = { |
| 8 | + "cartopy_utils": ( |
| 9 | + "cyclic_dataarray", |
| 10 | + "sample_data_map", |
| 11 | + "sample_dataarray", |
| 12 | + "xlabel_map", |
| 13 | + "xticklabels", |
| 14 | + "ylabel_map", |
| 15 | + "yticklabels", |
| 16 | + ), |
| 17 | + "colormaps": ("from_levels_and_cmap",), |
| 18 | + "map_layout": ("set_map_layout",), |
| 19 | + "mpl": ("_get_renderer",), |
| 20 | + "xrcompat": ("infer_interval_breaks",), |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +def test_00_deprecated_not_in_dir(): |
| 25 | + |
| 26 | + dir = mpu.__dir__() |
| 27 | + |
| 28 | + for module in DEPRECATED_MODULES: |
| 29 | + assert module not in dir |
| 30 | + |
| 31 | + |
| 32 | +def test_01_in_dir(): |
| 33 | + |
| 34 | + dir = mpu.__dir__() |
| 35 | + |
| 36 | + assert "hatch" in dir |
| 37 | + |
| 38 | + |
| 39 | +@pytest.mark.parametrize("mod", DEPRECATED_MODULES) |
| 40 | +def test_01_deprecated_modules_from_import(mod): |
| 41 | + |
| 42 | + with pytest.warns(FutureWarning, match=f"``mplotutils.{mod}`` is deprecated"): |
| 43 | + importlib.__import__("mplotutils", fromlist=[mod]) |
| 44 | + |
| 45 | + |
| 46 | +@pytest.mark.parametrize("mod, functions", DEPRECATED_MODULES.items()) |
| 47 | +def test_depm3(mod, functions): |
| 48 | + |
| 49 | + module = importlib.import_module(f"mplotutils.{mod}") |
| 50 | + |
| 51 | + for function in functions: |
| 52 | + with pytest.warns(FutureWarning, match=f"``mplotutils.{mod}`` is deprecated"): |
| 53 | + getattr(module, function) |
| 54 | + |
| 55 | + |
| 56 | +def test_fcn_warns(): |
| 57 | + |
| 58 | + # NOTE: this is the only import that does not warn |
| 59 | + import mplotutils.cartopy_utils |
| 60 | + |
| 61 | + with pytest.warns(FutureWarning): |
| 62 | + mplotutils.cartopy_utils.sample_data_map(6, 6) |
0 commit comments