@@ -739,6 +739,106 @@ def test_merge(self):
739739 self .assertEqual (destination .sections ["lvl" ].properties [0 ].value ,
740740 d_subprop_one .value )
741741
742+ def test_comparison (self ):
743+ sec_name = "sec name"
744+ sec_type = "sec type"
745+ sec_def = "an odml test section"
746+ sec_ref = "from over there"
747+
748+ sec_a = Section (name = sec_name , type = sec_type ,
749+ definition = sec_def , reference = sec_ref )
750+ sec_b = Section (name = sec_name , type = sec_type ,
751+ definition = sec_def , reference = sec_ref )
752+
753+ self .assertEqual (sec_a , sec_b )
754+
755+ sec_b .name = "newSecName"
756+ self .assertNotEqual (sec_a , sec_b )
757+
758+ sec_b .name = sec_name
759+
760+ # Test section equality with subsections
761+
762+ # Test equality with subsection of different entities
763+ # with same content and same children order
764+ subsec_aa = Section (name = "subsecA" , type = sec_type ,
765+ definition = sec_def , reference = sec_ref )
766+ subsec_ab = Section (name = "subsecB" , type = sec_type ,
767+ definition = sec_def , reference = sec_ref )
768+ subsec_ba = Section (name = "subsecA" , type = sec_type ,
769+ definition = sec_def , reference = sec_ref )
770+ subsec_bb = Section (name = "subsecB" , type = sec_type ,
771+ definition = sec_def , reference = sec_ref )
772+
773+ sec_a .extend ([subsec_aa , subsec_ab ])
774+ sec_b .extend ([subsec_ba , subsec_bb ])
775+
776+ self .assertEqual (sec_a , sec_b )
777+ self .assertEqual (sec_a .sections , sec_b .sections )
778+
779+ sec_b .sections [0 ].name = "newSubsecA"
780+ self .assertNotEqual (sec_a , sec_b )
781+ self .assertNotEqual (sec_a .sections , sec_b .sections )
782+
783+ sec_b .sections [0 ].name = "subsecA"
784+
785+ # Test inequality with different number of children
786+ sec_b .remove (sec_b .sections [1 ])
787+ self .assertNotEqual (sec_a , sec_b )
788+ self .assertNotEqual (sec_a .sections , sec_b .sections )
789+
790+ # Test equality with subsection of different entities
791+ # with same content and different children order
792+ sec_b .remove (sec_b .sections [0 ])
793+ sec_b .extend ([subsec_bb , subsec_ba ])
794+
795+ self .assertEqual (sec_a , sec_b )
796+ self .assertEqual (sec_a .sections , sec_b .sections )
797+
798+ sec_b .sections [0 ].name = "newSubsecB"
799+ self .assertNotEqual (sec_a , sec_b )
800+ self .assertNotEqual (sec_a .sections , sec_b .sections )
801+
802+ sec_b .sections [0 ].name = "subsecB"
803+
804+ # Test section equality with properties
805+
806+ # Test equality with properties of different entities
807+ # with same content and same children order
808+ prop_aa = Property (name = "propA" , definition = "propDef" )
809+ prop_ab = Property (name = "propB" , definition = "propDef" )
810+ prop_ba = Property (name = "propA" , definition = "propDef" )
811+ prop_bb = Property (name = "propB" , definition = "propDef" )
812+
813+ sec_a .extend ([prop_aa , prop_ab ])
814+ sec_b .extend ([prop_ba , prop_bb ])
815+
816+ self .assertEqual (sec_a , sec_b )
817+ self .assertEqual (sec_a .properties , sec_b .properties )
818+
819+ sec_b .properties [0 ].name = "newPropA"
820+ self .assertNotEqual (sec_a , sec_b )
821+ self .assertNotEqual (sec_a .properties , sec_b .properties )
822+
823+ sec_b .properties [0 ].name = "propA"
824+
825+ # Test inequality with different number of children
826+ sec_b .remove (sec_b .properties [1 ])
827+ self .assertNotEqual (sec_a , sec_b )
828+ self .assertNotEqual (sec_a .properties , sec_b .properties )
829+
830+ # Test equality with properties of different entities
831+ # with same content and different children order
832+ sec_b .remove (sec_b .properties [0 ])
833+ sec_b .extend ([prop_bb , prop_ba ])
834+
835+ self .assertEqual (sec_a , sec_b )
836+ self .assertEqual (sec_a .properties , sec_b .properties )
837+
838+ sec_b .properties [0 ].name = "newPropB"
839+ self .assertNotEqual (sec_a , sec_b )
840+ self .assertNotEqual (sec_a .properties , sec_b .properties )
841+
742842 def test_link (self ):
743843 pass
744844
0 commit comments