diff --git a/ixmp/__init__.py b/ixmp/__init__.py index acfc57117..a3c881884 100644 --- a/ixmp/__init__.py +++ b/ixmp/__init__.py @@ -69,8 +69,9 @@ def __getattr__(name): if name == "utils": - import ixmp.util + # Import via the old name to trigger DeprecatedPathFinder + import ixmp.utils as util # type: ignore [import-not-found] - return ixmp.util + return util else: raise AttributeError(name) diff --git a/ixmp/core/scenario.py b/ixmp/core/scenario.py index dc539dea8..0ac2bcc78 100644 --- a/ixmp/core/scenario.py +++ b/ixmp/core/scenario.py @@ -478,7 +478,7 @@ def init_item( if idx_names and len(idx_names) != len(idx_sets): raise ValueError( - f"index names {repr(idx_names)} must have same length as index sets" + f"index names {repr(idx_names)} must have the same length as index sets" f" {repr(idx_sets)}" ) diff --git a/ixmp/tests/core/test_scenario.py b/ixmp/tests/core/test_scenario.py index 8c6ec1d97..de3b5c107 100644 --- a/ixmp/tests/core/test_scenario.py +++ b/ixmp/tests/core/test_scenario.py @@ -147,7 +147,7 @@ def test_init_set(self, scen): with pytest.raises(ValueError, match="'foo' already exists"): scen.init_set("foo") - def test_init_par(self, scen): + def test_init_par(self, scen) -> None: scen = scen.clone(keep_solution=False) scen.check_out() @@ -157,6 +157,10 @@ def test_init_par(self, scen): # Return type of idx_sets is still list assert scen.idx_sets("foo") == ["i", "j"] + # Mismatched sets and names + with pytest.raises(ValueError, match="must have the same length"): + scen.init_par("bar", idx_sets=("i", "j"), idx_names=("a", "b", "c")) + def test_init_scalar(self, scen): scen2 = scen.clone(keep_solution=False) scen2.check_out() diff --git a/ixmp/tests/report/test_util.py b/ixmp/tests/report/test_util.py new file mode 100644 index 000000000..47ff277ae --- /dev/null +++ b/ixmp/tests/report/test_util.py @@ -0,0 +1,5 @@ +def test_import_rename_dims(): + """RENAME_DIMS can be imported from .report.util, though defined in .common.""" + from ixmp.report.util import RENAME_DIMS + + assert isinstance(RENAME_DIMS, dict) diff --git a/ixmp/tests/test_util.py b/ixmp/tests/test_util.py index 4c9c8f1de..7813d83a3 100644 --- a/ixmp/tests/test_util.py +++ b/ixmp/tests/test_util.py @@ -20,6 +20,13 @@ def test_import(self): ): import ixmp.reporting.computations # type: ignore # noqa: F401 + def test_import1(self): + """utils can be imported from ixmp, but raises DeprecationWarning.""" + with pytest.warns(DeprecationWarning): + from ixmp import utils + + assert "diff" in dir(utils) + def test_importerror(self): with pytest.warns(DeprecationWarning), pytest.raises(ImportError): import ixmp.reporting.foo # type: ignore # noqa: F401