Coverage for tests/test_showTasks.py: 77%

51 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-14 16:10 -0700

1# 

2# LSST Data Management System 

3# Copyright 2013 LSST Corporation. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <http://www.lsstcorp.org/LegalNotices/>. 

21# 

22import io 

23import sys 

24import textwrap 

25import unittest 

26 

27import lsst.pex.config as pexConfig 

28import lsst.pipe.base as pipeBase 

29 

30try: 

31 import lsst.pipe.base.argumentParser as argumentParser 

32except ImportError: 

33 argumentParser = None 

34import lsst.utils.tests 

35 

36 

37class SimpleTaskConfig(pexConfig.Config): 

38 ff3 = pexConfig.Field(doc="float 1", dtype=float, default=3.1) 

39 sf3 = pexConfig.Field(doc="str 1", dtype=str, default="default for sf1") 

40 

41 

42class SimpleTask(pipeBase.Task): 

43 ConfigClass = SimpleTaskConfig 

44 

45 

46class TaskWithSubtasksConfig(pexConfig.Config): 

47 sst1 = SimpleTask.makeField(doc="sub-subtask 1") 

48 sst2 = SimpleTask.makeField(doc="sub-subtask 2") 

49 ff2 = pexConfig.Field(doc="float 1", dtype=float, default=3.1) 

50 sf2 = pexConfig.Field(doc="str 1", dtype=str, default="default for sf1") 

51 

52 

53class TaskWithSubtasks(pipeBase.Task): 

54 ConfigClass = TaskWithSubtasksConfig 

55 

56 

57class MainTaskConfig(pexConfig.Config): 

58 st1 = TaskWithSubtasks.makeField(doc="subtask 1") 

59 st2 = TaskWithSubtasks.makeField(doc="subtask 2") 

60 ff1 = pexConfig.Field(doc="float 2", dtype=float, default=3.1) 

61 sf1 = pexConfig.Field(doc="str 2", dtype=str, default="default for strField") 

62 

63 

64class MainTask(pipeBase.Task): 

65 ConfigClass = MainTaskConfig 

66 

67 

68c = MainTaskConfig() 

69 

70 

71@unittest.skipIf(argumentParser is None, "Gen2 argument parser is not available") 

72class ShowTasksTestCase(unittest.TestCase): 

73 """A test case for the code that implements ArgumentParser's --show tasks 

74 option. 

75 """ 

76 

77 def testBasicShowTaskHierarchy(self): 

78 """Test basic usage of show""" 

79 config = MainTaskConfig() 

80 expectedData = """ 

81 Subtasks: 

82 st1: {0}.TaskWithSubtasks 

83 st1.sst1: {0}.SimpleTask 

84 st1.sst2: {0}.SimpleTask 

85 st2: {0}.TaskWithSubtasks 

86 st2.sst1: {0}.SimpleTask 

87 st2.sst2: {0}.SimpleTask 

88 """.format( 

89 __name__ 

90 ) 

91 tempStdOut = io.StringIO() 

92 savedStdOut, sys.stdout = sys.stdout, tempStdOut 

93 try: 

94 argumentParser.showTaskHierarchy(config) 

95 finally: 

96 sys.stdout = savedStdOut 

97 formatRead = tempStdOut.getvalue().strip() 

98 formatExpected = textwrap.dedent(expectedData).strip() 

99 self.assertEqual(formatRead, formatExpected) 

100 

101 

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

103 pass 

104 

105 

106def setup_module(module): 

107 lsst.utils.tests.init() 

108 

109 

110if __name__ == "__main__": 110 ↛ 111line 110 didn't jump to line 111, because the condition on line 110 was never true

111 lsst.utils.tests.init() 

112 unittest.main()