Coverage for tests/test_dataIdContainer.py: 55%
36 statements
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 02:42 -0700
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 02:42 -0700
1# This file is part of pipe_base.
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# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22"""Tests of the DataIdContainer class."""
24import unittest
25import unittest.mock
27try:
28 import lsst.daf.persistence as dafPersistence
29except ImportError:
30 dafPersistence = None
31try:
32 from lsst.pipe.base import DataIdContainer
33except ImportError:
34 DataIdContainer = None
35import lsst.utils.tests
38@unittest.skipIf(DataIdContainer is None or dafPersistence is None, "Gen2 infrastructure is not available")
39class DataIdContainerTestCase(lsst.utils.tests.TestCase):
40 def setUp(self):
41 self.container = DataIdContainer()
42 self.butler = unittest.mock.MagicMock(spec=dafPersistence.Butler)
44 def test_castDataIdsNoneDatasetType(self):
45 """Raise RuntimeError if we haven't set container.datasetType."""
46 with self.assertRaises(RuntimeError):
47 self.container.castDataIds(self.butler)
49 def test_makeDataRefListNoneDatasetType(self):
50 """Raise RuntimeError if we haven't set container.datasetType."""
51 with self.assertRaises(RuntimeError):
52 self.container.makeDataRefList(self.butler)
54 def test_castDataIdsRaiseKeyError(self):
55 """Test that castDataIds re-raises a butler.getKeys() exception."""
56 self.container.setDatasetType("nonsense!")
57 self.butler.getKeys.side_effect = KeyError
58 with self.assertRaises(KeyError) as cm:
59 self.container.castDataIds(self.butler)
60 self.assertIsInstance(cm.exception.__cause__, KeyError)
63class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
64 pass
67def setup_module(module):
68 lsst.utils.tests.init()
71if __name__ == "__main__": 71 ↛ 72line 71 didn't jump to line 72, because the condition on line 71 was never true
72 lsst.utils.tests.init()
73 unittest.main()