Coverage for tests / test_json_schema.py: 36%
21 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-23 08:27 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-23 08:27 +0000
1# This file is part of lsst-images.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# Use of this source code is governed by a 3-clause BSD-style
10# license that can be found in the LICENSE file.
12from __future__ import annotations
14import unittest
15import warnings
17from lsst.images import VisitImageSerializationModel
18from lsst.images.cells import CellCoaddSerializationModel
21class JsonSchemaTestCase(unittest.TestCase):
22 """Test that pydantic JSON Schema generation succeeds without warnings
23 for the complex serialization models that compose many helpers from
24 `_asdf_utils` (Quantity, Unit, Time, InlineArray) and `_geom` (Box,
25 Interval).
26 """
28 def _check(self, model: type, mode: str) -> None:
29 with warnings.catch_warnings():
30 # Any warning emitted during schema generation (e.g.
31 # PydanticJsonSchemaWarning for non-serializable defaults) is
32 # treated as a test failure.
33 warnings.simplefilter("error")
34 schema = model.model_json_schema(mode=mode)
35 self.assertIsInstance(schema, dict)
36 self.assertEqual(schema.get("type"), "object")
37 self.assertIn("properties", schema)
39 def test_visit_image(self) -> None:
40 for mode in ("validation", "serialization"):
41 with self.subTest(mode=mode):
42 self._check(VisitImageSerializationModel, mode)
44 def test_cell_coadd(self) -> None:
45 for mode in ("validation", "serialization"):
46 with self.subTest(mode=mode):
47 self._check(CellCoaddSerializationModel, mode)
50if __name__ == "__main__":
51 unittest.main()