77
88import pandas as pd
99import pandas .testing as pdt
10+ import pytest
1011
1112from activitysim .core import testing , workflow
1213
@@ -24,7 +25,6 @@ def _test_path(dirname):
2425def run_test_mtc (
2526 multiprocess = False , chunkless = False , recode = False , sharrow = False , extended = False
2627):
27-
2828 def regress (ext , out_dir ):
2929 if ext :
3030 regress_trips_df = pd .read_csv (_test_path ("regress/final_trips-ext.csv" ))
@@ -226,20 +226,36 @@ def test_mtc_sharrow_ext():
226226]
227227
228228
229- @testing .run_if_exists ("reference-pipeline-extended.zip" )
230- def test_mtc_extended_progressive ():
229+ @pytest .mark .parametrize (
230+ "chunk_training_mode,recode_pipeline_columns" ,
231+ [
232+ ("disabled" , True ),
233+ ("explicit" , False ),
234+ ],
235+ )
236+ def test_mtc_extended_progressive (chunk_training_mode , recode_pipeline_columns ):
231237 import activitysim .abm # register components # noqa: F401
232238
233- out_dir = _test_path ("output-progressive" )
239+ out_dir = _test_path (f "output-progressive-recode { recode_pipeline_columns } " )
234240 Path (out_dir ).mkdir (exist_ok = True )
235241 Path (out_dir ).joinpath (".gitignore" ).write_text ("**\n " )
236242
237243 working_dir = Path (_example_path ("." ))
238244
245+ output_trips_table = {
246+ "tablename" : "trips"
247+ }
248+ if recode_pipeline_columns :
249+ output_trips_table ["decode_columns" ] = {
250+ "origin" : "land_use.zone_id" ,
251+ "destination" : "land_use.zone_id" ,
252+ }
253+
239254 settings = {
240255 "treat_warnings_as_errors" : False ,
241256 "households_sample_size" : 10 ,
242257 "chunk_size" : 0 ,
258+ "chunk_training_mode" : chunk_training_mode ,
243259 "use_shadow_pricing" : False ,
244260 "want_dest_choice_sample_tables" : False ,
245261 "cleanup_pipeline_after_run" : True ,
@@ -249,16 +265,10 @@ def test_mtc_extended_progressive():
249265 "prefix" : "final_" ,
250266 "sort" : True ,
251267 "tables" : [
252- {
253- "tablename" : "trips" ,
254- "decode_columns" : {
255- "origin" : "land_use.zone_id" ,
256- "destination" : "land_use.zone_id" ,
257- },
258- },
268+ output_trips_table ,
259269 ],
260270 },
261- "recode_pipeline_columns" : True ,
271+ "recode_pipeline_columns" : recode_pipeline_columns ,
262272 }
263273
264274 state = workflow .State .make_default (
@@ -277,62 +287,30 @@ def test_mtc_extended_progressive():
277287 assert state .settings .chunk_size == 0
278288 assert not state .settings .sharrow
279289
280- for step_name in EXPECTED_MODELS :
281- state .run .by_name (step_name )
282- try :
283- state .checkpoint .check_against (
284- Path (__file__ ).parent .joinpath ("reference-pipeline-extended.zip" ),
285- checkpoint_name = step_name ,
286- )
287- except Exception :
288- print (f"> prototype_mtc_extended { step_name } : ERROR" )
289- raise
290- else :
291- print (f"> prototype_mtc_extended { step_name } : ok" )
292-
293-
294- @testing .run_if_exists ("reference-pipeline-extended.zip" )
295- def test_mtc_extended_progressive_chunkless ():
296-
297- import activitysim .abm # register components # noqa: F401
298-
299- out_dir = _test_path ("output-progressive-2" )
300- Path (out_dir ).mkdir (exist_ok = True )
301- Path (out_dir ).joinpath (".gitignore" ).write_text ("**\n " )
302-
303- state = workflow .State .make_default (
304- configs_dir = (
305- _test_path ("configs_chunkless" ),
306- _test_path ("ext-configs" ),
307- _example_path ("ext-configs" ),
308- _test_path ("configs" ),
309- _example_path ("configs" ),
310- ),
311- data_dir = _example_path ("data" ),
312- data_model_dir = _example_path ("data_model" ),
313- output_dir = out_dir ,
314- )
315- state .filesystem .persist_sharrow_cache ()
316- state .logging .config_logger ()
317- state .settings .trace_hh_id = 1196298
318-
319- assert state .settings .models == EXPECTED_MODELS
320- assert state .settings .chunk_size == 0
321- assert not state .settings .sharrow
290+ ref_pipeline = Path (__file__ ).parent .joinpath (f"reference-pipeline-extended-recode{ recode_pipeline_columns } .zip" )
291+ if not ref_pipeline .exists ():
292+ state .settings .cleanup_pipeline_after_run = False
322293
323294 for step_name in EXPECTED_MODELS :
324295 state .run .by_name (step_name )
325- try :
326- pass
327- # state.checkpoint.check_against(
328- # Path(__file__).parent.joinpath("reference-pipeline-extended.zip"),
329- # checkpoint_name=step_name,
330- # )
331- except Exception :
332- print (f"> prototype_mtc_extended { step_name } : ERROR" )
333- raise
296+ if ref_pipeline .exists ():
297+ try :
298+ state .checkpoint .check_against (
299+ Path (__file__ ).parent .joinpath (f"reference-pipeline-extended-recode{ recode_pipeline_columns } .zip" ),
300+ checkpoint_name = step_name ,
301+ )
302+ except Exception :
303+ print (f"> prototype_mtc_extended { step_name } : ERROR" )
304+ raise
305+ else :
306+ print (f"> prototype_mtc_extended { step_name } : ok" )
334307 else :
335- print (f"> prototype_mtc_extended { step_name } : ok" )
308+ print (f"> prototype_mtc_extended { step_name } : ran, not checked" )
309+
310+ if not ref_pipeline .exists ():
311+ # make new reference pipeline file if it is missing
312+ import shutil
313+ shutil .make_archive (ref_pipeline .with_suffix ("" ), 'zip' , state .checkpoint .store .filename )
336314
337315
338316if __name__ == "__main__" :
0 commit comments