1212import pytest
1313from genno .testing import assert_qty_equal
1414from ixmp import Platform
15+ from ixmp .backend import ItemType
1516from ixmp .backend .jdbc import JDBCBackend
1617from ixmp .report import Reporter as ixmp_Reporter
1718from ixmp .testing import assert_logs
2021from pandas .testing import assert_frame_equal , assert_series_equal
2122
2223from message_ix import Scenario
24+ from message_ix .models import MESSAGE
2325from message_ix .report import Reporter , configure
2426from message_ix .testing import SCENARIO , make_dantzig , make_westeros
2527
@@ -152,6 +154,22 @@ def test_reporter_from_scenario(
152154 assert_qty_equal (vom , rep .get (vom_key ))
153155
154156
157+ @pytest .fixture (scope = "module" )
158+ def exp_len_all (test_mp : Platform ) -> int :
159+ """Expected items collected under the "all" reporting key."""
160+
161+ # - Sets not included in "all".
162+ # - 1 item each for PAR and VAR.
163+ # - 2 items (values and marginals) for EQU.
164+ count = {ItemType .SET : 0 , ItemType .PAR : 1 , ItemType .EQU : 2 , ItemType .VAR : 1 }
165+ N = sum (count [i .type ] for i in MESSAGE .items .values ())
166+
167+ # With IXMP4Backend, scenarios do not include variables 'C' and 'I'
168+ N += 0 if is_ixmp4backend (test_mp ._backend ) else 2
169+
170+ return N
171+
172+
155173#: Expected number of data points for items in the make_dantzig() scenario.
156174EXP_LEN_DANTZIG = defaultdict (
157175 lambda : 0 ,
@@ -175,7 +193,7 @@ def test_reporter_from_scenario(
175193
176194
177195def test_reporter_from_dantzig (
178- request : pytest .FixtureRequest , test_mp : Platform
196+ request : pytest .FixtureRequest , test_mp : Platform , exp_len_all : int
179197) -> None :
180198 scen = make_dantzig (test_mp , solve = True , quiet = True , request = request )
181199
@@ -186,12 +204,11 @@ def test_reporter_from_dantzig(
186204 result = rep .get ("all" )
187205
188206 # Result contains data for expected number of model data items
189- # With IXMP4Backend, `scen` and thus `result` does not include variables 'C' and 'I'
190- assert 268 + (0 if is_ixmp4backend (test_mp ._backend ) else 2 ) == len (result )
207+ assert exp_len_all == len (result )
191208
192209 # Items have expected length
193210 for qty in result :
194- assert EXP_LEN_DANTZIG [qty .name ] == len (qty )
211+ assert EXP_LEN_DANTZIG [qty .name ] == len (qty ), f" { qty . name } : { qty . to_string () } "
195212
196213
197214#: Expected number of data points for items in the make_westeros() scenario.
@@ -227,7 +244,7 @@ def test_reporter_from_dantzig(
227244
228245
229246def test_reporter_from_westeros (
230- request : pytest .FixtureRequest , test_mp : Platform
247+ request : pytest .FixtureRequest , test_mp : Platform , exp_len_all : int
231248) -> None :
232249 scen = make_westeros (test_mp , emissions = True , solve = True , request = request )
233250
@@ -242,7 +259,7 @@ def test_reporter_from_westeros(
242259
243260 # Result contains data for expected number of model data items
244261 # With IXMP4Backend, `scen` and thus `result` does not include variables 'C' and 'I'
245- assert 266 + ( 0 if is_ixmp4backend ( test_mp . _backend ) else 2 ) == len (result )
262+ assert exp_len_all == len (result )
246263
247264 # Items have expected length
248265 for qty in result :
0 commit comments