Coverage for tests/test_serialization_backends.py: 100%
41 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-04 17:17 +0000
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-04 17:17 +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 os
15import tempfile
16import unittest
18import numpy as np
20from lsst.images import Box, Image
21from lsst.images import fits as images_fits
22from lsst.images.serialization import Backend, backend_for_path
25class BackendForPathTestCase(unittest.TestCase):
26 """Tests for suffix -> backend resolution."""
28 def test_fits(self) -> None:
29 from lsst.images.fits import FitsInputArchive
31 b = backend_for_path("a/b/c.fits")
32 self.assertIsInstance(b, Backend)
33 self.assertEqual(b.name, "fits")
34 self.assertIs(b.input_archive, FitsInputArchive)
35 self.assertTrue(callable(b.write))
37 def test_fits_gz(self) -> None:
38 self.assertEqual(backend_for_path("c.fits.gz").name, "fits")
39 self.assertEqual(backend_for_path("file://a/b/c.fits.gz?param=2").name, "fits")
41 def test_json(self) -> None:
42 from lsst.images.json import JsonInputArchive
44 b = backend_for_path("c.json")
45 self.assertEqual(b.name, "json")
46 self.assertIs(b.input_archive, JsonInputArchive)
48 def test_ndf(self) -> None:
49 self.assertEqual(backend_for_path("c.sdf").name, "ndf")
50 self.assertEqual(backend_for_path("c.h5").name, "ndf")
52 def test_unknown(self) -> None:
53 with self.assertRaises(ValueError) as cm:
54 backend_for_path("c.txt")
55 self.assertIn(".fits", str(cm.exception))
58class MinifyDispatchTestCase(unittest.TestCase):
59 """minify resolves backend and schema via the shared APIs."""
61 def test_minify_unsupported_schema_uses_shared_dispatch(self) -> None:
62 from lsst.images.tests._minify_for_fixtures import minify
64 tmp = tempfile.mkdtemp()
65 src = os.path.join(tmp, "plain.fits")
66 out = os.path.join(tmp, "plain.json")
67 images_fits.write(Image(np.zeros((4, 4), dtype=np.float32), bbox=Box.factory[0:4, 0:4]), src)
68 # Reaching the "no subsetter" error proves backend_for_path and
69 # get_basic_info ran and detected schema_name "image".
70 with self.assertRaises(NotImplementedError) as cm:
71 minify(src, out)
72 self.assertIn("image", str(cm.exception))
75if __name__ == "__main__":
76 unittest.main()