Skip to content

Commit

Permalink
Improve .transport.test_build.test_debug()
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Nov 18, 2024
1 parent 48b75de commit 539c319
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions message_ix_models/tests/model/transport/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ def test_debug(test_context, tmp_path, regions, years, N_node, options):
test_context, tmp_path=tmp_path, regions=regions, years=years, options=options
)

fail = False # Sentinel value for deferred failure assertion

# Check that some keys (a) can be computed without error and (b) have correct units
# commented: these are slow because they repeat some calculations many times.
# Uncommented as needed for debugging
Expand All @@ -194,7 +196,8 @@ def test_debug(test_context, tmp_path, regions, years, N_node, options):
# Quantity can be computed
result = c.get(key)

print(f"{result = }")
# Display the entire `result` object
# print(f"{result = }")

if isinstance(result, Quantity):
print(result.to_series().to_string())
Expand All @@ -214,13 +217,20 @@ def test_debug(test_context, tmp_path, regions, years, N_node, options):
for k, v in result.items():
print(
f"=== {k} ===",
# v.head().to_string(), # Initial rows
v.to_string(), # Entire value
# v.tail().to_string(), # Final rows
v.head().to_string(), # Initial rows
"...",
v.tail().to_string(), # Final rows
# v.to_string(), # Entire value
f"=== {k} ===",
sep="\n",
)
# print(v.tail().to_string())

missing = v.isna()
if missing.any(axis=None):
raise ValueError("Missing values")
print("… missing values")
fail = True # Fail later

assert not fail # Any failure in the above loop

assert not fail # Any failure in the above loop

0 comments on commit 539c319

Please sign in to comment.