88import tempfile
99import unittest
1010
11+ from odml import Document , Section , Property
1112from odml .tools import odmlparser
1213
1314
@@ -82,6 +83,10 @@ def test_json_file(self):
8283 self .assertEqual (json_doc , self .odml_doc )
8384
8485 def test_rdf_file (self ):
86+ """
87+ Test comparison of document before and after rdf-conversion
88+ """
89+
8590 self .rdf_writer .write_file (self .odml_doc , self .rdf_file )
8691 rdf_doc = self .rdf_reader .from_file (self .rdf_file , "xml" )
8792
@@ -101,6 +106,45 @@ def test_rdf_file(self):
101106 with self .assertRaises (ValueError ):
102107 self .rdf_reader .from_file (self .rdf_file )
103108
109+ doc = Document ()
110+ sec1 = Section (name = "sec1" , type = "int" , parent = doc )
111+ Property (name = "prop11" , values = [1 , 2 , 3 ], dtype = "int" , parent = sec1 )
112+ Property (name = "prop12" , values = [1.1 , 2.2 , 3.3 ], dtype = "float" , parent = sec1 )
113+ Property (name = "prop13" , values = ["a" , "b" , "c" ], dtype = "string" , parent = sec1 )
114+ sec2 = Section (name = "sec2" , type = "int" , parent = doc )
115+ Property (name = "prop21" , values = [1 , 2 , 3 ], dtype = "int" , parent = sec2 )
116+ Property (name = "prop22" , values = [1.1 , 2.2 , 3.3 ], dtype = "float" , parent = sec2 )
117+ Property (name = "prop23" , values = ["a" , "b" , "c" ], dtype = "string" , parent = sec2 )
118+ sec3 = Section (name = "sec3" , type = "int" , parent = doc )
119+ Property (name = "prop31" , values = [1 , 2 , 3 ], dtype = "int" , parent = sec3 )
120+ Property (name = "prop32" , values = [1.1 , 2.2 , 3.3 ], dtype = "float" , parent = sec3 )
121+ Property (name = "prop33" , values = ["a" , "b" , "c" ], dtype = "string" , parent = sec3 )
122+ self .rdf_writer .write_file (doc , self .rdf_file )
123+ rdf_doc = self .rdf_reader .from_file (self .rdf_file , "xml" )
124+
125+ self .assertEqual (doc , rdf_doc [0 ])
126+ self .assertEqual (len (rdf_doc ), 1 )
127+ self .assertEqual (len (rdf_doc [0 ].sections ), 3 )
128+
129+ self .assertIn (doc .sections [0 ].name , rdf_doc [0 ].sections )
130+ self .assertIn (doc .sections [1 ].name , rdf_doc [0 ].sections )
131+ self .assertIn (doc .sections [2 ].name , rdf_doc [0 ].sections )
132+ rdf_sec1 = rdf_doc [0 ].sections [doc .sections [0 ].name ]
133+ self .assertEqual (len (rdf_sec1 .properties ), 3 )
134+ self .assertIn (doc .sections [0 ].properties [0 ].name , rdf_sec1 .properties )
135+ self .assertIn (doc .sections [0 ].properties [1 ].name , rdf_sec1 .properties )
136+ self .assertIn (doc .sections [0 ].properties [1 ].name , rdf_sec1 .properties )
137+ rdf_sec2 = rdf_doc [0 ].sections [doc .sections [1 ].name ]
138+ self .assertEqual (len (rdf_sec2 .properties ), 3 )
139+ self .assertIn (doc .sections [1 ].properties [0 ].name , rdf_sec2 .properties )
140+ self .assertIn (doc .sections [1 ].properties [1 ].name , rdf_sec2 .properties )
141+ self .assertIn (doc .sections [1 ].properties [1 ].name , rdf_sec2 .properties )
142+ rdf_sec3 = rdf_doc [0 ].sections [doc .sections [2 ].name ]
143+ self .assertEqual (len (rdf_sec3 .properties ), 3 )
144+ self .assertIn (doc .sections [2 ].properties [0 ].name , rdf_sec3 .properties )
145+ self .assertIn (doc .sections [2 ].properties [1 ].name , rdf_sec3 .properties )
146+ self .assertIn (doc .sections [2 ].properties [1 ].name , rdf_sec3 .properties )
147+
104148 def test_xml_string (self ):
105149 # Read from string
106150 author = "HPL"
0 commit comments