@@ -725,6 +725,56 @@ def test_metamodel_in_schemaview() -> None:
725725 assert exp_slot_uri is not None
726726
727727
728+ def test_eq_true_false () -> None :
729+ """Test that __eq__ returns True or False appropriately."""
730+ schema = SchemaDefinition (id = "test-schema" , name = "TestSchema" )
731+ view = SchemaView (schema )
732+
733+ # Create a new SchemaView with the same schema
734+ view_copy = SchemaView (schema )
735+ assert view .schema .id == view_copy .schema .id
736+ assert view .modifications == view_copy .modifications
737+ # the new schema will have a unique UUID
738+ assert view .uuid != view_copy .uuid
739+ # the two schemas will therefore not be equal
740+ assert view != view_copy
741+
742+ # copy over the uuid and modifications from the original schema
743+ view_copy .uuid = view .uuid
744+ view_copy .modifications = view .modifications
745+
746+ # the schemas are now equal. Hurrah!
747+ assert view == view_copy
748+
749+ # alter the modification count
750+ view_copy .modifications += 1
751+ assert view != view_copy
752+
753+ # Create a new SchemaView with a different schema
754+ diff_schema = SchemaDefinition (id = "different-schema" , name = "DifferentSchema" )
755+ diff_view = SchemaView (diff_schema )
756+ assert view != diff_view
757+
758+ # copy over the UUID and modifications from the original schema
759+ diff_view .uuid = view .uuid
760+ diff_view .modifications = view .modifications
761+
762+ # schemas have different IDs so will still be different
763+ assert diff_view != view
764+
765+
766+ def test_eq_not_implemented () -> None :
767+ """Test that __eq__ returns NotImplemented for non-SchemaView objects."""
768+ schema = SchemaDefinition (id = "test-schema" , name = "TestSchema" )
769+ view = SchemaView (schema )
770+
771+ # Compare with a string
772+ assert view .__eq__ ("not-a-schemaview" ) is NotImplemented
773+
774+ # Compare with a different object
775+ assert view .__eq__ (object ()) is NotImplemented
776+
777+
728778def test_in_schema (schema_view_with_imports : SchemaView ) -> None :
729779 """Test the in_schema function for determining the source schema of a class or slot."""
730780 view = schema_view_with_imports
0 commit comments