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.
32 from lsst.daf.butler
import Registry
33 from lsst.daf.butler
import ButlerConfig
36 @dataclasses.dataclass
38 """Values to test against in sublcasses of `InstrumentTests`.
42 """The name of the Camera this instrument describes."""
45 """The number of detectors in the Camera."""
47 firstDetectorName: str
48 """The name of the first detector in the Camera."""
50 physical_filters: {str}
51 """A subset of the physical filters should be registered."""
55 """Tests of sublcasses of Instrument.
57 TestCase subclasses must derive from this, then `TestCase`, and override
58 ``data`` and ``instrument``.
62 """`InstrumentTestData` containing the values to test against."""
65 """The `~lsst.obs.base.Instrument` to be tested."""
71 """Test that getCamera() returns a reasonable Camera definition.
74 self.assertEqual(camera.getName(), self.
instrument.getName())
75 self.assertEqual(len(camera), self.
data.nDetectors)
76 self.assertEqual(next(iter(camera)).getName(), self.
data.firstDetectorName)
79 """Test that register() sets appropriate Dimensions.
81 registry = Registry.fromConfig(ButlerConfig())
83 self.assertEqual(list(registry.queryDimensions([
"instrument"])), [])
84 self.assertEqual(list(registry.queryDimensions([
"detector"])), [])
85 self.assertEqual(list(registry.queryDimensions([
"physical_filter"])), [])
89 instrumentDataIds = list(registry.queryDimensions([
"instrument"]))
90 self.assertEqual(len(instrumentDataIds), 1)
91 instrumentNames = {dataId[
"instrument"]
for dataId
in instrumentDataIds}
92 self.assertEqual(instrumentNames, {self.
data.name})
93 detectorDataIds = list(registry.queryDimensions([
"detector"]))
94 self.assertEqual(len(detectorDataIds), self.
data.nDetectors)
95 detectorNames = {dataId.records[
"detector"].full_name
for dataId
in detectorDataIds}
96 self.assertIn(self.
data.firstDetectorName, detectorNames)
97 physicalFilterDataIds = list(registry.queryDimensions([
"physical_filter"]))
98 filterNames = {dataId[
'physical_filter']
for dataId
in physicalFilterDataIds}
99 self.assertGreaterEqual(filterNames, self.
data.physical_filters)
102 registeredInstrument = Instrument.fromName(self.
instrument.getName(), registry)
103 self.assertEqual(type(registeredInstrument), type(self.
instrument))