22 """Helpers for writing tests against subclassses of Instrument.
24 These are not tests themselves, but can be subclassed (plus unittest.TestCase)
25 to get a functional test of an Instrument.
33 from lsst.daf.butler
import Registry
34 from lsst.daf.butler
import ButlerConfig
37 @dataclasses.dataclass
39 """Values to test against in sublcasses of `InstrumentTests`.
43 """The name of the Camera this instrument describes."""
46 """The number of detectors in the Camera."""
48 firstDetectorName: str
49 """The name of the first detector in the Camera."""
51 physical_filters: {str}
52 """A subset of the physical filters should be registered."""
56 """Tests of sublcasses of Instrument.
58 TestCase subclasses must derive from this, then `TestCase`, and override
59 ``data`` and ``instrument``.
63 """`InstrumentTestData` containing the values to test against."""
66 """The `~lsst.obs.base.Instrument` to be tested."""
72 """Test that getCamera() returns a reasonable Camera definition.
75 self.assertEqual(camera.getName(), self.
instrument.getName())
76 self.assertEqual(len(camera), self.
data.nDetectors)
77 self.assertEqual(
next(
iter(camera)).getName(), self.
data.firstDetectorName)
80 """Test that register() sets appropriate Dimensions.
82 registry = Registry.fromConfig(ButlerConfig())
84 self.assertEqual(
list(registry.queryDimensions([
"instrument"])), [])
85 self.assertEqual(
list(registry.queryDimensions([
"detector"])), [])
86 self.assertEqual(
list(registry.queryDimensions([
"physical_filter"])), [])
90 instrumentDataIds =
list(registry.queryDimensions([
"instrument"]))
91 self.assertEqual(len(instrumentDataIds), 1)
92 instrumentNames = {dataId[
"instrument"]
for dataId
in instrumentDataIds}
93 self.assertEqual(instrumentNames, {self.
data.name})
94 detectorDataIds =
list(registry.queryDimensions([
"detector"]))
95 self.assertEqual(len(detectorDataIds), self.
data.nDetectors)
96 detectorNames = {dataId.records[
"detector"].full_name
for dataId
in detectorDataIds}
97 self.assertIn(self.
data.firstDetectorName, detectorNames)
98 physicalFilterDataIds =
list(registry.queryDimensions([
"physical_filter"]))
99 filterNames = {dataId[
'physical_filter']
for dataId
in physicalFilterDataIds}
100 self.assertGreaterEqual(filterNames, self.
data.physical_filters)
103 registeredInstrument = Instrument.fromName(self.
instrument.getName(), registry)
107 factory = self.
instrument.makeDataIdTranslatorFactory()
108 self.assertIsInstance(factory, TranslatorFactory)