Coverage for tests/test_config.py: 59%
52 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-10 02:03 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-10 02:03 -0800
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# (http://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 <http://www.gnu.org/licenses/>.
22"""Simple unit test for ResourceConfig.
23"""
25import unittest
27import lsst.pex.config as pexConfig
28import lsst.pipe.base as pipeBase
29import lsst.utils.tests
30from lsst.daf.butler import StorageClass, StorageClassFactory
33class NullConnections(pipeBase.PipelineTaskConnections, dimensions=()):
34 pass
37class NoResourceTask(pipeBase.PipelineTask):
38 _DefaultName = "no_resource_task"
39 ConfigClass = pipeBase.PipelineTaskConfig
42class OneConfig(pipeBase.PipelineTaskConfig, pipelineConnections=NullConnections):
43 resources = pexConfig.ConfigField(dtype=pipeBase.ResourceConfig, doc="Resource configuration")
46class OneTask(pipeBase.PipelineTask):
47 _DefaultName = "one_task"
48 ConfigClass = OneConfig
51class TwoConfig(pipeBase.PipelineTaskConfig, pipelineConnections=NullConnections):
52 resources = pexConfig.ConfigField(dtype=pipeBase.ResourceConfig, doc="Resource configuration")
54 def setDefaults(self):
55 self.resources.minMemoryMB = 1024
56 self.resources.minNumCores = 32
59class TwoTask(pipeBase.PipelineTask):
60 _DefaultName = "two_task"
61 ConfigClass = TwoConfig
64class TaskTestCase(unittest.TestCase):
65 """A test case for Task"""
67 @classmethod
68 def setUpClass(cls):
69 for name in ("SCA", "SCB", "SCC", "SCX", "SCY"):
70 StorageClassFactory().registerStorageClass(StorageClass(name))
72 def testNoResource(self):
73 """Test for a task without resource config"""
74 task = NoResourceTask()
75 res_config = task.getResourceConfig()
76 self.assertIs(res_config, None)
78 def testOneResource(self):
79 """Test for a task with resource config"""
80 task = OneTask()
81 res_config = task.getResourceConfig()
82 self.assertIsNot(res_config, None)
83 self.assertIs(res_config.minMemoryMB, None)
84 self.assertEqual(res_config.minNumCores, 1)
86 def testTwoResource(self):
87 """Test for a task with resource config and special defaults"""
88 task = TwoTask()
89 res_config = task.getResourceConfig()
90 self.assertIsNot(res_config, None)
91 self.assertEqual(res_config.minMemoryMB, 1024)
92 self.assertEqual(res_config.minNumCores, 32)
95class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
96 pass
99def setup_module(module):
100 lsst.utils.tests.init()
103if __name__ == "__main__": 103 ↛ 104line 103 didn't jump to line 104, because the condition on line 103 was never true
104 lsst.utils.tests.init()
105 unittest.main()