Skip to content

Commit

Permalink
Adjust reporting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Aug 12, 2022
1 parent ed034e6 commit 6719c13
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 19 additions & 2 deletions ixmp/tests/reporting/test_computations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re
from functools import partial

import pandas as pd
Expand Down Expand Up @@ -140,6 +141,22 @@ def test_store_ts(request, caplog, test_mp):
c.add("input 3", test_data[0].assign(variable="Foo", region="Moon"))
c.add("test 2", store_ts, "target", "input 3")

# The computation fails
with pytest.raises(ComputationError, match="baz"):
# A message is logged
c.get("test 2")
r = caplog.record_tuples[0]
assert (
1 == len(caplog.record_tuples)
and "ixmp.reporting.computations" == r[0]
and logging.ERROR == r[1]
and r[2].startswith("Failed with ValueError('region = Moon')")
), caplog.record_tuples

caplog.clear()

# with strict=True, the computation fails
c.add("test 2", partial(store_ts, strict=True), "target", "input 3")
with pytest.raises(
ComputationError,
match=re.compile("computing 'test 2' using:.*region = Moon", flags=re.DOTALL),
):
c.get("test 2")
4 changes: 1 addition & 3 deletions ixmp/tests/reporting/test_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ def test_cli(ixmp_cli, test_mp, test_data_path):
# TODO warning should be logged

# Reporting produces the expected command-line output

assert re.match(
"i j " # Trailing whitespace
r"""
Expand All @@ -176,8 +175,7 @@ def test_cli(ixmp_cli, test_mp, test_data_path):
seattle chicago 1\.7
new-york 2\.5
topeka 1\.8
(Name: value, )?dtype: float64
""",
(Name: value, )?dtype: float64(, units: dimensionsless)?""",
result.output,
)

Expand Down

0 comments on commit 6719c13

Please sign in to comment.