8
8
import tempfile
9
9
import unittest
10
10
11
+ from odml import Document , Section , Property
11
12
from odml .tools import odmlparser
12
13
13
14
@@ -82,6 +83,10 @@ def test_json_file(self):
82
83
self .assertEqual (json_doc , self .odml_doc )
83
84
84
85
def test_rdf_file (self ):
86
+ """
87
+ Test comparison of document before and after rdf-conversion
88
+ """
89
+
85
90
self .rdf_writer .write_file (self .odml_doc , self .rdf_file )
86
91
rdf_doc = self .rdf_reader .from_file (self .rdf_file , "xml" )
87
92
@@ -101,6 +106,45 @@ def test_rdf_file(self):
101
106
with self .assertRaises (ValueError ):
102
107
self .rdf_reader .from_file (self .rdf_file )
103
108
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
+
104
148
def test_xml_string (self ):
105
149
# Read from string
106
150
author = "HPL"
0 commit comments