@@ -71,7 +71,7 @@ class TestScenario:
7171 "temp_profile" : [{"time" : [0 , 1 , 2 ]}, {"temp" : [1 , 2 , 3 ]}],
7272 "pressure_profile" : [{"time" : [0 , 1 , 2 ]}, {"pressure" : [1 , 2 , 3 ]}],
7373 "height_profile" : [
74- {"time" : [0 , 1 , 2 , 3 , 4 ]}, # TODO #115: should be caught
74+ {"time" : [0 , 1 , 2 ]},
7575 {"height" : [1 , 2 , 3 ]},
7676 ],
7777 "gas_emissions" : [
@@ -260,3 +260,62 @@ def test_time_varying_aero_multimode(key, mode_names):
260260 dist .mode (i_mode ).name
261261 ]["num_conc" ]
262262 )
263+
264+ ERR_MSG_2_ELEM_LIST_EXPECTED = (
265+ "PROF_profile expected to be a 2-element list (of single-element dictionaries)"
266+ )
267+ ERR_MSG_ALL_ELEMS_DICTS = (
268+ "PROF_profile expected to contain only single-element dicts"
269+ )
270+ ERR_MSG_PROFILE_LEN_MATCH = (
271+ "PROF_profile 'time' and 'PROF' arrays do not have matching size"
272+ )
273+ ERR_MSG_TIME_KEY_MISSING = (
274+ "PROF_profile first element is expeced to be"
275+ " a single-element dict with 'time' key"
276+ )
277+ ERR_MSG_PROF_KEY_MISSING = (
278+ "PROF_profile second element is expeced to be"
279+ " a single-element dict with 'PROF' key"
280+ )
281+
282+ @staticmethod
283+ @pytest .mark .parametrize ("prof" , ("height" , "temp" , "pressure" ))
284+ @pytest .mark .parametrize (
285+ "data, msg" ,
286+ (
287+ ({}, ERR_MSG_2_ELEM_LIST_EXPECTED ),
288+ ([{}, {}, {}], ERR_MSG_2_ELEM_LIST_EXPECTED ),
289+ ([[], []], ERR_MSG_ALL_ELEMS_DICTS ),
290+ ([{}, []], ERR_MSG_ALL_ELEMS_DICTS ),
291+ ([[], {}], ERR_MSG_ALL_ELEMS_DICTS ),
292+ ([{"1" : 1 , "2" : 2 }, {}], ERR_MSG_ALL_ELEMS_DICTS ),
293+ ([{"1" : 1 , "2" : 2 , "3" : 3 }, {"1" : 1 , "2" : 2 }], ERR_MSG_ALL_ELEMS_DICTS ),
294+ ([{"xtime" : "" }, {"PROF" : "" }], ERR_MSG_TIME_KEY_MISSING ),
295+ ([{"time" : "" }, {"xPROF" : "" }], ERR_MSG_PROF_KEY_MISSING ),
296+ ([{"time" : "" }, {"PROF" : []}], ERR_MSG_PROFILE_LEN_MATCH ),
297+ ([{"time" : []}, {"PROF" : "" }], ERR_MSG_PROFILE_LEN_MATCH ),
298+ ([{"time" : [1 , 2 ]}, {"PROF" : [1 , 2 , 3 ]}], ERR_MSG_PROFILE_LEN_MATCH ),
299+ ),
300+ )
301+ def test_throws_if_profile_not_of_proper_form (prof , data , msg ):
302+ # arrange
303+ aero_data = ppmc .AeroData (AERO_DATA_CTOR_ARG_MINIMAL )
304+ gas_data = ppmc .GasData (GAS_DATA_CTOR_ARG_MINIMAL )
305+
306+ data = copy .deepcopy (data )
307+ if len (data ) == 2 and isinstance (data [1 ], dict ) and len (data [1 ].keys ()) == 1 :
308+ key = tuple (data [1 ].keys ())[0 ]
309+ new_key = key .replace ("PROF" , prof )
310+ if key != new_key :
311+ data [1 ][new_key ] = data [1 ][key ]
312+ del data [1 ][key ]
313+ ctor_arg = copy .deepcopy (SCENARIO_CTOR_ARG_MINIMAL )
314+ ctor_arg [f"{ prof } _profile" ] = data
315+
316+ # act
317+ with pytest .raises (RuntimeError ) as excinfo :
318+ _ = ppmc .Scenario (gas_data , aero_data , ctor_arg )
319+
320+ # assert
321+ assert str (excinfo .value ) == msg .replace ("PROF" , f"{ prof } " )
0 commit comments