Beispiel #1
0
 def update_github_metadata(
     self,
     dandiset_ids: Sequence[str],
     exclude: Optional[re.Pattern[str]],
 ) -> None:
     ds_stats: List[DandisetStats] = []
     for d in self.get_dandisets(dandiset_ids, exclude=exclude):
         ds = Dataset(self.target_path / d.identifier)
         repo = self.get_github_repo_for_dataset(ds)
         log.info("Setting metadata for %s ...", repo.full_name)
         stats = self.get_dandiset_stats(ds)
         repo.edit(
             homepage=f"https://identifiers.org/DANDI:{d.identifier}",
             description=self.describe_dandiset(d, stats),
         )
         ds_stats.append(stats)
     if not dandiset_ids and exclude is None:
         superds = Dataset(self.target_path)
         self.set_superds_description(superds, ds_stats)
Beispiel #2
0
    def test_drop_after(self, path):
        ds = Dataset(path).create(force=True)
        ds.repo.set_gitattributes([('a*', {'annex.largefiles': 'nothing'})])
        # make some files go to git, so we could test that we do not blow
        # while trying to drop what is in git not annex
        res = ds.addurls(self.json_file, '{url}', '{name}', drop_after=True)

        assert_result_count(res, 3, action='addurl',
                            status='ok')  # a, b, c  even if a goes to git
        assert_result_count(res, 2, action='drop', status='ok')  # b, c
Beispiel #3
0
 def test_addurls_stdin_input_command_line(self, path):
     # The previous test checks all the cases, but it overrides sys.stdin.
     # Do a simple check that's closer to a command line call.
     Dataset(path).create(force=True)
     runner = WitlessRunner(cwd=path)
     with open(self.json_file) as jfh:
         runner.run(["datalad", "addurls", '-', '{url}', '{name}'],
                    stdin=jfh)
     for fname in ["a", "b", "c"]:
         ok_exists(op.join(path, fname))
Beispiel #4
0
def test_zip_archive(path):
    ds = Dataset(opj(path, 'ds')).create(force=True, no_annex=True)
    ds.add('.')
    with chpwd(path):
        ds.export_archive(filename='my', archivetype='zip')
        assert_true(os.path.exists('my.zip'))
        custom1_md5 = md5sum('my.zip')
        time.sleep(1.1)
        ds.export_archive(filename='my', archivetype='zip')
        assert_equal(md5sum('my.zip'), custom1_md5)
Beispiel #5
0
def check_integration1(login,
                       keyring,
                       path,
                       organization=None,
                       kwargs={},
                       oauthtokens=None):
    kwargs = kwargs.copy()
    if organization:
        kwargs['github_organization'] = organization

    ds = Dataset(path).create()
    config_patch = {}
    if oauthtokens:
        config_patch['hub.oauthtoken'] = tuple(ensure_list(oauthtokens))

    # so we do not pick up local repo configuration/token
    repo_name = 'test_integration1'
    # ATM all the github goodness does not care about "this dataset"
    # so patch the global config
    with patch_config(config_patch):
        # everything works just nice, no conflicts etc
        res = ds.create_sibling_github(repo_name, **kwargs)

        if organization:
            url_fmt = 'https://{login}@github.com/{organization}/{repo_name}.git'
        else:
            url_fmt = 'https://github.com/{login}/{repo_name}.git'
        assert_in_results(res,
                          path=ds.path,
                          url=url_fmt.format(**locals()),
                          preexisted=False)

        # but if we rerun - should kaboom since already has this sibling:
        assert_in_results(
            ds.create_sibling_github(repo_name, on_failure='ignore', **kwargs),
            message=('already has a configured sibling "%s"', 'github'),
            status='error',
        )

        # but we can give it a new name, but it should kaboom since the remote one
        # exists already
        assert_in_results(
            ds.create_sibling_github(repo_name,
                                     name="github2",
                                     on_failure='ignore',
                                     **kwargs),
            message=('repository "%s" already exists on Github',
                     'test_integration1'),
            status='error',
        )
        # we should not leave the broken sibling behind
        assert_not_in('github2', ds.repo.get_remotes())

        # If we ask to reconfigure - should proceed normally
        ds.create_sibling_github(repo_name, existing='reconfigure', **kwargs)
