class TestFilterDefinitionCollection(lsst.utils.tests.TestCase): def setUp(self): self.filters1 = FilterDefinitionCollection( FilterDefinition(physical_filter='abc', lambdaEff=123), FilterDefinition(physical_filter='def', band='d', doc="This is a test filter.", lambdaEff=456)) self.filters2 = FilterDefinitionCollection( FilterDefinition(physical_filter='abc', lambdaEff=321), FilterDefinition(physical_filter='def', band='dd', lambdaEff=654)) FilterDefinitionCollection.reset() def test_singleton(self): self.filters1.defineFilters() self.assertEqual( lsst.afw.image.Filter('abc').getFilterProperty().getLambdaEff(), 123) self.assertEqual( lsst.afw.image.Filter('def').getFilterProperty().getLambdaEff(), 456) self.filters1.defineFilters() # this should not change anything self.assertEqual( lsst.afw.image.Filter('abc').getFilterProperty().getLambdaEff(), 123) self.assertEqual( lsst.afw.image.Filter('def').getFilterProperty().getLambdaEff(), 456) with self.assertRaises(RuntimeError): self.filters2.defineFilters() # the defined filters should be unchanged self.assertEqual( lsst.afw.image.Filter('abc').getFilterProperty().getLambdaEff(), 123) self.assertEqual( lsst.afw.image.Filter('def').getFilterProperty().getLambdaEff(), 456) def test_reset(self): self.filters1.defineFilters() with self.assertRaises(RuntimeError): self.filters2.defineFilters() self.filters1.reset() # The new filters can be defiend and should replace the old ones. self.filters2.defineFilters() self.assertEqual( lsst.afw.image.Filter('abc').getFilterProperty().getLambdaEff(), 321) self.assertEqual( lsst.afw.image.Filter('def').getFilterProperty().getLambdaEff(), 654) def test_findAll(self): self.assertEqual(set(self.filters1.findAll('r')), set()) matches = self.filters1.findAll('abc') self.assertEqual(len(matches), 1) match = list(matches)[0] self.assertEqual(match.physical_filter, 'abc') def test_physical_to_band(self): """Test that the physical_to_band dict returns expected values. """ self.assertIsNone(self.filters1.physical_to_band['abc']) self.assertEqual(self.filters1.physical_to_band['def'], 'd') self.assertIsNone(self.filters2.physical_to_band['abc']) self.assertEqual(self.filters2.physical_to_band['def'], 'dd')
class TestFilterDefinitionCollection(lsst.utils.tests.TestCase): def setUp(self): self.filters1 = FilterDefinitionCollection( FilterDefinition(physical_filter='abc', lambdaEff=123), FilterDefinition(physical_filter='def', lambdaEff=456)) self.filters2 = FilterDefinitionCollection( FilterDefinition(physical_filter='abc', lambdaEff=321), FilterDefinition(physical_filter='def', lambdaEff=654)) FilterDefinitionCollection.reset() def test_singleton(self): self.filters1.defineFilters() self.assertEqual( lsst.afw.image.Filter('abc').getFilterProperty().getLambdaEff(), 123) self.assertEqual( lsst.afw.image.Filter('def').getFilterProperty().getLambdaEff(), 456) self.filters1.defineFilters() # this should not change anything self.assertEqual( lsst.afw.image.Filter('abc').getFilterProperty().getLambdaEff(), 123) self.assertEqual( lsst.afw.image.Filter('def').getFilterProperty().getLambdaEff(), 456) with self.assertRaises(RuntimeError): self.filters2.defineFilters() # the defined filters should be unchanged self.assertEqual( lsst.afw.image.Filter('abc').getFilterProperty().getLambdaEff(), 123) self.assertEqual( lsst.afw.image.Filter('def').getFilterProperty().getLambdaEff(), 456) def test_reset(self): self.filters1.defineFilters() with self.assertRaises(RuntimeError): self.filters2.defineFilters() self.filters1.reset() # The new filters can be defiend and should replace the old ones. self.filters2.defineFilters() self.assertEqual( lsst.afw.image.Filter('abc').getFilterProperty().getLambdaEff(), 321) self.assertEqual( lsst.afw.image.Filter('def').getFilterProperty().getLambdaEff(), 654)