コード例 #1
0
ファイル: utils.py プロジェクト: marcelfarres/NiBetaSeries
 def create_association_pair(src, dst, kind, kind2=None):
     kind2 = kind2 or kind
     pk1 = '#'.join([src, dst, kind])
     if pk1 not in seen_assocs:
         self.session.add(FileAssociation(src=src, dst=dst, kind=kind))
         seen_assocs.add(pk1)
     pk2 = '#'.join([dst, src, kind2])
     if pk2 not in seen_assocs:
         self.session.add(FileAssociation(src=dst, dst=src, kind=kind2))
         seen_assocs.add(pk2)
コード例 #2
0
ファイル: test_models.py プロジェクト: fedeadolfi/pybids
def test_file_associations():
    session = create_session()
    img = BIDSFile('sub-03/func/sub-03_task-rest_run-2_bold.nii.gz')
    md1 = BIDSFile('sub-03/func/sub-03_task-rest_run-2_bold.json')
    md2 = BIDSFile('task-rest_run-2_bold.json')
    assocs = [
        FileAssociation(src=md1.path, dst=img.path, kind="MetadataFor"),
        FileAssociation(src=img.path, dst=md1.path, kind="MetadataIn"),
        FileAssociation(src=md1.path, dst=md2.path, kind="Child"),
        FileAssociation(src=md2.path, dst=md1.path, kind="Parent"),
        FileAssociation(src=md2.path, dst=img.path, kind="Informs")
    ]
    session.add_all([img, md1, md2] + assocs)
    session.commit()
    assert img._associations == [md1, md2] == img.get_associations()
    assert md2._associations == [md1]
    assert img.get_associations(kind='MetadataFor') == []
    assert img.get_associations(kind='MetadataIn') == [md1]
    results = img.get_associations(kind='MetadataIn', include_parents=True)
    assert set(results) == {md1, md2}