def test_archive(path):
    ds = Dataset(opj(path, 'ds')).create(force=True)
    ds.add('.')
    committed_date = ds.repo.get_commit_date()
    default_outname = opj(path, 'datalad_{}.tar.gz'.format(ds.id))
    with chpwd(path):
        res = list(ds.export_archive())
        assert_status('ok', res)
        assert_result_count(res, 1)
        assert (isabs(res[0]['path']))
    assert_true(os.path.exists(default_outname))
    custom_outname = opj(path, 'myexport.tar.gz')
    # feed in without extension
    ds.export_archive(filename=custom_outname[:-7])
    assert_true(os.path.exists(custom_outname))
    custom1_md5 = md5sum(custom_outname)
    # encodes the original archive filename -> different checksum, despit
    # same content
    assert_not_equal(md5sum(default_outname), custom1_md5)
    # should really sleep so if they stop using time.time - we know
    time.sleep(1.1)
    ds.export_archive(filename=custom_outname)
    # should not encode mtime, so should be identical
    assert_equal(md5sum(custom_outname), custom1_md5)

    def check_contents(outname, prefix):
        with tarfile.open(outname) as tf:
            nfiles = 0
            for ti in tf:
                # any annex links resolved
                assert_false(ti.issym())
                ok_startswith(ti.name, prefix + '/')
                assert_equal(ti.mtime, committed_date)
                if '.datalad' not in ti.name:
                    # ignore any files in .datalad for this test to not be
                    # susceptible to changes in how much we generate a meta info
                    nfiles += 1
            # we have exactly four files (includes .gitattributes for default
            # MD5E backend), and expect no content for any directory
            assert_equal(nfiles, 4)

    check_contents(default_outname, 'datalad_%s' % ds.id)
    check_contents(custom_outname, 'myexport')

    # now loose some content
    if ds.repo.is_direct_mode():
        # in direct mode the add() aove commited directly to the annex/direct/master
        # branch, hence drop will have no effect (notneeded)
        # this might be undesired behavior (or not), but this is not the place to test
        # for it
        return
    ds.drop('file_up', check=False)
    assert_raises(IOError, ds.export_archive, filename=opj(path, 'my'))
    ds.export_archive(filename=opj(path, 'partial'), missing_content='ignore')
    assert_true(os.path.exists(opj(path, 'partial.tar.gz')))
