Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions tests/test_utils/test_schemaview.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,56 @@ def test_metamodel_in_schemaview() -> None:
assert exp_slot_uri is not None


def test_eq_true_false() -> None:
"""Test that __eq__ returns True or False appropriately."""
schema = SchemaDefinition(id="test-schema", name="TestSchema")
view = SchemaView(schema)

# Create a new SchemaView with the same schema
view_copy = SchemaView(schema)
assert view.schema.id == view_copy.schema.id
assert view.modifications == view_copy.modifications
# the new schema will have a unique UUID
assert view.uuid != view_copy.uuid
# the two schemas will therefore not be equal
assert view != view_copy

# copy over the uuid and modifications from the original schema
view_copy.uuid = view.uuid
view_copy.modifications = view.modifications

# the schemas are now equal. Hurrah!
assert view == view_copy

# alter the modification count
view_copy.modifications += 1
assert view != view_copy

# Create a new SchemaView with a different schema
diff_schema = SchemaDefinition(id="different-schema", name="DifferentSchema")
diff_view = SchemaView(diff_schema)
assert view != diff_view

# copy over the UUID and modifications from the original schema
diff_view.uuid = view.uuid
diff_view.modifications = view.modifications

# schemas have different IDs so will still be different
assert diff_view != view


def test_eq_not_implemented() -> None:
"""Test that __eq__ returns NotImplemented for non-SchemaView objects."""
schema = SchemaDefinition(id="test-schema", name="TestSchema")
view = SchemaView(schema)

# Compare with a string
assert view.__eq__("not-a-schemaview") is NotImplemented

# Compare with a different object
assert view.__eq__(object()) is NotImplemented


def test_in_schema(schema_view_with_imports: SchemaView) -> None:
"""Test the in_schema function for determining the source schema of a class or slot."""
view = schema_view_with_imports
Expand All @@ -734,6 +784,8 @@ def test_in_schema(schema_view_with_imports: SchemaView) -> None:
assert view.in_schema(SlotDefinitionName("name")) == "core"
assert view.in_schema(SlotDefinitionName(ACTIVITY)) == "core"
assert view.in_schema(SlotDefinitionName("string")) == "types"
with pytest.raises(ValueError, match="Element fake_element not in any schema"):
view.in_schema("fake_element")


CREATURE_EXPECTED = {
Expand Down Expand Up @@ -1108,6 +1160,12 @@ def test_all_classes_ordered_by(sv_ordering_tests: SchemaView, ordered_by: str)
assert list(sv_ordering_tests.all_classes(ordered_by=ordered_by).keys()) == ORDERING_TESTS[ordered_by]


def test_all_classes_ordered_by_error(sv_ordering_tests: SchemaView) -> None:
"""Test the ordered_by method throws an error when appropriate."""
with pytest.raises(ValueError, match="ordered_by must be in OrderedBy or None, got whatever"):
sv_ordering_tests.all_classes(ordered_by="whatever")


def test_all_classes_class_induced_slots(schema_view_with_imports: SchemaView) -> None:
"""Test all_classes and class_induced_slots."""
view = schema_view_with_imports
Expand Down
Loading