Skip to content

Commit

Permalink
Add test of ID generation
Browse files Browse the repository at this point in the history
Load a schema without IDs and set them, and load the same schema with
ID generation turned off to check that an exception is thrown.
  • Loading branch information
JeremyMcCormick committed Aug 23, 2024
1 parent dc8c03a commit d590889
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/test_datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,19 @@ def test_model_validate(self) -> None:
data = yaml.safe_load(test_yaml)
Schema.model_validate(data)

def test_id_generation(self) -> None:
"""Test ID generation."""
test_path = os.path.join(TESTDIR, "data", "test_id_generation.yaml")
with open(test_path) as test_yaml:
yaml_data = yaml.safe_load(test_yaml)
# Generate IDs for objects in the test schema.
Schema.model_validate(yaml_data, context={"id_generation": True})
with open(test_path) as test_yaml:
yaml_data = yaml.safe_load(test_yaml)
# Test that an error is raised when id generation is disabled.
with self.assertRaises(ValidationError):
Schema.model_validate(yaml_data, context={"id_generation": False})


class SchemaVersionTest(unittest.TestCase):
"""Test the schema version."""
Expand Down

0 comments on commit d590889

Please sign in to comment.