Beispiel #7
0
def test_download_url_dataset(toppath=None, topurl=None, path=None):
    # Non-dataset directory.
    file1_fullpath = opj(path, "file1.txt")
    with chpwd(path):
        download_url(topurl + "file1.txt")
        ok_exists(file1_fullpath)
    os.remove(file1_fullpath)

    files_tosave = ['file1.txt', 'file2.txt']
    urls_tosave = [topurl + f for f in files_tosave]

    ds = Dataset(opj(path, "ds")).create()

    # By default, files are saved when called in a dataset.
    ds.download_url(urls_tosave)
    for fname in files_tosave:
        ok_(ds.repo.file_has_content(fname))

    eq_(ds.repo.get_urls("file1.txt"), [urls_tosave[0]])
    eq_(ds.repo.get_urls("file2.txt"), [urls_tosave[1]])

    ds.download_url([topurl + "file3.txt"], save=False)
    assert_false(ds.repo.file_has_content("file3.txt"))

    # Leading paths for target are created if needed.
    subdir_target = opj("l1", "l2", "f")
    ds.download_url([opj(topurl, "file1.txt")], path=subdir_target)
    ok_(ds.repo.file_has_content(subdir_target))

    subdir_path = opj(ds.path, "subdir", "")
    os.mkdir(subdir_path)
    with chpwd(subdir_path):
        download_url(topurl + "file4.txt")
        download_url(topurl + "file5.txt", path="five.txt")
        ds.download_url(topurl + "file6.txt")
        download_url(topurl + "file7.txt", dataset=ds.path)
    # download_url calls within a subdirectory save the file there
    ok_(ds.repo.file_has_content(opj("subdir", "file4.txt")))
    ok_(ds.repo.file_has_content(opj("subdir", "five.txt")))
    # ... unless the dataset instance is provided
    ok_(ds.repo.file_has_content("file6.txt"))
    # ... but a string for the dataset (as it would be from the command line)
    # still uses CWD semantics
    ok_(ds.repo.file_has_content(opj("subdir", "file7.txt")))

    with chpwd(path):
        # We're in a non-dataset path and pass in a string as the dataset. The
        # path is taken as relative to the current working directory, so we get
        # an error when trying to save it.
        assert_in_results(download_url(topurl + "file8.txt",
                                       dataset=ds.path,
                                       on_failure="ignore"),
                          status="error",
                          action="status")
    assert_false((ds.pathobj / "file8.txt").exists())
Beispiel #8
0
def test_create_alias(ds_path, ria_path, clone_path):
    ds_path = Path(ds_path)
    clone_path = Path(clone_path)

    ds_path.mkdir()
    dsa = Dataset(ds_path / "a").create()

    res = dsa.create_sibling_ria(url="ria+file://{}".format(ria_path),
                                 name="origin",
                                 alias="ds-a")
    assert_result_count(res, 1, status='ok', action='create-sibling-ria')
    eq_(len(res), 1)

    ds_clone = clone(source="ria+file://{}#~ds-a".format(ria_path),
                     path=clone_path / "a")
    assert_repo_status(ds_clone.path)

    # multiple datasets in a RIA store with different aliases work
    dsb = Dataset(ds_path / "b").create()

    res = dsb.create_sibling_ria(url="ria+file://{}".format(ria_path),
                                 name="origin",
                                 alias="ds-b")
    assert_result_count(res, 1, status='ok', action='create-sibling-ria')
    eq_(len(res), 1)

    ds_clone = clone(source="ria+file://{}#~ds-b".format(ria_path),
                     path=clone_path / "b")
    assert_repo_status(ds_clone.path)

    # second dataset in a RIA store with the same alias emits a warning
    dsc = Dataset(ds_path / "c").create()

    with swallow_logs(logging.WARNING) as cml:
        res = dsc.create_sibling_ria(url="ria+file://{}".format(ria_path),
                                     name="origin",
                                     alias="ds-a")
        assert_in(
            "Alias 'ds-a' already exists in the RIA store, not adding an alias",
            cml.out)
    assert_result_count(res, 1, status='ok', action='create-sibling-ria')
    eq_(len(res), 1)
Beispiel #9
0
def test_bf2458(src=None, dst=None):
    ds = Dataset(src).create(force=True)
    ds.save(to_git=False)

    # no clone (empty) into new dst
    clone = install(source=ds.path, path=dst)
    # content is not here
    eq_(clone.repo.whereis('dummy'), [ds.config.get('annex.uuid')])
    # check that plain metadata access does not `get` stuff
    clone.metadata('.', on_failure='ignore')
    eq_(clone.repo.whereis('dummy'), [ds.config.get('annex.uuid')])
def test_add_archive_single_file(repo_path=None):
    ds = Dataset(repo_path).create(force=True)
    with chpwd(repo_path):
        archives = glob('archives/*')
        ds.save(archives, message='Added archives')

        for archive in archives:
            archive_name = os.path.splitext(archive)[0]
            archive_content = os.path.basename(archive_name)
            ds.add_archive_content(archive)
            ok_file_has_content(archive_name, archive_content)
