Ejemplo n.º 1
0
def test_prepare_for_datalad(tmpdir):
    pytest.importorskip("datalad", minversion=MIN_VERSION)
    studydir = tmpdir.join("PI").join("study")
    studydir_ = str(studydir)
    os.makedirs(studydir_)
    populate_bids_templates(studydir_)

    add_to_datalad(str(tmpdir), studydir_, None, False)

    from datalad.api import Dataset
    superds = Dataset(str(tmpdir))

    assert superds.is_installed()
    assert not superds.repo.dirty
    subdss = superds.subdatasets(recursive=True, result_xfm='relpaths')
    for ds_path in sorted(subdss):
        ds = Dataset(opj(superds.path, ds_path))
        assert ds.is_installed()
        assert not ds.repo.dirty

    # the last one should have been the study
    target_files = {
        '.gitattributes',
        '.datalad/config', '.datalad/.gitattributes',
        'dataset_description.json',
        'CHANGES', 'README'}
    assert set(ds.repo.get_indexed_files()) == target_files
    # and all are under git
    for f in target_files:
        assert not ds.repo.is_under_annex(f)
    assert not ds.repo.is_under_annex('.gitattributes')

    # Above call to add_to_datalad does not create .heudiconv subds since
    # directory does not exist (yet).
    # Let's first check that it is safe to call it again
    add_to_datalad(str(tmpdir), studydir_, None, False)
    assert not ds.repo.dirty

    old_hexsha = ds.repo.get_hexsha()
    # Now let's check that if we had previously converted data so that
    # .heudiconv was not a submodule, we still would not fail
    dsh_path = os.path.join(ds.path, '.heudiconv')
    dummy_path = os.path.join(dsh_path, 'dummy.nii.gz')

    create_file_if_missing(dummy_path, '')
    ds.add(dummy_path, message="added a dummy file")
    # next call must not fail, should just issue a warning
    add_to_datalad(str(tmpdir), studydir_, None, False)
    ds.repo.is_under_annex(dummy_path)
    assert not ds.repo.dirty
    assert '.heudiconv/dummy.nii.gz' in ds.repo.get_files()

    # Let's now roll back and make it a proper submodule
    ds.repo._git_custom_command([], ['git', 'reset', '--hard', old_hexsha])
    # now we do not add dummy to git
    create_file_if_missing(dummy_path, '')
    add_to_datalad(str(tmpdir), studydir_, None, False)
    assert '.heudiconv' in ds.subdatasets(result_xfm='relpaths')
    assert not ds.repo.dirty
    assert '.heudiconv/dummy.nii.gz' not in ds.repo.get_files()
Ejemplo n.º 2
0
def test_populate_bids_templates(tmpdir):
    populate_bids_templates(str(tmpdir),
                            defaults={'Acknowledgements': 'something'})
    for f in "README", "dataset_description.json", "CHANGES":
        # Just test that we have created them and they all have stuff TODO
        assert "TODO" in tmpdir.join(f).read()
    description_file = tmpdir.join('dataset_description.json')
    assert "something" in description_file.read()

    # it should also be available as a command
    os.unlink(str(description_file))

    # it must fail if no heuristic was provided
    with pytest.raises(ValueError) as cme:
        runner(['--command', 'populate-templates', '--files', str(tmpdir)])
    assert str(cme.value).startswith("Specify heuristic using -f. Known are:")
    assert "convertall," in str(cme.value)
    assert not description_file.exists()

    runner([
        '--command', 'populate-templates', '-f', 'convertall', '--files',
        str(tmpdir)
    ])
    assert "something" not in description_file.read()
    assert "TODO" in description_file.read()

    assert load_json(tmpdir / "scans.json") == SCANS_FILE_FIELDS
Ejemplo n.º 3
0
def test_populate_bids_templates(tmpdir):
    populate_bids_templates(
        str(tmpdir),
        defaults={'Acknowledgements': 'something'})
    for f in "README", "dataset_description.json", "CHANGES":
        # Just test that we have created them and they all have stuff TODO
        assert "TODO" in tmpdir.join(f).read()
    assert "something" in tmpdir.join('dataset_description.json').read()
Ejemplo n.º 4
0
def test_populate_bids_templates(tmpdir):
    populate_bids_templates(str(tmpdir),
                            defaults={'Acknowledgements': 'something'})
    for f in "README", "dataset_description.json", "CHANGES":
        # Just test that we have created them and they all have stuff TODO
        assert "TODO" in tmpdir.join(f).read()
    description_file = tmpdir.join('dataset_description.json')
    assert "something" in description_file.read()

    # it should also be available as a command
    os.unlink(str(description_file))
    runner([
        '--command', 'populate-templates', '-f', 'convertall', '--files',
        str(tmpdir)
    ])
    assert "something" not in description_file.read()
    assert "TODO" in description_file.read()