Skip to content

Commit ba1be52

Browse files
committed
[test/odmlparser] Add json from_string test
1 parent fa17e16 commit ba1be52

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

test/test_parser_odml.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,32 @@ def test_xml_string(self):
121121
self.assertEqual(str(xml_doc.date), date)
122122
self.assertEqual(len(xml_doc.sections), 1)
123123
self.assertEqual(xml_doc.sections[0].name, sec_name)
124+
125+
def test_json_string(self):
126+
author = "HPL"
127+
date = "1890-08-20"
128+
sec_name = "section name"
129+
sec_type = "section type"
130+
doc = """
131+
{
132+
"odml-version": "1.1",
133+
"Document": {
134+
"author": "%s",
135+
"date": "%s",
136+
"sections": [{
137+
"name": "%s",
138+
"type": "%s"
139+
}]
140+
}
141+
}
142+
""" % (author, date, sec_name, sec_type)
143+
144+
json_doc = self.json_reader.from_string(doc)
145+
146+
self.assertEqual(json_doc.author, author)
147+
self.assertEqual(str(json_doc.date), date)
148+
self.assertEqual(len(json_doc.sections), 1)
149+
self.assertEqual(json_doc.sections[0].name, sec_name)
150+
151+
# Test empty return on broken json document
152+
self.assertIsNone(self.json_reader.from_string("{"))

0 commit comments

Comments
 (0)