Skip to content

Commit

Permalink
Restore test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Nov 17, 2023
1 parent 6de44bf commit 6e76165
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ixmp/backend/jdbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def init(self, ts, annotation):
method = getattr(self.jobj, "new" + klass)
try:
jobj = method(ts.model, ts.scenario, *args)
except java.IxException as e:
except java.IxException as e: # pragma: no cover
_raise_jexception(e)

self._index_and_set_attrs(jobj, ts)
Expand Down
4 changes: 2 additions & 2 deletions ixmp/core/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ def items(
filters = dict()
elif type != ItemType.PAR:
log.warning(
"Scenario.items(…, filters=…) has no effect for item type"
+ repr(type.name)
"Scenario.items(…, filters=…) has no effect for item type "
+ repr(type.name).lower()
)

names = sorted(self._backend("list_items", str(type.name).lower()))
Expand Down
2 changes: 1 addition & 1 deletion ixmp/report/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def remove_ts(
ts.check_out(timeseries_only=True)
try:
ts.remove_timeseries(data)
except Exception:
except Exception: # pragma: no cover
ts.discard_changes()
else:
ts.commit(f"Remove time series data ({__name__}.remove_ts)")
Expand Down
11 changes: 11 additions & 0 deletions ixmp/tests/core/test_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,17 @@ def test_items1(self, scen, item_type, indexed_by, exp):
# Function runs and yields the expected sequence of item names
assert exp == list(scen.items(item_type, indexed_by=indexed_by, par_data=False))

def test_items2(self, caplog, scen):
item_type = ixmp.ItemType.SET

list(scen.items(item_type, filters={"foo": "bar"}))

# Warning is logged
assert (
"Scenario.items(…, filters=…) has no effect for item type 'set'"
in caplog.messages
)

def test_var(self, scen):
df = scen.var("x", filters={"i": ["seattle"]})

Expand Down
5 changes: 5 additions & 0 deletions ixmp/tests/report/test_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def test_configure(test_mp, test_data_path):
# Configure globally; handles 'rename_dims' section
configure(rename_dims={"i": "i_renamed"})

# Test direct import
from ixmp.report import RENAME_DIMS

assert "i" in RENAME_DIMS

# Reporting uses the RENAME_DIMS mapping of 'i' to 'i_renamed'
scen = make_dantzig(test_mp)
rep = Reporter.from_scenario(scen)
Expand Down
4 changes: 4 additions & 0 deletions ixmp/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def test_import(self):
):
import ixmp.reporting.computations # type: ignore # noqa: F401

def test_importerror(self):
with pytest.warns(DeprecationWarning), pytest.raises(ImportError):
import ixmp.reporting.foo # type: ignore # noqa: F401


def test_check_year():
# If y is a string value, raise a Value Error.
Expand Down

0 comments on commit 6e76165

Please sign in to comment.