From 539c3190ec7c4837f88f3d6f4a82d242f35392d2 Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Mon, 18 Nov 2024 04:01:32 +0100 Subject: [PATCH] Improve .transport.test_build.test_debug() --- .../tests/model/transport/test_build.py | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/message_ix_models/tests/model/transport/test_build.py b/message_ix_models/tests/model/transport/test_build.py index dcaea8726..9ae551a4c 100644 --- a/message_ix_models/tests/model/transport/test_build.py +++ b/message_ix_models/tests/model/transport/test_build.py @@ -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 @@ -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()) @@ -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