Skip to content

Commit

Permalink
Test deprecated signature for report()
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Nov 2, 2023
1 parent f196191 commit a35b2c7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion message_ix_models/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def discard_on_error(*args):

# Transfer args, kwargs to context
context.set_scenario(scenario)
context.report.legacy = kwargs.pop("legacy")
context.report.legacy.update(kwargs.pop("legacy", {}))

if len(args) + len(set(kwargs.keys()) & {"path"}) != 1:
raise TypeError(
Expand Down
39 changes: 31 additions & 8 deletions message_ix_models/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,41 @@ def _cb(*args):


@MARK[1]
def test_report_bare_res(request, test_context):
def test_report_bare_res(request, tmp_path, test_context):
"""Prepare and run the standard MESSAGE-GLOBIOM reporting on a bare RES."""
scenario = testing.bare_res(request, test_context, solved=True)
test_context.set_scenario(scenario)

# Prepare the reporter
test_context.report.update(from_file="global.yaml", key="message::default")
reporter, key = prepare_reporter(test_context, scenario)
test_context.report.update(
from_file="global.yaml",
# key="message::default",
# Use a key that doesn't access model solution data
key="y0",
output_dir=tmp_path,
)

# Prepare the reporter and compute the result
report(test_context)


@MARK[1]
def test_report_deprecated(caplog, request, tmp_path, test_context):
# Create a target scenario
scenario = testing.bare_res(request, test_context, solved=False)
test_context.set_scenario(scenario)

# Use a key that doesn't access model solution data
test_context.report.key = "y0"

# Set dry_run = True to not actually perform any calculations or modifications
test_context.dry_run = True
# Call succeeds, raises a warning
with pytest.warns(DeprecationWarning, match="pass a Context instead"):
report(scenario, tmp_path)

# Get the default report
# NB commented because the bare RES currently contains no activity, so the
# reporting steps fail
# reporter.get(key)
# Invalid call warns *and* raises TypeError
with pytest.raises(TypeError), pytest.warns(DeprecationWarning):
report(scenario, tmp_path, "foo")


@pytest.mark.xfail(raises=ModuleNotFoundError, reason="Requires message_data")
Expand Down

0 comments on commit a35b2c7

Please sign in to comment.