Beispiel #11
0
    def test_addurls_subdataset(self=None, path=None):
        ds = Dataset(path).create(force=True)

        for save in True, False:
            label = "save" if save else "nosave"
            with swallow_outputs() as cmo:
                ds.addurls(self.json_file,
                           "{url}",
                           "{subdir}-" + label + "//{name}",
                           save=save,
                           cfg_proc=["yoda"])
                # The custom result renderer transforms the subdataset
                # action=create results into something more informative than
                # "create(ok): . (dataset)"...
                assert_in("create(ok): foo-{} (dataset)".format(label),
                          cmo.out)
                # ... and that doesn't lose the standard summary.
                assert_in("create (ok: 2)", cmo.out)

            subdirs = [
                op.join(ds.path, "{}-{}".format(d, label))
                for d in ["foo", "bar"]
            ]
            subdir_files = dict(zip(subdirs, [["a", "c"], ["b"]]))

            for subds, fnames in subdir_files.items():
                for fname in fnames:
                    ok_exists(op.join(subds, fname))
                # cfg_proc was applied generated subdatasets.
                ok_exists(op.join(subds, "code"))
            if save:
                assert_repo_status(path)
            else:
                # The datasets are create but not saved (since asked not to)
                assert_repo_status(path, untracked=subdirs)
                # but the downloaded files aren't.
                for subds, fnames in subdir_files.items():
                    assert_repo_status(subds, added=fnames)

        # Now save the "--nosave" changes and check that we have
        # all the subdatasets.
        ds.save()
        eq_(
            set(subdatasets(dataset=ds, recursive=True,
                            result_xfm="relpaths")),
            {"foo-save", "bar-save", "foo-nosave", "bar-nosave"})

        # We don't try to recreate existing subdatasets.
        with swallow_logs(new_level=logging.DEBUG) as cml:
            ds.addurls(self.json_file,
                       "{url}",
                       "{subdir}-nosave//{name}",
                       result_renderer='disabled')
            assert_in("Not creating subdataset at existing path", cml.out)
Beispiel #12
0
def test_custom_commit_date(tmp_path: Path) -> None:
    ds = Dataset(tmp_path)
    ds.create(cfg_proc="text2git")
    (tmp_path / "file.txt").write_text("This is test text.\n")
    with custom_commit_date(
            datetime(2021, 6, 1, 12, 34, 56, tzinfo=timezone.utc)):
        ds.save(message="Add a file")
    repo = GitRepo(tmp_path)
    assert repo.get_commit_date("HEAD") == "2021-06-01T12:34:56+00:00"
    assert repo.get_commit_author(
        "HEAD") == "DANDI User <*****@*****.**>"
Beispiel #13
0
 def test_addurls_invalid_input(self=None, path=None):
     ds = Dataset(path).create(force=True)
     in_file = op.join(path, "in")
     for in_type in au.INPUT_TYPES:
         with assert_raises(IncompleteResultsError) as exc:
             ds.addurls(in_file,
                        "{url}",
                        "{name}",
                        input_type=in_type,
                        result_renderer='disabled')
         assert_in("Failed to read", str(exc.value))
Beispiel #14
0
def create_study(json_data):
    study_id = json_data["name"]
    folder_name = studies_folder + "/" + study_id

    if not os.path.isdir(folder_name):
        os.makedirs(folder_name)
        datalad_dataset = Dataset(folder_name)
        file_name = studies_folder + "/" + study_id + "/" + study_id + ".json"
        with open(file_name, 'w') as f:
            json.dump(json_data, f, ensure_ascii=False, indent=4)
        datalad_dataset.save(file_name, message="new file " + file_name + " for study")
Beispiel #15
0
    def test_addurls_repindex(self, path):
        ds = Dataset(path).create(force=True)

        with assert_raises(IncompleteResultsError) as raised:
            ds.addurls(self.json_file, "{url}", "{subdir}")
        assert_in("There are file name collisions", str(raised.exception))

        ds.addurls(self.json_file, "{url}", "{subdir}-{_repindex}")

        for fname in ["foo-0", "bar-0", "foo-1"]:
            ok_exists(op.join(ds.path, fname))
