Coverage for tests/test_commonMetrics.py : 32%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# This file is part of verify. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (https://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>.
def run(self): time.sleep(self.taskLength)
def makeTask(cls): return TimingMetricTask(config=cls._standardConfig())
def _standardConfig(): config = TimingMetricTask.ConfigClass() config.metadata.name = DummyTask._DefaultName + "_metadata" config.target = DummyTask._DefaultName + ".run" config.metric = "verify.DummyTime" return config
"""Create a dummy instance of `FringeTask` so that test cases can run and measure it. """ super().setUp() self.config = TimingMetricTestSuite._standardConfig()
self.scienceTask = DummyTask() self.scienceTask.run()
result = self.task.run([self.scienceTask.getFullMetadata()]) meas = result.measurement
self.assertIsInstance(meas, Measurement) self.assertEqual(meas.metric_name, Name(metric=self.config.metric)) self.assertGreater(meas.quantity, 0.0 * u.second) self.assertLess(meas.quantity, 2 * DummyTask.taskLength * u.second)
self.config.metric = "foo.bar.FooBarTime" task = TimingMetricTask(config=self.config) with self.assertRaises(TypeError): task.run([self.scienceTask.getFullMetadata()])
result = self.task.run([None]) meas = result.measurement self.assertIsNone(meas)
result = self.task.run([]) meas = result.measurement self.assertIsNone(meas)
self.config.target = DummyTask._DefaultName + ".runDataRef" task = TimingMetricTask(config=self.config) result = task.run([self.scienceTask.getFullMetadata()]) meas = result.measurement self.assertIsNone(meas)
metadata = self.scienceTask.getFullMetadata() startKeys = [key for key in metadata.paramNames(topLevelOnly=False) if "StartCpuTime" in key] for key in startKeys: metadata.remove(key)
task = TimingMetricTask(config=self.config) with self.assertRaises(MetricComputationError): task.run([metadata])
metadata = self.scienceTask.getFullMetadata() endKeys = [key for key in metadata.paramNames(topLevelOnly=False) if "EndCpuTime" in key] for key in endKeys: metadata.set(key, str(metadata.getAsDouble(key)))
task = TimingMetricTask(config=self.config) with self.assertRaises(MetricComputationError): task.run([metadata])
types = TimingMetricTask.getInputDatasetTypes(self.config) self.assertSetEqual(set(types.keys()), {"metadata"}) expected = DummyTask._DefaultName + "_metadata" self.assertEqual(types["metadata"], expected)
metadata = self.scienceTask.getFullMetadata() inputData = {"metadata": [metadata]} inputDataIds = {"metadata": [{"visit": 42, "ccd": 1}]} outputDataId = {"measurement": {"visit": 42, "ccd": 1}} measDirect = self.task.run([metadata]).measurement measIndirect = self.task.adaptArgsAndRun( inputData, inputDataIds, outputDataId).measurement
assert_quantity_allclose(measIndirect.quantity, measDirect.quantity)
metadata = self.scienceTask.getFullMetadata() nCcds = 3 inputData = {"metadata": [metadata] * nCcds} inputDataIds = {"metadata": [{"visit": 42, "ccd": x} for x in range(nCcds)]} outputDataId = {"measurement": {"visit": 42}} measDirect = self.task.run([metadata]).measurement measMany = self.task.adaptArgsAndRun( inputData, inputDataIds, outputDataId).measurement
assert_quantity_allclose(measMany.quantity, nCcds * measDirect.quantity)
self.assertEqual(TimingMetricTask.getOutputMetricName(self.config), Name(self.config.metric))
# Hack around unittest's hacky test setup system
lsst.utils.tests.init()
lsst.utils.tests.init() unittest.main() |