Coverage for tests/test_json_schema.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-16 15:24 -0700

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. 

11 

12from __future__ import annotations 

13 

14import warnings 

15 

16import pytest 

17 

18from lsst.images import VisitImageSerializationModel 

19from lsst.images.cells import CellCoaddSerializationModel 

20 

21 

22def _check_json_schema(model: type, mode: str) -> None: 

23 """Assert that ``model.model_json_schema(mode=mode)`` succeeds without 

24 warnings and returns a well-formed object schema dict. 

25 """ 

26 with warnings.catch_warnings(): 

27 # Any warning emitted during schema generation (e.g. 

28 # PydanticJsonSchemaWarning for non-serializable defaults) is 

29 # treated as a test failure. 

30 warnings.simplefilter("error") 

31 schema = model.model_json_schema(mode=mode) 

32 assert isinstance(schema, dict) 

33 assert schema.get("type") == "object" 

34 assert "properties" in schema 

35 

36 

37@pytest.mark.parametrize("mode", ["validation", "serialization"]) 

38def test_visit_image(mode: str) -> None: 

39 """Test that pydantic JSON Schema generation succeeds without warnings 

40 for VisitImageSerializationModel. 

41 """ 

42 _check_json_schema(VisitImageSerializationModel, mode) 

43 

44 

45@pytest.mark.parametrize("mode", ["validation", "serialization"]) 

46def test_cell_coadd(mode: str) -> None: 

47 """Test that pydantic JSON Schema generation succeeds without warnings 

48 for CellCoaddSerializationModel. 

49 """ 

50 _check_json_schema(CellCoaddSerializationModel, mode)