Coverage for python / lsst / images / tests / _formatter.py: 55%
11 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-21 08:52 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-21 08:52 +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
14__all__ = ("make_test_formatter",)
16from typing import Any
18from lsst.daf.butler import (
19 DataCoordinate,
20 DatasetRef,
21 DatasetType,
22 DimensionUniverse,
23 FileDescriptor,
24 FormatterV2,
25 Location,
26 StorageClass,
27)
29_UNIVERSE = DimensionUniverse()
32def make_test_formatter[F: FormatterV2](
33 formatter_cls: type[F],
34 pytype: type,
35 *,
36 location: str = "/tmp/test.fits",
37 parameters: dict[str, Any] | None = None,
38 write_parameters: dict[str, Any] | None = None,
39) -> F:
40 """Construct a butler formatter wired to a minimal
41 `~lsst.daf.butler.DatasetRef`.
43 Intended for unit tests that exercise formatter logic without a full
44 butler. ``pytype`` is wrapped in a fresh `~lsst.daf.butler.StorageClass`
45 whose name is taken from the class.
46 """
47 storage_class = StorageClass(name=pytype.__name__, pytype=pytype)
48 file_descriptor = FileDescriptor(Location(None, location), storage_class, parameters=parameters)
49 dataset_type = DatasetType(
50 pytype.__name__,
51 dimensions=_UNIVERSE.empty,
52 storageClass=storage_class,
53 )
54 ref = DatasetRef(dataset_type, DataCoordinate.make_empty(_UNIVERSE), run="test")
55 return formatter_cls(
56 file_descriptor=file_descriptor,
57 ref=ref,
58 write_parameters=write_parameters,
59 )