def test_fetch_parcellations(tmpdir): """Test fetching parcellations.""" this_subjects_dir = str(tmpdir) os.mkdir(op.join(this_subjects_dir, 'fsaverage')) os.mkdir(op.join(this_subjects_dir, 'fsaverage', 'label')) os.mkdir(op.join(this_subjects_dir, 'fsaverage', 'surf')) for hemi in ('lh', 'rh'): shutil.copyfile( op.join(subjects_dir, 'fsaverage', 'surf', '%s.white' % hemi), op.join(this_subjects_dir, 'fsaverage', 'surf', '%s.white' % hemi)) # speed up by prenteding we have one of them with open(op.join(this_subjects_dir, 'fsaverage', 'label', 'lh.aparc_sub.annot'), 'wb'): pass datasets.fetch_aparc_sub_parcellation(subjects_dir=this_subjects_dir) with ArgvSetter(('--accept-hcpmmp-license',)): datasets.fetch_hcp_mmp_parcellation(subjects_dir=this_subjects_dir) for hemi in ('lh', 'rh'): assert op.isfile(op.join(this_subjects_dir, 'fsaverage', 'label', '%s.aparc_sub.annot' % hemi)) # test our annot round-trips here kwargs = dict(subject='fsaverage', hemi='both', sort=False, subjects_dir=this_subjects_dir) labels = read_labels_from_annot(parc='HCPMMP1', **kwargs) write_labels_to_annot( labels, parc='HCPMMP1_round', table_name='./left.fsaverage164.label.gii', **kwargs) orig = op.join(this_subjects_dir, 'fsaverage', 'label', 'lh.HCPMMP1.annot') first = hashfunc(orig) new = orig[:-6] + '_round.annot' second = hashfunc(new) assert first == second
def test_hashfunc(tmpdir): """Test md5/sha1 hash calculations.""" tempdir = str(tmpdir) fname1 = op.join(tempdir, 'foo') fname2 = op.join(tempdir, 'bar') with open(fname1, 'wb') as fid: fid.write(b'abcd') with open(fname2, 'wb') as fid: fid.write(b'efgh') for hash_type in ('md5', 'sha1'): hash1 = hashfunc(fname1, hash_type=hash_type) hash1_ = hashfunc(fname1, 1, hash_type=hash_type) hash2 = hashfunc(fname2, hash_type=hash_type) hash2_ = hashfunc(fname2, 1024, hash_type=hash_type) assert hash1 == hash1_ assert hash2 == hash2_ assert hash1 != hash2