def test_get_metadata(path):
    ds = Dataset(path).create(force=True)
    meta = MetadataExtractor(ds, []).get_metadata(True, False)[0]
    del meta['@context']
    dump = dumps(meta, sort_keys=True, indent=2, ensure_ascii=False)
    assert_equal(
        dump, """\
{
  "BIDSVersion": "1.0.0-rc3",
  "author": [
    "Mike One",
    "Anna Two"
  ],
  "citation": [
    "http://studyforrest.org"
  ],
  "conformsto": "http://bids.neuroimaging.io/bids_spec1.0.0-rc3.pdf",
  "description": "Some description",
  "fundedby": "We got money from collecting plastic bottles",
  "license": "PDDL",
  "name": "studyforrest_phase2"
}""")

    test_fname = opj('sub-01', 'func', 'sub-01_task-some_bold.nii.gz')
    cmeta = list(
        MetadataExtractor(
            ds, [opj('sub-01', 'func', 'sub-01_task-some_bold.nii.gz')
                 ]).get_metadata(False, True)[1])
    assert_equal(len(cmeta), 1)
    assert_equal(cmeta[0][0], test_fname)
    # check that we get file props extracted from the file name from pybids
    fmeta = cmeta[0][1]
    assert_equal(fmeta['subject']['id'], '01')
    # There was a RF from a restrictive "type" to a more generic, but more
    # BIDS ad-hoc "suffix" lacking semantic value really in 0.7.0.
    type_field = 'suffix' if external_versions['bids'] >= '0.7.0' else 'type'
    assert_equal(fmeta[type_field], 'bold')
    assert_equal(fmeta['task'], 'some')
    datatype_field = 'datatype' if external_versions[
        'bids'] >= '0.7.0' else 'modality'
    assert_equal(fmeta[datatype_field], 'func')
    # the fact that there is participant vs subject is already hotly debated in Tal's brain
    assert_in('handedness', fmeta['subject'])
    assert_in('language', fmeta['subject'])
    assert_equal(fmeta['subject']['language'], u'русский')
    assert_equal(fmeta['subject']['gender'], u'n/a')
def test_get_metadata_with_README(path):
    ds = Dataset(path).create(force=True)
    meta = MetadataExtractor(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"
}""")
def test_get_metadata_with_description_and_README(path):

    ds = Dataset(path).create(force=True)
    meta = MetadataExtractor(ds, []).get_metadata(True, False)[0]
    del meta['@context']
    dump = dumps(meta, sort_keys=True, indent=2, ensure_ascii=False)
    assert_equal(
        dump, """\
{
  "BIDSVersion": "1.0.0-rc3",
  "conformsto": "http://bids.neuroimaging.io/bids_spec1.0.0-rc3.pdf",
  "description": "Some description",
  "name": "test"
}""")