Skip to content

Commit 7c3d668

Browse files
Merge branch 'main' into schemaview_add_delete_get_entity
2 parents 7e53203 + 5af475d commit 7c3d668

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/test_utils/test_schemaview.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,56 @@ def test_metamodel_in_schemaview() -> None:
726726
assert exp_slot_uri is not None
727727

728728

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

739791

740792
CREATURE_EXPECTED = {
@@ -1109,6 +1161,12 @@ def test_all_classes_ordered_by(sv_ordering_tests: SchemaView, ordered_by: str)
11091161
assert list(sv_ordering_tests.all_classes(ordered_by=ordered_by).keys()) == ORDERING_TESTS[ordered_by]
11101162

11111163

1164+
def test_all_classes_ordered_by_error(sv_ordering_tests: SchemaView) -> None:
1165+
"""Test the ordered_by method throws an error when appropriate."""
1166+
with pytest.raises(ValueError, match="ordered_by must be in OrderedBy or None, got whatever"):
1167+
sv_ordering_tests.all_classes(ordered_by="whatever")
1168+
1169+
11121170
def test_all_classes_class_induced_slots(schema_view_with_imports: SchemaView) -> None:
11131171
"""Test all_classes and class_induced_slots."""
11141172
view = schema_view_with_imports

0 commit comments

Comments
 (0)