Coverage for tests/test_config.py: 59%
Shortcuts 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
Shortcuts 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
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.utils.tests
28import lsst.pex.config as pexConfig
29from lsst.daf.butler import StorageClass, StorageClassFactory
30import lsst.pipe.base as pipeBase
33class NullConnections(pipeBase.PipelineTaskConnections,
34 dimensions=()):
35 pass
38class NoResourceTask(pipeBase.PipelineTask):
39 _DefaultName = "no_resource_task"
40 ConfigClass = pipeBase.PipelineTaskConfig
43class OneConfig(pipeBase.PipelineTaskConfig,
44 pipelineConnections=NullConnections):
45 resources = pexConfig.ConfigField(dtype=pipeBase.ResourceConfig,
46 doc="Resource configuration")
49class OneTask(pipeBase.PipelineTask):
50 _DefaultName = "one_task"
51 ConfigClass = OneConfig
54class TwoConfig(pipeBase.PipelineTaskConfig,
55 pipelineConnections=NullConnections):
56 resources = pexConfig.ConfigField(dtype=pipeBase.ResourceConfig,
57 doc="Resource configuration")
59 def setDefaults(self):
60 self.resources.minMemoryMB = 1024
61 self.resources.minNumCores = 32
64class TwoTask(pipeBase.PipelineTask):
65 _DefaultName = "two_task"
66 ConfigClass = TwoConfig
69class TaskTestCase(unittest.TestCase):
70 """A test case for Task
71 """
73 @classmethod
74 def setUpClass(cls):
75 for name in ("SCA", "SCB", "SCC", "SCX", "SCY"):
76 StorageClassFactory().registerStorageClass(StorageClass(name))
78 def testNoResource(self):
79 """Test for a task without resource config
80 """
81 task = NoResourceTask()
82 res_config = task.getResourceConfig()
83 self.assertIs(res_config, None)
85 def testOneResource(self):
86 """Test for a task with resource config
87 """
88 task = OneTask()
89 res_config = task.getResourceConfig()
90 self.assertIsNot(res_config, None)
91 self.assertIs(res_config.minMemoryMB, None)
92 self.assertEqual(res_config.minNumCores, 1)
94 def testTwoResource(self):
95 """Test for a task with resource config and special defaults
96 """
97 task = TwoTask()
98 res_config = task.getResourceConfig()
99 self.assertIsNot(res_config, None)
100 self.assertEqual(res_config.minMemoryMB, 1024)
101 self.assertEqual(res_config.minNumCores, 32)
104class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
105 pass
108def setup_module(module):
109 lsst.utils.tests.init()
112if __name__ == "__main__": 112 ↛ 113line 112 didn't jump to line 113, because the condition on line 112 was never true
113 lsst.utils.tests.init()
114 unittest.main()