Coverage for tests/test_serialization_backends.py: 40%
40 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-06 08:37 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-06 08:37 +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")
40 def test_json(self) -> None:
41 from lsst.images.json import JsonInputArchive
43 b = backend_for_path("c.json")
44 self.assertEqual(b.name, "json")
45 self.assertIs(b.input_archive, JsonInputArchive)
47 def test_ndf(self) -> None:
48 self.assertEqual(backend_for_path("c.sdf").name, "ndf")
49 self.assertEqual(backend_for_path("c.ndf").name, "ndf")
51 def test_unknown(self) -> None:
52 with self.assertRaises(ValueError) as cm:
53 backend_for_path("c.txt")
54 self.assertIn(".fits", str(cm.exception))
57class MinifyDispatchTestCase(unittest.TestCase):
58 """minify resolves backend and schema via the shared APIs."""
60 def test_minify_unsupported_schema_uses_shared_dispatch(self) -> None:
61 from lsst.images.tests._minify_for_fixtures import minify
63 tmp = tempfile.mkdtemp()
64 src = os.path.join(tmp, "plain.fits")
65 out = os.path.join(tmp, "plain.json")
66 images_fits.write(Image(np.zeros((4, 4), dtype=np.float32), bbox=Box.factory[0:4, 0:4]), src)
67 # Reaching the "no subsetter" error proves backend_for_path and
68 # get_basic_info ran and detected schema_name "image".
69 with self.assertRaises(NotImplementedError) as cm:
70 minify(src, out)
71 self.assertIn("image", str(cm.exception))
74if __name__ == "__main__":
75 unittest.main()