Beispiel #1
0
class TestWetRun:
    def test_wet_run(self, gtk_context):
        acq = gtk_context.get_input_path('acquisition_table')
        ses = gtk_context.get_input_path('session_table')
        sub = gtk_context.get_input_path('subject_table')
        if acq and ses and sub:
            # All inputs provided, there should be no outputs
            run.main(gtk_context)
            outdir = Path(gtk_context.output_dir)
            assert len(os.listdir(outdir)) == 0
        elif not (acq or ses or sub):
            # No inputs provided, there should be three outputs
            run.main(gtk_context)
            outdir = Path(gtk_context.output_dir)
            outfiles = os.listdir(outdir)
            assert len(outfiles) == 3
        else:
            # Raise system exit when not all three or none are provided
            with pytest.raises(SystemExit):
                run.main(gtk_context)
                assert True


#        if gtk_context.config:

if __name__ == '__main__':
    gtk_context = flywheel_gear_toolkit.GearToolkitContext()
    gtk_context.init_logging()
    gtk_context.log_config()
    run.main(gtk_context)
Beispiel #2
0
        df = ld.load_text_dataframe(csv_file, first_row, delimiter)
        mapping_column = ld.validate_df(df, mapping_column, subject_column)

        df = id.import_data(
            fw,
            df,
            project_id,
            mapping_column,
            subject_column,
            object_type,
            attached_files,
            metadata_destination,
            overwrite,
            dry_run,
        )

        report_output = context.output_dir
        id.save_df_to_csv(df, report_output)

    except Exception as e:
        log.exception(e)
        return 1

    return 0


if __name__ == "__main__":

    result = main(gt.GearToolkitContext())
    sys.exit(result)
Beispiel #3
0
def test_dry_run_works(tmp_path, caplog, install_gear, search_caplog_contains,
                       search_caplog):

    caplog.set_level(logging.DEBUG)

    user_json = Path(Path.home() / ".config/flywheel/user.json")
    if not user_json.exists():
        TestCase.skipTest("", f"No API key available in {str(user_json)}")
    with open(user_json) as json_file:
        data = json.load(json_file)
        if "ga" not in data["key"]:
            TestCase.skipTest("", "Not logged in to ga.")

    FWV0 = Path.cwd()

    install_gear("dry_run.zip")

    with flywheel_gear_toolkit.GearToolkitContext(
            input_args=[]) as gtk_context:

        status = run.main(gtk_context)

        assert status == 0
        assert (FWV0 / "work/bids/.bidsignore").exists()
        assert (FWV0 / "freesurfer/subjects/sub-42/label/empty").exists()
        assert search_caplog_contains(
            caplog,
            "command is",
            "--bids-filter-file=input/bids-filter-file/PyBIDS_filter.json",
        )
        assert search_caplog_contains(
            caplog, "--work-dir",
            "flywheel/v0/output/61608fc7dbf5f9487f231006")

        # Since the "work-dir" option was used, the gear created the old data's /tmp/ path and
        # ran in it, and a symbolic link was created from the current /tmp/ path to the old one.
        # The "current" path was created just before these tests started (in conftest.py). E.g.:
        # % ls /tmp
        # gear-temp-dir-2cde80oy -> /tmp/gear-temp-dir-yhv7hq29
        # gear-temp-dir-yhv7hq29
        # where "yhv7hq29" is the old random part found in the provided "work-dir" data and
        # "2cde80oy" is the new random part of the /tmp/ path created to run these tests.
        # The new part is generated randomly so it will change but the old one is in the gear test
        # data provided as an input to the gear.
        old_tmp_path = Path(*(list(Path.cwd().parts)[:3]))
        assert "yhv7hq29" in list(old_tmp_path.parts)[2]
        current_tmp_path = Path(*(list(FWV0.parts)[:3]))
        assert current_tmp_path.is_symlink()
        # now change back to the original /tmp/ path so that following tests will not be affected
        current_tmp_path.unlink()
        old_tmp_path.replace(current_tmp_path)

        assert search_caplog_contains(caplog, "command is", "participant")
        assert search_caplog_contains(caplog, "command is", "'arg1', 'arg2'")
        assert search_caplog(caplog, "No BIDS errors detected.")
        assert search_caplog(caplog, "including sub-TOME3024/figures")
        assert search_caplog(caplog, "Zipping work directory")
        assert search_caplog(caplog,
                             "Zipping work/bids/dataset_description.json")
        assert search_caplog(
            caplog, "Zipping work/bids/sub-TOME3024/ses-Session2/anat")
        assert search_caplog(
            caplog, "Looked for anatsub-TOME3024_desc-about_T1w.html")
        assert search_caplog(caplog, "Warning: gear-dry-run is set")

        # Make sure platform-viewable archive includes figures
        html_zip_files = list(FWV0.glob("output/sub-TOME3024_*.html.zip"))
        html_zip_file = html_zip_files[0]
        assert html_zip_file.exists()
        unzip_archive(html_zip_file, tmp_path)
        assert Path(tmp_path / "index.html").exists()
        assert Path(
            tmp_path /
            "sub-TOME3024/figures/sub-TOME3024_ses-Session2_acq-MPRHA_dseg.svg"
        ).exists()
Beispiel #4
0
    report_generator.upload_report(gear_args['api_key'], session_id,
                                   gear_args.get('parent_acq'))

    # Log number of DICOM files transmitted and exit accordingly
    if DICOMS_SENT == 0:
        log.error("No DICOM files were transmitted. Exiting.")
        os.sys.exit(1)
    elif DICOMS_SENT < DICOMS_PRESENT:
        log.error(
            "Not all DICOMS were successfully transmitted. Please check report."
        )
        os.sys.exit(1)
    else:
        log.info(
            f"!!! TOTAL -- There were {DICOMS_SENT} DICOM files transmitted.")
        exit_status = 0
        return exit_status


if __name__ == "__main__":

    with flywheel_gear_toolkit.GearToolkitContext() as gear_context:
        gear_context.init_logging()
        log = gear_context.log
        exit_status = main(gear_context)

    log.info(
        f"Successful dicom-send gear execution with exit status {exit_status}."
    )