Skip to content

Commit bb95670

Browse files
committed
[test/odmlparser] Add rdf from_string test
1 parent 1945a45 commit bb95670

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

odml/tools/odmlparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def from_string(self, string, doc_format=None):
166166

167167
elif self.parser == 'RDF':
168168
if not doc_format:
169-
raise KeyError("Format of the rdf file was not specified")
169+
raise ValueError("Format of the rdf file was not specified")
170170

171171
self.doc = RDFReader().from_string(string, doc_format)
172172
return self.doc

test/test_parser_odml.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,37 @@ def test_yaml_string(self):
172172
self.assertEqual(str(ydoc.date), date)
173173
self.assertEqual(len(ydoc.sections), 1)
174174
self.assertEqual(ydoc.sections[0].name, sec_name)
175+
176+
def test_rdf_string(self):
177+
author = "HPL"
178+
date = "1890-08-20"
179+
sec_name = "section name"
180+
sec_type = "section type"
181+
rdf_doc = u"""
182+
@prefix odml: <https://g-node.org/projects/odml-rdf#> .
183+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
184+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
185+
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
186+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
187+
188+
odml:Hub odml:hasDocument <https://g-node.org/projects/odml-rdf#1c9ca24a-1d2c-40b6-a096-5a48efbd77d0> .
189+
190+
<https://g-node.org/projects/odml-rdf#1c9ca24a-1d2c-40b6-a096-5a48efbd77d0> a odml:Document ;
191+
odml:hasAuthor "%s" ;
192+
odml:hasDate "%s"^^xsd:date ;
193+
odml:hasSection <https://g-node.org/projects/odml-rdf#2abc6711-34e1-4102-8e3a-297fa4a3d19a> .
194+
195+
<https://g-node.org/projects/odml-rdf#2abc6711-34e1-4102-8e3a-297fa4a3d19a> a odml:Section ;
196+
odml:hasName "%s" ;
197+
odml:hasType "%s" .
198+
""" % (author, date, sec_name, sec_type)
199+
200+
rdoc = self.rdf_reader.from_string(rdf_doc, "turtle")
201+
202+
self.assertEqual(rdoc[0].author, author)
203+
self.assertEqual(str(rdoc[0].date), date)
204+
self.assertEqual(len(rdoc[0].sections), 1)
205+
self.assertEqual(rdoc[0].sections[0].name, sec_name)
206+
207+
with self.assertRaises(ValueError):
208+
self.rdf_reader.from_string(rdf_doc)

0 commit comments

Comments
 (0)