diff --git a/tests/test_datamodel.py b/tests/test_datamodel.py index 4db5369b..4ab2a6cf 100644 --- a/tests/test_datamodel.py +++ b/tests/test_datamodel.py @@ -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."""