Coverage for tests/test_showTasks.py : 71%

Hot-keys 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#
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 sys
23import io
24import unittest
25import textwrap
27import lsst.utils.tests
28import lsst.pex.config as pexConfig
29import lsst.pipe.base as pipeBase
32class SimpleTaskConfig(pexConfig.Config):
33 ff3 = pexConfig.Field(doc="float 1", dtype=float, default=3.1)
34 sf3 = pexConfig.Field(doc="str 1", dtype=str, default="default for sf1")
37class SimpleTask(pipeBase.Task):
38 ConfigClass = SimpleTaskConfig
41class TaskWithSubtasksConfig(pexConfig.Config):
42 sst1 = SimpleTask.makeField(doc="sub-subtask 1")
43 sst2 = SimpleTask.makeField(doc="sub-subtask 2")
44 ff2 = pexConfig.Field(doc="float 1", dtype=float, default=3.1)
45 sf2 = pexConfig.Field(doc="str 1", dtype=str, default="default for sf1")
48class TaskWithSubtasks(pipeBase.Task):
49 ConfigClass = TaskWithSubtasksConfig
52class MainTaskConfig(pexConfig.Config):
53 st1 = TaskWithSubtasks.makeField(doc="subtask 1")
54 st2 = TaskWithSubtasks.makeField(doc="subtask 2")
55 ff1 = pexConfig.Field(doc="float 2", dtype=float, default=3.1)
56 sf1 = pexConfig.Field(doc="str 2", dtype=str, default="default for strField")
59class MainTask(pipeBase.Task):
60 ConfigClass = MainTaskConfig
63c = MainTaskConfig()
66class ShowTasksTestCase(unittest.TestCase):
67 """A test case for the code that implements ArgumentParser's --show tasks option
68 """
70 def testBasicShowTaskHierarchy(self):
71 """Test basic usage of show
72 """
73 config = MainTaskConfig()
74 expectedData = """
75 Subtasks:
76 st1: {0}.TaskWithSubtasks
77 st1.sst1: {0}.SimpleTask
78 st1.sst2: {0}.SimpleTask
79 st2: {0}.TaskWithSubtasks
80 st2.sst1: {0}.SimpleTask
81 st2.sst2: {0}.SimpleTask
82 """.format(__name__)
83 tempStdOut = io.StringIO()
84 savedStdOut, sys.stdout = sys.stdout, tempStdOut
85 try:
86 pipeBase.argumentParser.showTaskHierarchy(config)
87 finally:
88 sys.stdout = savedStdOut
89 formatRead = tempStdOut.getvalue().strip()
90 formatExpected = textwrap.dedent(expectedData).strip()
91 self.assertEqual(formatRead, formatExpected)
94class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
95 pass
98def setup_module(module):
99 lsst.utils.tests.init()
102if __name__ == "__main__": 102 ↛ 103line 102 didn't jump to line 103, because the condition on line 102 was never true
103 lsst.utils.tests.init()
104 unittest.main()