Beispiel #16
0
    def test_addurls(self, path):
        ds = Dataset(path).rev_create(force=True)

        def get_annex_commit_counts():
            return int(
                ds.repo.repo.git.rev_list("--count", "git-annex").strip())

        n_annex_commits = get_annex_commit_counts()

        with chpwd(path):
            ds.addurls(self.json_file, "{url}", "{name}")

            filenames = ["a", "b", "c"]
            for fname in filenames:
                ok_exists(fname)

            for (fname, meta), subdir in zip(ds.repo.get_metadata(filenames),
                                             ["foo", "bar", "foo"]):
                assert_dict_equal(meta,
                                  {"subdir": [subdir], "name": [fname]})

            # Ignore this check if we're faking dates because that disables
            # batch mode.
            if not os.environ.get('DATALAD_FAKE__DATES'):
                # We should have two new commits on the git-annex: one for the
                # added urls and one for the added metadata.
                eq_(n_annex_commits + 2, get_annex_commit_counts())

            # Add to already existing links, overwriting.
            with swallow_logs(new_level=logging.DEBUG) as cml:
                ds.addurls(self.json_file, "{url}", "{name}",
                           ifexists="overwrite")
                for fname in filenames:
                    assert_in("Removing {}".format(os.path.join(path, fname)),
                              cml.out)

            # Add to already existing links, skipping.
            assert_in_results(
                ds.addurls(self.json_file, "{url}", "{name}", ifexists="skip"),
                action="addurls",
                status="notneeded")

            # Add to already existing links works, as long content is the same.
            ds.addurls(self.json_file, "{url}", "{name}")

            # But it fails if something has changed.
            ds.unlock("a")
            with open("a", "w") as ofh:
                ofh.write("changed")
            ds.rev_save("a")

            assert_raises(IncompleteResultsError,
                          ds.addurls,
                          self.json_file, "{url}", "{name}")
Beispiel #17
0
 def test_addurls_no_rows(self=None, path=None):
     ds = Dataset(path).create(force=True)
     for fname in ["in.csv", "in.tsv", "in.json"]:
         with swallow_logs(new_level=logging.WARNING) as cml:
             assert_in_results(ds.addurls(fname,
                                          "{url}",
                                          "{name}",
                                          result_renderer='disabled'),
                               action="addurls",
                               status="notneeded")
             cml.assert_logged("No rows", regex=False)
Beispiel #18
0
def test_dont_trip_over_missing_subds(path):
    ds1 = Dataset(opj(path, 'ds1')).create()
    ds2 = Dataset(opj(path, 'ds2')).create()
    subds2 = ds1.install(source=ds2.path,
                         path='subds2',
                         result_xfm='datasets',
                         return_type='item-or-list')
    assert_true(subds2.is_installed())
    assert_in('subds2', ds1.subdatasets(result_xfm='relpaths'))
    subds2.uninstall()
    assert_in('subds2', ds1.subdatasets(result_xfm='relpaths'))
    assert_false(subds2.is_installed())
    # see if it wants to talk to github (and fail), or if it trips over something
    # before
    assert_raises(gh.BadCredentialsException,
                  ds1.create_sibling_github,
                  'bogus',
                  recursive=True,
                  github_login='******')
    # inject remote config prior run
    assert_not_in('github', ds1.repo.get_remotes())
    # fail on existing
    ds1.repo.add_remote('github', 'http://nothere')
    assert_raises(ValueError,
                  ds1.create_sibling_github,
                  'bogus',
                  recursive=True,
                  github_login='******')
    # talk to github when existing is OK
    assert_raises(gh.BadCredentialsException,
                  ds1.create_sibling_github,
                  'bogus',
                  recursive=True,
                  github_login='******',
                  existing='reconfigure')
    # return happy emptiness when all is skipped
    assert_equal(
        ds1.create_sibling_github('bogus',
                                  recursive=True,
                                  github_login='******',
                                  existing='skip'), [])
 def setUp(self):
     pt = Path.cwd() / 'ephy_testing_data'
     if pt.exists():
         self.dataset = Dataset(pt)
     else:
         self.dataset = install(
             'https://gin.g-node.org/NeuralEnsemble/ephy_testing_data')
     # Must pin to previous dataset version
     # See https://github.com/SpikeInterface/spikeextractors/pull/675
     self.dataset.repo.call_git(
         ['checkout', '17e8f37674d70af84cdba6acd83df964a8e09f0c'])
     self.savedir = Path(tempfile.mkdtemp())
