@@ -42,3 +42,66 @@ def test_rdf_formats(self):
4242 self .assertEqual (len (r [0 ].sections ), 1 )
4343 self .assertEqual (len (r [0 ].sections [0 ].sections ), 1 )
4444 self .assertEqual (len (r [0 ].sections [0 ].properties ), 1 )
45+
46+ def test_doc (self ):
47+ """
48+ Test if a document and its attributes get converted correctly from rdf to odml.
49+ """
50+ doc = Document ()
51+ doc .author = "D. N. Adams"
52+ doc .version = 42
53+ doc .date = datetime .date (1979 , 10 , 12 )
54+
55+ w = RDFWriter (doc ).get_rdf_str ()
56+ r = RDFReader ().from_string (w , "turtle" )
57+
58+ self .assertEqual (r [0 ].author , "D. N. Adams" )
59+ self .assertEqual (r [0 ].version , "42" )
60+ self .assertEqual (r [0 ].date , datetime .date (1979 , 10 , 12 ))
61+
62+ def test_section (self ):
63+ """
64+ Test if a section and its attributes get converted correctly from rdf to odml.
65+ """
66+ doc = Document ()
67+ sec1 = Section (name = "sec1" , type = "test" , parent = doc , definition = "Interesting stuff." ,
68+ reference = "The Journal" )
69+ Section (name = "sec2" , type = "test" , parent = sec1 )
70+
71+ w = RDFWriter (doc ).get_rdf_str ()
72+ r = RDFReader ().from_string (w , "turtle" )
73+
74+ self .assertEqual (r [0 ].sections [0 ].name , "sec1" )
75+ self .assertEqual (r [0 ].sections [0 ].type , "test" )
76+ self .assertEqual (r [0 ].sections [0 ].id , sec1 .id )
77+ self .assertEqual (r [0 ].sections [0 ].definition , "Interesting stuff." )
78+ self .assertEqual (r [0 ].sections [0 ].reference , "The Journal" )
79+ self .assertEqual (r [0 ].sections [0 ].parent , r [0 ])
80+ self .assertEqual (len (r [0 ].sections [0 ].sections ), 1 )
81+
82+ def test_property (self ):
83+ """
84+ Test if a property and its attributes get converted correctly from rdf to odml.
85+ """
86+ doc = Document ()
87+ sec1 = Section (name = "sec1" , type = "test" , parent = doc )
88+ prop2 = Property (name = "numbers" , definition = "any number" , dtype = "float" , parent = sec1 ,
89+ values = [1 , 3.4 , 67.8 , - 12 ], unit = "meter" , uncertainty = 0.8 ,
90+ value_origin = "force" , reference = "Experiment 1" )
91+
92+ w = RDFWriter (doc ).get_rdf_str ()
93+ r = RDFReader ().from_string (w , "turtle" )
94+
95+ prop = r [0 ].sections [0 ].properties ["numbers" ]
96+
97+ self .assertEqual (prop .name , "numbers" )
98+ self .assertEqual (prop .dtype , "float" )
99+ self .assertEqual (prop .id , prop2 .id )
100+ self .assertEqual (prop .parent , r [0 ].sections [0 ])
101+ self .assertEqual (len (prop .values ), 4 )
102+ self .assertEqual (prop .values , [1 , 3.4 , 67.8 , - 12 ])
103+ self .assertEqual (prop .definition , "any number" )
104+ self .assertEqual (prop .unit , "meter" )
105+ self .assertEqual (prop .uncertainty , "0.8" )
106+ self .assertEqual (prop .value_origin , "force" )
107+ self .assertEqual (prop .reference , "Experiment 1" )
0 commit comments