def test_download_bids_for_runlevel_acquisition_exception_detected( tmp_path, caplog): caplog.set_level(logging.DEBUG) with patch( "flywheel_gear_toolkit.GearToolkitContext.client", return_value=Acquisition(), ): with patch( "utils.bids.download_run_level.download_bids_dir", side_effect=flywheel.ApiException("foo", "fum"), ): with patch( "utils.bids.download_run_level.validate_bids", return_value=0, ): gtk_context = flywheel_gear_toolkit.GearToolkitContext( input_args=["-d aex:analysis"], gear_path=tmp_path) err_code = download_bids_for_runlevel( gtk_context, HIERARCHY, tree=False, tree_title=None, src_data=True, folders=["anat", "func"], dry_run=True, ) assert len(caplog.records) == 6 assert "(foo) Reason: fum" in caplog.records[4].message
def test_run_level_exception_handled(caplog): caplog.set_level(logging.DEBUG) with patch( "flywheel.Client.get", MagicMock(side_effect=flywheel.ApiException("foo", "fum")), ): fw = flywheel.Client hierarchy = get_run_level_and_hierarchy(fw, "01234") print(caplog.records) assert "Unable to get level and hierarchy" in caplog.records[0].message
def test_run_level_exception_handled(caplog): caplog.set_level(logging.DEBUG) with patch( "flywheel.Client.get", MagicMock(side_effect=flywheel.ApiException("foo", "fum")), ): fw = flywheel.Client hierarchy = get_analysis_run_level_and_hierarchy(fw, "01234") print(caplog.records) assert "does not reference a valid analysis" in caplog.records[0].message
def raise_func(*args): raise flywheel.ApiException(status=400)