Beispiel #20
0
def test_get_metadata_with_README(path):
    ds = Dataset(path).create(force=True)
    meta = MetadataParser(ds, []).get_metadata(True, False)[0]
    del meta['@context']
    dump = dumps(meta, sort_keys=True, indent=2, ensure_ascii=False)
    assert_equal(
        dump, u"""\
{
  "conformsto": "http://bids.neuroimaging.io",
  "description": "A very detailed\\ndescription с юникодом",
  "name": "test"
}""")
Beispiel #21
0
def test_ensure_datalad_remote_maybe_enable(path=None, *, autoenable):
    path = Path(path)
    ds_a = Dataset(path / "a").create(force=True)
    init_datalad_remote(ds_a.repo, DATALAD_SPECIAL_REMOTE,
                        autoenable=autoenable)

    ds_b = clone(source=ds_a.path, path=path / "b")
    repo = ds_b.repo
    if not autoenable:
        assert_not_in("datalad", repo.get_remotes())
    ensure_datalad_remote(repo)
    assert_in("datalad", repo.get_remotes())
Beispiel #22
0
def get_sourcerepo():
    srcrepopath = normpath(opj(dirname(datalad_neuroimaging.__file__), pardir))
    srcrepo = Dataset(srcrepopath)
    if not srcrepo.is_installed():
        srcrepo = install(
            source='https://github.com/datalad/datalad-neuroimaging.git',
            path=opj(appdirs.user_cache_dir, 'datalad_neuroimaging_srcrepo'))
        # this will eventually show us if we can properly upgrade submodules
        srcrepo.update(merge=True)
        # TODO we might want to try to check out a tag that corresponds to the
        # installed version
    return srcrepo
Beispiel #23
0
def test_ephemeral(ds_path=None, store_path=None, clone_path=None):

    dspath = Path(ds_path)
    store = Path(store_path)
    file_test = Path('file1.txt')
    file_testsub = Path('sub') / 'other.txt'

    # create the original dataset
    ds = Dataset(dspath)
    ds.create(force=True)
    ds.save()

    # put into store:
    ds.create_sibling_ria("ria+{}".format(store.as_uri()),
                          "riastore",
                          new_store_ok=True)
    ds.push(to="riastore", data="anything")

    # now, get an ephemeral clone from the RIA store:
    eph_clone = clone('ria+{}#{}'.format(store.as_uri(), ds.id),
                      clone_path,
                      reckless="ephemeral")

    # ephemeral clone was properly linked (store has bare repos!):
    clone_annex = (eph_clone.repo.dot_git / 'annex')
    assert_true(clone_annex.is_symlink())
    assert_true(clone_annex.resolve().samefile(store / ds.id[:3] / ds.id[3:] /
                                               'annex'))
    if not eph_clone.repo.is_managed_branch():
        # TODO: We can't properly handle adjusted branch yet
        # we don't need to get files in order to access them:
        assert_equal((eph_clone.pathobj / file_test).read_text(), "some")
        assert_equal((eph_clone.pathobj / file_testsub).read_text(), "other")

        # can we unlock those files?
        eph_clone.unlock(file_test)
        # change content
        (eph_clone.pathobj / file_test).write_text("new content")
        eph_clone.save()

        # new content should already be in store
        # (except the store doesn't know yet)
        res = eph_clone.repo.fsck(remote="riastore-storage", fast=True)
        assert_equal(len(res), 2)
        assert_result_count(res, 1, success=True, file=file_test.as_posix())
        assert_result_count(res, 1, success=True, file=file_testsub.as_posix())

        # push back git history
        eph_clone.push(to=DEFAULT_REMOTE, data="nothing")

        # get an update in origin
        ds.update(merge=True, reobtain_data=True)
        assert_equal((ds.pathobj / file_test).read_text(), "new content")
