1212from odml .tools .parser_utils import ParserException , InvalidVersionException
1313
1414
15+ _INVALID_ATTRIBUTE_HANDLING_DOC = """
16+ {
17+ "Document": {
18+ "id": "6af2a3ec-9f3a-42d6-a59d-95f3ccbaa383",
19+ "%s": "i_do_not_exist_on_doc_level",
20+ "sections": [
21+ {
22+ "id": "51f3c79c-a7d7-471e-be16-e085caa851fb",
23+ "%s": "i_do_not_exist_on_sec_level",
24+ "type": "test",
25+ "name": "sec",
26+ "sections": [],
27+ "properties": [
28+ {
29+ "id": "c5aed35a-d9ff-437d-82d6-68f0cda8ea94",
30+ "%s": "i_do_not_exist_on_prop_level",
31+ "name": "prop",
32+ "value": [
33+ 1,
34+ 2,
35+ 3
36+ ],
37+ "type": "int"
38+ }
39+ ]
40+ }
41+ ]
42+ },
43+ "odml-version": "1.1"
44+ }
45+ """ .strip ()
46+
47+ _SEC_CREATION_ERROR_DOC = """
48+ {
49+ "Document": {
50+ "id": "6af2a3ec-9f3a-42d6-a59d-95f3ccbaa383",
51+ "sections": [
52+ {
53+ "id": "1113c79c-a7d7-471e-be16-e085caa851fb",
54+ "name": "sec",
55+ "type": "test",
56+ "sections": [
57+ {
58+ "id": "1213c79c-a7d7-471e-be16-e085caa851fb",
59+ "name": "%s",
60+ "type": "test"
61+ },
62+ {
63+ "id": [
64+ "I-am-so-kaputt"
65+ ],
66+ "name": "%s",
67+ "type": "test"
68+ }
69+ ]
70+ }
71+ ]
72+ },
73+ "odml-version": "1.1"
74+ }
75+ """ .strip ()
76+
77+ _PROP_CREATION_ERROR_DOC = """
78+ {
79+ "Document": {
80+ "id": "6af2a3ec-9f3a-42d6-a59d-95f3ccbaa383",
81+ "sections": [
82+ {
83+ "id": "51f3c79c-a7d7-471e-be16-e085caa851fb",
84+ "type": "test",
85+ "name": "sec",
86+ "properties": [
87+ {
88+ "id": "121ed35a-d9ff-437d-82d6-68f0cda8ea94",
89+ "name": "valid_prop"
90+ },
91+ {
92+ "id": "122ed35a-d9ff-437d-82d6-68f0cda8ea94",
93+ "name": "invalid_prop",
94+ "value": [
95+ "a",
96+ "b"
97+ ],
98+ "type": "int"
99+ }
100+ ]
101+ }
102+ ]
103+ },
104+ "odml-version": "1.1"
105+ }
106+ """ .strip ()
107+
108+
15109class TestJSONParser (unittest .TestCase ):
16110
17111 def setUp (self ):
@@ -82,36 +176,7 @@ def test_invalid_attribute_handling(self):
82176 inv_sec_attr = "invalid_sec_attr"
83177 inv_prop_attr = "invalid_prop_attr"
84178
85- file_content = """{
86- "Document": {
87- "id": "6af2a3ec-9f3a-42d6-a59d-95f3ccbaa383",
88- "%s": "i_do_not_exist_on_doc_level",
89- "sections": [
90- {
91- "id": "51f3c79c-a7d7-471e-be16-e085caa851fb",
92- "%s": "i_do_not_exist_on_sec_level",
93- "type": "test",
94- "name": "sec",
95- "sections": [],
96- "properties": [
97- {
98- "id": "c5aed35a-d9ff-437d-82d6-68f0cda8ea94",
99- "%s": "i_do_not_exist_on_prop_level",
100- "name": "prop",
101- "value": [
102- 1,
103- 2,
104- 3
105- ],
106- "type": "int"
107- }
108- ]
109- }
110- ]
111- },
112- "odml-version": "1.1"
113- }
114- """ % (inv_doc_attr , inv_sec_attr , inv_prop_attr )
179+ file_content = _INVALID_ATTRIBUTE_HANDLING_DOC % (inv_doc_attr , inv_sec_attr , inv_prop_attr )
115180 parsed_doc = self ._prepare_doc (filename , file_content )
116181
117182 # Test ParserException on default parse
@@ -138,34 +203,7 @@ def test_sec_creation_error(self):
138203 valid = "valid_sec"
139204 invalid = "invalid_sec"
140205
141- file_content = """{
142- "Document": {
143- "id": "6af2a3ec-9f3a-42d6-a59d-95f3ccbaa383",
144- "sections": [
145- {
146- "id": "1113c79c-a7d7-471e-be16-e085caa851fb",
147- "name": "sec",
148- "type": "test",
149- "sections": [
150- {
151- "id": "1213c79c-a7d7-471e-be16-e085caa851fb",
152- "name": "%s",
153- "type": "test"
154- },
155- {
156- "id": [
157- "I-am-so-kaputt"
158- ],
159- "name": "%s",
160- "type": "test"
161- }
162- ]
163- }
164- ]
165- },
166- "odml-version": "1.1"
167- }
168- """ % (valid , invalid )
206+ file_content = _SEC_CREATION_ERROR_DOC % (valid , invalid )
169207 parsed_doc = self ._prepare_doc (filename , file_content )
170208
171209 # Test ParserException on default parse
@@ -189,36 +227,8 @@ def test_sec_creation_error(self):
189227
190228 def test_prop_creation_error (self ):
191229 filename = "broken_property.yaml"
192- file_content = """{
193- "Document": {
194- "id": "6af2a3ec-9f3a-42d6-a59d-95f3ccbaa383",
195- "sections": [
196- {
197- "id": "51f3c79c-a7d7-471e-be16-e085caa851fb",
198- "type": "test",
199- "name": "sec",
200- "properties": [
201- {
202- "id": "121ed35a-d9ff-437d-82d6-68f0cda8ea94",
203- "name": "valid_prop"
204- },
205- {
206- "id": "122ed35a-d9ff-437d-82d6-68f0cda8ea94",
207- "name": "invalid_prop",
208- "value": [
209- "a",
210- "b"
211- ],
212- "type": "int"
213- }
214- ]
215- }
216- ]
217- },
218- "odml-version": "1.1"
219- }
220- """
221- parsed_doc = self ._prepare_doc (filename , file_content )
230+
231+ parsed_doc = self ._prepare_doc (filename , _PROP_CREATION_ERROR_DOC )
222232
223233 # Test ParserException on default parse
224234 exc_msg = "Property not created"
0 commit comments