Coverage for tests/test_config.py: 59%

52 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-10-29 02:33 -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# (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/>. 

21 

22"""Simple unit test for ResourceConfig. 

23""" 

24 

25import unittest 

26 

27import lsst.pex.config as pexConfig 

28import lsst.pipe.base as pipeBase 

29import lsst.utils.tests 

30from lsst.daf.butler import StorageClass, StorageClassFactory 

31 

32 

33class NullConnections(pipeBase.PipelineTaskConnections, dimensions=()): 

34 pass 

35 

36 

37class NoResourceTask(pipeBase.PipelineTask): 

38 _DefaultName = "no_resource_task" 

39 ConfigClass = pipeBase.PipelineTaskConfig 

40 

41 

42class OneConfig(pipeBase.PipelineTaskConfig, pipelineConnections=NullConnections): 

43 resources = pexConfig.ConfigField(dtype=pipeBase.ResourceConfig, doc="Resource configuration") 

44 

45 

46class OneTask(pipeBase.PipelineTask): 

47 _DefaultName = "one_task" 

48 ConfigClass = OneConfig 

49 

50 

51class TwoConfig(pipeBase.PipelineTaskConfig, pipelineConnections=NullConnections): 

52 resources = pexConfig.ConfigField(dtype=pipeBase.ResourceConfig, doc="Resource configuration") 

53 

54 def setDefaults(self): 

55 self.resources.minMemoryMB = 1024 

56 self.resources.minNumCores = 32 

57 

58 

59class TwoTask(pipeBase.PipelineTask): 

60 _DefaultName = "two_task" 

61 ConfigClass = TwoConfig 

62 

63 

64class TaskTestCase(unittest.TestCase): 

65 """A test case for Task""" 

66 

67 @classmethod 

68 def setUpClass(cls): 

69 for name in ("SCA", "SCB", "SCC", "SCX", "SCY"): 

70 StorageClassFactory().registerStorageClass(StorageClass(name)) 

71 

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) 

77 

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) 

85 

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) 

93 

94 

95class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

96 pass 

97 

98 

99def setup_module(module): 

100 lsst.utils.tests.init() 

101 

102 

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()