Beispiel #24
0
def release(
    datasetter: DandiDatasetter,
    dandiset: str,
    version: str,
    commitish: Optional[str],
    push: bool,
) -> None:
    dandiset_obj = datasetter.dandi_client.get_dandiset(dandiset, version)
    dataset = Dataset(datasetter.target_path / dandiset)
    datasetter.mkrelease(dandiset_obj, dataset, commitish=commitish, push=push)
    if push:
        dataset.push(to="github", jobs=datasetter.config.jobs)
def test_dicom(path):
    ds = Dataset(path).create()
    ds.config.add('datalad.metadata.nativetype', 'dicom', where='dataset')
    copy(
        opj(dirname(dirname(dirname(__file__))), 'tests', 'data', 'dicom.dcm'),
        path)
    ds.add('.')
    ok_clean_git(ds.path)
    res = ds.aggregate_metadata()
    assert_status('ok', res)
    # query for the file metadata
    res = ds.metadata('dicom.dcm')
    assert_result_count(res, 1)
    # from this extractor
    meta = res[0]['metadata']['dicom']
    assert_in('@context', meta)
    # no point in testing ALL keys, but we got plenty
    assert (len(meta.keys()) > 70)
    eq_(meta['SeriesDate'], '20070205')

    # now ask for the dataset metadata, which should have both the unique props
    # and a list of imageseries (one in this case, but a list)
    res = ds.metadata(reporton='datasets')
    assert_result_count(res, 1)
    dsmeta = res[0]['metadata']['dicom']
    # same context
    assert_dict_equal(meta['@context'], dsmeta['@context'])
    meta.pop('@context')
    eq_(dsmeta['Series'], [meta])

    # for this artificial case pretty much the same info also comes out as
    # unique props, but wrapped in lists
    ucp = res[0]['metadata']["datalad_unique_content_properties"]['dicom']
    assert_dict_equal(
        {
            k: [v]
            for k, v in dsmeta['Series'][0].items()
            if k not in DicomExtractor._unique_exclude and k in ucp
        }, {
            k: v
            for k, v in ucp.items() if k not in DicomExtractor._unique_exclude
        })

    # buuuut, if we switch of file-based metadata storage
    ds.config.add('datalad.metadata.aggregate-content-dicom',
                  'false',
                  where='dataset')
    ds.aggregate_metadata()
    res = ds.metadata(reporton='datasets')

    # the auto-uniquified bits are gone but the Series description stays
    assert_not_in("datalad_unique_content_properties", res[0]['metadata'])
    eq_(dsmeta['Series'], [meta])
 def setup(self):
     repo_path = tempfile.mkdtemp(**get_tempfile_kwargs(prefix="tree"))
     create_tree(repo_path,
                 {'1.tar': {
                     'file.txt': 'load',
                     '1.dat': 'load2'
                 }})
     self.ds = ds = Dataset(repo_path)
     ds.create(force=True)
     self.annex = ds.repo
     # Let's add first archive to the annex so we could test
     ds.save('1.tar', message="added 1.tar")
