Coverage for tests / test_ndf_common.py: 48%
21 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-23 08:25 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-23 08:25 +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
16try:
17 from lsst.images.ndf._common import NdfPointerModel, archive_path_to_hdf5_path
19 HAVE_H5PY = True
20except ImportError:
21 HAVE_H5PY = False
24@unittest.skipUnless(HAVE_H5PY, "h5py is not installed")
25class NdfPointerModelTestCase(unittest.TestCase):
26 """Tests for `NdfPointerModel` and `archive_path_to_hdf5_path`."""
28 def test_round_trips_through_json(self):
29 original = NdfPointerModel(path="/MORE/LSST/PSF")
30 json_bytes = original.model_dump_json().encode()
31 recovered = NdfPointerModel.model_validate_json(json_bytes)
32 self.assertEqual(recovered, original)
34 def test_archive_path_to_hdf5_path(self):
35 self.assertEqual(archive_path_to_hdf5_path(""), "/MORE/LSST/JSON")
36 self.assertEqual(archive_path_to_hdf5_path("/psf"), "/MORE/LSST/PSF")
37 self.assertEqual(archive_path_to_hdf5_path("/psf/coefficients"), "/MORE/LSST/PSF/COEFFICIENTS")
39 def test_archive_path_to_hdf5_path_rejects_long_components(self):
40 with self.assertRaisesRegex(ValueError, "16-character HDS limit"):
41 archive_path_to_hdf5_path("/psf/this_component_is_too_long")