Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Nov 21, 2023
1 parent 3560213 commit 4c479f6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions ixmp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion ixmp/core/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
)

Expand Down
6 changes: 5 additions & 1 deletion ixmp/tests/core/test_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions ixmp/tests/report/test_util.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions ixmp/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c479f6

Please sign in to comment.