Beispiel #27
0
def test_dont_trip_over_missing_subds(path):
    ds1 = Dataset(opj(path, 'ds1')).create()
    ds2 = Dataset(opj(path, 'ds2')).create()
    subds2 = ds1.install(source=ds2.path, path='subds2')
    assert_true(subds2.is_installed())
    assert_in('subds2', ds1.get_subdatasets())
    subds2.uninstall(remove_handles=True, remove_history=True)
    assert_in('subds2', ds1.get_subdatasets())
    assert_false(subds2.is_installed())
    # this will deinit the submodule
    ds1.save(files=['subds2'])
    # see if it wants to talk to github (and fail), or if it trips over something
    # before
    assert_raises(gh.BadCredentialsException,
                  ds1.create_sibling_github,
                  'bogus',
                  recursive=True,
                  github_user='')
    # inject remote config prior run
    assert_not_in('github', ds1.repo.get_remotes())
    # fail on existing
    ds1.repo.add_remote('github', 'http://nothere')
    assert_raises(ValueError,
                  ds1.create_sibling_github,
                  'bogus',
                  recursive=True,
                  github_user='')
    # talk to github when existing is OK
    assert_raises(gh.BadCredentialsException,
                  ds1.create_sibling_github,
                  'bogus',
                  recursive=True,
                  github_user='',
                  existing='reconfigure')
    # return happy emptiness when all is skipped
    assert_equal(
        ds1.create_sibling_github('bogus',
                                  recursive=True,
                                  github_user='',
                                  existing='skip'), [])
Beispiel #28
0
def test_container_files(ds_path, local_file, url):
    # setup things to add
    #
    # Note: Since "adding" as a container doesn't actually call anything or use
    # the container in some way, but simply registers it, for testing any file
    # is sufficient.
    local_file = get_local_file_url(op.join(local_file, 'some_container.img'))

    # prepare dataset:
    ds = Dataset(ds_path).create()
    # non-default location:
    ds.config.add("datalad.containers.location",
                  value=op.join(".datalad", "test-environments"),
                  where='dataset')
    ds.save(message="Configure container mountpoint")

    # no containers yet:
    res = ds.containers_list(**RAW_KWDS)
    assert_result_count(res, 0)

    # add first "image": must end up at the configured default location
    target_path = op.join(ds.path, ".datalad", "test-environments", "first",
                          "image")
    res = ds.containers_add(name="first", url=local_file)
    ok_clean_git(ds.repo)

    assert_result_count(res,
                        1,
                        status="ok",
                        type="file",
                        path=target_path,
                        action="containers_add")
    ok_(op.lexists(target_path))

    res = ds.containers_list(**RAW_KWDS)
    assert_result_count(res, 1)
    assert_result_count(res,
                        1,
                        name='first',
                        type='file',
                        action='containers',
                        status='ok',
                        path=target_path)

    # and kill it again
    # but needs name
    assert_raises(TypeError, ds.containers_remove)
    res = ds.containers_remove('first', remove_image=True)
    assert_status('ok', res)
    assert_result_count(ds.containers_list(**RAW_KWDS), 0)
    # image removed
    assert (not op.lexists(target_path))
Beispiel #29
0
    def test_addurls_metafail(self, path):
        ds = Dataset(path).create(force=True)

        # Force failure by passing a non-existent file name to annex.
        fn = ds.repo.set_metadata_

        def set_meta(_, **kwargs):
            for i in fn("wreaking-havoc-and-such", **kwargs):
                yield i

        with patch.object(ds.repo, 'set_metadata_', set_meta):
            with assert_raises(IncompleteResultsError):
                ds.addurls(self.json_file, "{url}", "{name}")
Beispiel #30
0
def test_invalid_calls(path):

    ds = Dataset(path).create()

    # no argument:
    assert_raises(TypeError, ds.create_sibling_ria)

    # same name for git- and special remote:
    assert_raises(ValueError,
                  ds.create_sibling_ria,
                  'ria+file:///some/where',
                  name='some',
                  ria_remote_name='some')