Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/schema_salad/tests/test_cg.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
1 import json | |
2 import os | |
3 | |
4 import pytest | |
5 | |
6 import schema_salad.metaschema as cg_metaschema | |
7 from schema_salad.ref_resolver import file_uri | |
8 | |
9 from .matcher import JsonDiffMatcher | |
10 from .util import get_data | |
11 | |
12 | |
13 def test_load(): | |
14 doc = { | |
15 "type": "record", | |
16 "fields": [{"name": "hello", "doc": "Hello test case", "type": "string"}], | |
17 } | |
18 rs = cg_metaschema.RecordSchema.fromDoc( | |
19 doc, "http://example.com/", cg_metaschema.LoadingOptions() | |
20 ) | |
21 assert "record" == rs.type | |
22 assert "http://example.com/#hello" == rs.fields[0].name | |
23 assert "Hello test case" == rs.fields[0].doc | |
24 assert "string" == rs.fields[0].type | |
25 assert { | |
26 "type": "record", | |
27 "fields": [ | |
28 { | |
29 "name": "http://example.com/#hello", | |
30 "doc": "Hello test case", | |
31 "type": "string", | |
32 } | |
33 ], | |
34 } == rs.save() | |
35 | |
36 | |
37 def test_err(): | |
38 doc = {"doc": "Hello test case", "type": "string"} | |
39 with pytest.raises(cg_metaschema.ValidationException): | |
40 cg_metaschema.RecordField.fromDoc(doc, "", cg_metaschema.LoadingOptions()) | |
41 | |
42 | |
43 def test_include(): | |
44 doc = {"name": "hello", "doc": [{"$include": "hello.txt"}], "type": "documentation"} | |
45 rf = cg_metaschema.Documentation.fromDoc( | |
46 doc, | |
47 "http://example.com/", | |
48 cg_metaschema.LoadingOptions(fileuri=file_uri(get_data("tests/_"))), | |
49 ) | |
50 assert "http://example.com/#hello" == rf.name | |
51 assert ["hello world!\n"] == rf.doc | |
52 assert "documentation" == rf.type | |
53 assert { | |
54 "name": "http://example.com/#hello", | |
55 "doc": ["hello world!\n"], | |
56 "type": "documentation", | |
57 } == rf.save() | |
58 | |
59 | |
60 def test_import(): | |
61 doc = {"type": "record", "fields": [{"$import": "hellofield.yml"}]} | |
62 lead = file_uri(os.path.normpath(get_data("tests"))) | |
63 rs = cg_metaschema.RecordSchema.fromDoc( | |
64 doc, "http://example.com/", cg_metaschema.LoadingOptions(fileuri=lead + "/_") | |
65 ) | |
66 assert "record" == rs.type | |
67 assert lead + "/hellofield.yml#hello" == rs.fields[0].name | |
68 assert "hello world!\n" == rs.fields[0].doc | |
69 assert "string" == rs.fields[0].type | |
70 assert { | |
71 "type": "record", | |
72 "fields": [ | |
73 { | |
74 "name": lead + "/hellofield.yml#hello", | |
75 "doc": "hello world!\n", | |
76 "type": "string", | |
77 } | |
78 ], | |
79 } == rs.save() | |
80 | |
81 | |
82 maxDiff = None | |
83 | |
84 | |
85 def test_import2(): | |
86 rs = cg_metaschema.load_document( | |
87 file_uri(get_data("tests/docimp/d1.yml")), "", cg_metaschema.LoadingOptions() | |
88 ) | |
89 assert [ | |
90 { | |
91 "doc": [ | |
92 u"*Hello*", | |
93 "hello 2", | |
94 u"*dee dee dee five*", | |
95 "hello 3", | |
96 "hello 4", | |
97 u"*dee dee dee five*", | |
98 "hello 5", | |
99 ], | |
100 "type": "documentation", | |
101 "name": file_uri(get_data("tests/docimp/d1.yml")) | |
102 + "#Semantic_Annotations_for_Linked_Avro_Data", | |
103 } | |
104 ] == [r.save() for r in rs] | |
105 | |
106 | |
107 def test_err2(): | |
108 doc = { | |
109 "type": "rucord", | |
110 "fields": [{"name": "hello", "doc": "Hello test case", "type": "string"}], | |
111 } | |
112 with pytest.raises(cg_metaschema.ValidationException): | |
113 cg_metaschema.RecordSchema.fromDoc(doc, "", cg_metaschema.LoadingOptions()) | |
114 | |
115 | |
116 def test_idmap(): | |
117 doc = { | |
118 "type": "record", | |
119 "fields": {"hello": {"doc": "Hello test case", "type": "string"}}, | |
120 } | |
121 rs = cg_metaschema.RecordSchema.fromDoc( | |
122 doc, "http://example.com/", cg_metaschema.LoadingOptions() | |
123 ) | |
124 assert "record" == rs.type | |
125 assert "http://example.com/#hello" == rs.fields[0].name | |
126 assert "Hello test case" == rs.fields[0].doc | |
127 assert "string" == rs.fields[0].type | |
128 assert { | |
129 "type": "record", | |
130 "fields": [ | |
131 { | |
132 "name": "http://example.com/#hello", | |
133 "doc": "Hello test case", | |
134 "type": "string", | |
135 } | |
136 ], | |
137 } == rs.save() | |
138 | |
139 | |
140 def test_idmap2(): | |
141 doc = {"type": "record", "fields": {"hello": "string"}} | |
142 rs = cg_metaschema.RecordSchema.fromDoc( | |
143 doc, "http://example.com/", cg_metaschema.LoadingOptions() | |
144 ) | |
145 assert "record" == rs.type | |
146 assert "http://example.com/#hello" == rs.fields[0].name | |
147 assert rs.fields[0].doc is None | |
148 assert "string" == rs.fields[0].type | |
149 assert { | |
150 "type": "record", | |
151 "fields": [{"name": "http://example.com/#hello", "type": "string"}], | |
152 } == rs.save() | |
153 | |
154 | |
155 def test_load_pt(): | |
156 doc = cg_metaschema.load_document( | |
157 file_uri(get_data("tests/pt.yml")), "", cg_metaschema.LoadingOptions() | |
158 ) | |
159 assert [ | |
160 "https://w3id.org/cwl/salad#null", | |
161 "http://www.w3.org/2001/XMLSchema#boolean", | |
162 "http://www.w3.org/2001/XMLSchema#int", | |
163 "http://www.w3.org/2001/XMLSchema#long", | |
164 "http://www.w3.org/2001/XMLSchema#float", | |
165 "http://www.w3.org/2001/XMLSchema#double", | |
166 "http://www.w3.org/2001/XMLSchema#string", | |
167 ] == doc.symbols | |
168 | |
169 | |
170 def test_load_metaschema(): | |
171 doc = cg_metaschema.load_document( | |
172 file_uri(get_data("metaschema/metaschema.yml")), | |
173 "", | |
174 cg_metaschema.LoadingOptions(), | |
175 ) | |
176 with open(get_data("tests/metaschema-pre.yml")) as f: | |
177 pre = json.load(f) | |
178 saved = [d.save(relative_uris=False) for d in doc] | |
179 assert saved == JsonDiffMatcher(pre) | |
180 | |
181 | |
182 def test_load_cwlschema(): | |
183 doc = cg_metaschema.load_document( | |
184 file_uri(get_data("tests/test_schema/CommonWorkflowLanguage.yml")), | |
185 "", | |
186 cg_metaschema.LoadingOptions(), | |
187 ) | |
188 with open(get_data("tests/cwl-pre.yml")) as f: | |
189 pre = json.load(f) | |
190 saved = [d.save(relative_uris=False) for d in doc] | |
191 assert saved == JsonDiffMatcher(pre) |