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
68 option.
69 """
71 def testBasicShowTaskHierarchy(self):
72 """Test basic usage of show
73 """
74 config = MainTaskConfig()
75 expectedData = """
76 Subtasks:
77 st1: {0}.TaskWithSubtasks
78 st1.sst1: {0}.SimpleTask
79 st1.sst2: {0}.SimpleTask
80 st2: {0}.TaskWithSubtasks
81 st2.sst1: {0}.SimpleTask
82 st2.sst2: {0}.SimpleTask
83 """.format(__name__)
84 tempStdOut = io.StringIO()
85 savedStdOut, sys.stdout = sys.stdout, tempStdOut
86 try:
87 pipeBase.argumentParser.showTaskHierarchy(config)
88 finally:
89 sys.stdout = savedStdOut
90 formatRead = tempStdOut.getvalue().strip()
91 formatExpected = textwrap.dedent(expectedData).strip()
92 self.assertEqual(formatRead, formatExpected)
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()