@@ -196,3 +196,98 @@ def test_insert(self):
196
196
with self .assertRaises (ValueError ):
197
197
doc .insert (0 , subsec )
198
198
self .assertEqual (len (doc ), 3 )
199
+
200
+ def test_comparison (self ):
201
+ doc_auth = "author"
202
+ doc_ver = "ver1.0"
203
+
204
+ doc_a = Document (author = doc_auth , version = doc_ver )
205
+ doc_b = Document (author = doc_auth , version = doc_ver )
206
+
207
+ self .assertEqual (doc_a , doc_b )
208
+
209
+ doc_b .author = "someone else"
210
+ self .assertNotEqual (doc_a , doc_b )
211
+
212
+ doc_b .author = doc_auth
213
+
214
+ # Test section equality with subsections
215
+
216
+ # Test equality with subsection of different entities
217
+ # with same content and same children order
218
+ sec_type = "sec type"
219
+ sec_def = "an odml test section"
220
+ sec_ref = "from over there"
221
+
222
+ subsec_aa = Section (name = "subsecA" , type = sec_type ,
223
+ definition = sec_def , reference = sec_ref )
224
+ subsec_ab = Section (name = "subsecB" , type = sec_type ,
225
+ definition = sec_def , reference = sec_ref )
226
+ subsec_ba = Section (name = "subsecA" , type = sec_type ,
227
+ definition = sec_def , reference = sec_ref )
228
+ subsec_bb = Section (name = "subsecB" , type = sec_type ,
229
+ definition = sec_def , reference = sec_ref )
230
+
231
+ doc_a .extend ([subsec_aa , subsec_ab ])
232
+ doc_b .extend ([subsec_ba , subsec_bb ])
233
+
234
+ self .assertEqual (doc_a , doc_b )
235
+ self .assertEqual (doc_a .sections , doc_b .sections )
236
+
237
+ doc_b .sections [0 ].name = "newSubsecA"
238
+ self .assertNotEqual (doc_a , doc_b )
239
+ self .assertNotEqual (doc_a .sections , doc_b .sections )
240
+
241
+ doc_b .sections [0 ].name = "subsecA"
242
+
243
+ # Test inequality with different number of children
244
+ doc_b .remove (doc_b .sections [1 ])
245
+ self .assertNotEqual (doc_a , doc_b )
246
+ self .assertNotEqual (doc_a .sections , doc_b .sections )
247
+
248
+ # Test equality with subsection of different entities
249
+ # with same content and different children order
250
+ doc_b .remove (doc_b .sections [0 ])
251
+ doc_b .extend ([subsec_bb , subsec_ba ])
252
+
253
+ self .assertEqual (doc_a , doc_b )
254
+ self .assertEqual (doc_a .sections , doc_b .sections )
255
+
256
+ doc_b .sections [0 ].name = "newSubsecB"
257
+ self .assertNotEqual (doc_a , doc_b )
258
+ self .assertNotEqual (doc_a .sections , doc_b .sections )
259
+
260
+ doc_b .sections [0 ].name = "subsecB"
261
+
262
+ # Test section equality with properties
263
+
264
+ # Test equality with properties of different entities
265
+ # with same content and same children order
266
+ prop_aa = Property (name = "propA" , definition = "propDef" )
267
+ prop_ab = Property (name = "propB" , definition = "propDef" )
268
+ prop_ba = Property (name = "propA" , definition = "propDef" )
269
+ prop_bb = Property (name = "propB" , definition = "propDef" )
270
+
271
+ doc_a .sections ["subsecA" ].extend ([prop_aa , prop_ab ])
272
+ doc_b .sections ["subsecA" ].extend ([prop_ba , prop_bb ])
273
+
274
+ self .assertEqual (doc_a , doc_b )
275
+
276
+ doc_b .sections ["subsecA" ].properties [0 ].name = "newPropA"
277
+ self .assertNotEqual (doc_a , doc_b )
278
+
279
+ doc_b .sections ["subsecA" ].properties [0 ].name = "propA"
280
+
281
+ # Test inequality with different number of children
282
+ doc_b .sections ["subsecA" ].remove (doc_b .sections ["subsecA" ].properties [1 ])
283
+ self .assertNotEqual (doc_a , doc_b )
284
+
285
+ # Test equality with properties of different entities
286
+ # with same content and different children order
287
+ doc_b .sections ["subsecA" ].remove (doc_b .sections ["subsecA" ].properties [0 ])
288
+ doc_b .sections ["subsecA" ].extend ([prop_bb , prop_ba ])
289
+
290
+ self .assertEqual (doc_a , doc_b )
291
+
292
+ doc_b .sections ["subsecA" ].properties [0 ].name = "newPropB"
293
+ self .assertNotEqual (doc_a , doc_b )
0 commit comments