Skip to content

Commit

Permalink
Adjust two tests for less-informative exceptions
Browse files Browse the repository at this point in the history
…with Python 3.12 and JPype 1.5.0 only.
  • Loading branch information
khaeru committed Jan 8, 2024
1 parent 6ab08fc commit 58617f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 9 additions & 3 deletions ixmp/tests/core/test_scenario.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import sys

import numpy.testing as npt
import pandas as pd
Expand Down Expand Up @@ -93,10 +94,15 @@ def test_from_url(self, mp, caplog):
with pytest.raises(Exception, match=expected):
scen, mp = ixmp.Scenario.from_url(url + "#10000", errors="raise")

# Giving an invalid scenario with errors='warn' raises an exception
# Giving an invalid scenario with errors='warn' causes a message to be logged
msg = (
"ValueError: scenario='Hitchhikerfoo'\n"
f"when loading Scenario from url: {repr(url + 'foo')}"
"ValueError: "
+ (
"scenario='Hitchhikerfoo'"
if sys.version_info.minor != 12
else "model, scenario, or version not found"
)
+ f"\nwhen loading Scenario from url: {repr(url + 'foo')}"
)
with assert_logs(caplog, msg):
scen, mp = ixmp.Scenario.from_url(url + "foo")
Expand Down
8 changes: 7 additions & 1 deletion ixmp/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import sys
from pathlib import Path

import pandas as pd
Expand Down Expand Up @@ -403,7 +404,12 @@ def test_solve(ixmp_cli, test_mp):
]
result = ixmp_cli.invoke(cmd)
assert result.exit_code == 1, result.output
assert "Error: model='non-existing'" in result.output
exp = (
"='non-existing'"
if sys.version_info.minor != 12
else ", scenario, or version not found"
)
assert f"Error: model{exp}" in result.output

result = ixmp_cli.invoke([f"--url=ixmp://{test_mp.name}/foo/bar", "solve"])
assert UsageError.exit_code == result.exit_code, result.output
Expand Down

0 comments on commit 58617f3

Please sign in to comment.