From aee5d1eec9af4965cff04f6b85390195d3631aa9 Mon Sep 17 00:00:00 2001 From: Matt Craig Date: Sun, 4 Feb 2024 14:32:55 -0600 Subject: [PATCH] Add test and test cases --- stellarphot/settings/tests/test_astropy_pydantic.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/stellarphot/settings/tests/test_astropy_pydantic.py b/stellarphot/settings/tests/test_astropy_pydantic.py index f8a07ff6..3bb65698 100644 --- a/stellarphot/settings/tests/test_astropy_pydantic.py +++ b/stellarphot/settings/tests/test_astropy_pydantic.py @@ -33,6 +33,7 @@ class _QuantityModel(BaseModel): [ Unit("m"), 1, + 4.0, "meter", "parsec / fortnight", "", @@ -50,7 +51,9 @@ def test_unit_initialization(init): "init", [ -2 * Unit("m"), + -2.0 * Unit("m"), 1, + 1.0, "5 meter", "13 parsec / fortnight", "42", @@ -229,7 +232,6 @@ class Model(BaseModel): assert model.model_dump()["value"] == serialize_astropy_type(val) # We should be able to create a new model from the dumped json... - # ...but we can't because we apparently aren't serializing right. model2 = Model.model_validate_json(model.model_dump_json()) if klass is SkyCoord: @@ -240,3 +242,11 @@ class Model(BaseModel): ) else: assert model2.value == model.value + + +def test_time_pydantic_invalid_value(): + class Model(BaseModel): + value: Annotated[Time, AstropyValidator] + + with pytest.raises(ValidationError, match="Input should be an instance of Time"): + Model(value="not a time")