|
4 | 4 |
|
5 | 5 | import os.path |
6 | 6 | import shutil |
| 7 | +import json |
7 | 8 |
|
8 | 9 | from openminds.collection import Collection |
9 | 10 | import openminds.latest.controlled_terms |
@@ -74,3 +75,60 @@ def test_round_trip_multi_file(): |
74 | 75 | p = person.to_jsonld(include_empty_properties=False, embed_linked_nodes=True) |
75 | 76 | np = new_person.to_jsonld(include_empty_properties=False, embed_linked_nodes=True) |
76 | 77 | assert p == np |
| 78 | + |
| 79 | + |
| 80 | +def test_collection_sort_by_id(): |
| 81 | + person = omcore.Person(given_name="A", family_name="Professor", id="_:004") |
| 82 | + uni1 = omcore.Organization(full_name="University of This Place", id="_:002") |
| 83 | + uni2 = omcore.Organization(full_name="University of That Place", id="_:001") |
| 84 | + person.affiliations = [ |
| 85 | + omcore.Affiliation(member_of = uni1), |
| 86 | + omcore.Affiliation(member_of = uni2), |
| 87 | + ] |
| 88 | + |
| 89 | + c = Collection(person,uni1,uni2) |
| 90 | + output_paths = c.save("test_collection_sort_by_id.jsonld", individual_files=False, include_empty_properties=False) |
| 91 | + |
| 92 | + assert output_paths == ["test_collection_sort_by_id.jsonld"] |
| 93 | + |
| 94 | + with open(output_paths[0]) as fp: |
| 95 | + saved_data = json.load(fp) |
| 96 | + os.remove("test_collection_sort_by_id.jsonld") |
| 97 | + |
| 98 | + expected_saved_data={ |
| 99 | + "@context": {"@vocab": "https://openminds.om-i.org/props/"}, |
| 100 | + "@graph": [ |
| 101 | + { |
| 102 | + "@id": "_:001", |
| 103 | + "@type": "https://openminds.om-i.org/types/Organization", |
| 104 | + "fullName": "University of That Place" |
| 105 | + }, |
| 106 | + { |
| 107 | + "@id": "_:002", |
| 108 | + "@type": "https://openminds.om-i.org/types/Organization", |
| 109 | + "fullName": "University of This Place" |
| 110 | + }, |
| 111 | + { |
| 112 | + "@id": "_:004", |
| 113 | + "@type": "https://openminds.om-i.org/types/Person", |
| 114 | + "affiliation": [ |
| 115 | + { |
| 116 | + "@type": "https://openminds.om-i.org/types/Affiliation", |
| 117 | + "memberOf": { |
| 118 | + "@id": "_:002" |
| 119 | + } |
| 120 | + }, |
| 121 | + { |
| 122 | + "@type": "https://openminds.om-i.org/types/Affiliation", |
| 123 | + "memberOf": { |
| 124 | + "@id": "_:001" |
| 125 | + } |
| 126 | + } |
| 127 | + ], |
| 128 | + "familyName": "Professor", |
| 129 | + "givenName": "A" |
| 130 | + } |
| 131 | + ] |
| 132 | + } |
| 133 | + |
| 134 | + assert saved_data == expected_saved_data |
0 commit comments