Skip to content

Commit

Permalink
Add test and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcraig committed Feb 4, 2024
1 parent de56a31 commit aee5d1e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion stellarphot/settings/tests/test_astropy_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class _QuantityModel(BaseModel):
[
Unit("m"),
1,
4.0,
"meter",
"parsec / fortnight",
"",
Expand All @@ -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",
Expand Down Expand Up @@ -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:
Expand All @@ -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")

0 comments on commit aee5d1e

Please sign in to comment.