Coverage for tests/test_dotTools.py : 37%

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# This file is part of ctrl_mpexec.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://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 <https://www.gnu.org/licenses/>.
22"""Simple unit test for Pipeline.
23"""
25import io
26import unittest
28from lsst.pipe.base import (PipelineTask, PipelineTaskConfig,
29 Pipeline, PipelineTaskConnections)
30import lsst.pipe.base.connectionTypes as cT
31from lsst.ctrl.mpexec.dotTools import pipeline2dot
32import lsst.utils.tests
35class ExamplePipelineTaskConnections(PipelineTaskConnections, dimensions=()):
36 input1 = cT.Input(name="",
37 dimensions=["visit", "detector"],
38 storageClass="example",
39 doc="Input for this task")
40 input2 = cT.Input(name="",
41 dimensions=["visit", "detector"],
42 storageClass="example",
43 doc="Input for this task")
44 output1 = cT.Output(name="",
45 dimensions=["visit", "detector"],
46 storageClass="example",
47 doc="Output for this task")
48 output2 = cT.Output(name="",
49 dimensions=["visit", "detector"],
50 storageClass="example",
51 doc="Output for this task")
53 def __init__(self, *, config=None):
54 super().__init__(config=config)
55 if not config.connections.input2:
56 self.inputs.remove("input2")
57 if not config.connections.output2:
58 self.outputs.remove("output2")
61class ExamplePipelineTaskConfig(PipelineTaskConfig, pipelineConnections=ExamplePipelineTaskConnections):
62 pass
65def _makeConfig(inputName, outputName, pipeline, label):
66 """Factory method for config instances
68 inputName and outputName can be either string or tuple of strings
69 with two items max.
70 """
71 if isinstance(inputName, tuple):
72 pipeline.addConfigOverride(label, "connections.input1", inputName[0])
73 pipeline.addConfigOverride(label, "connections.input2", inputName[1] if len(inputName) > 1 else "")
74 else:
75 pipeline.addConfigOverride(label, "connections.input1", inputName)
77 if isinstance(outputName, tuple):
78 pipeline.addConfigOverride(label, "connections.output1", outputName[0])
79 pipeline.addConfigOverride(label, "connections.output2", outputName[1] if len(outputName) > 1 else "")
80 else:
81 pipeline.addConfigOverride(label, "connections.output1", outputName)
84class ExamplePipelineTask(PipelineTask):
85 ConfigClass = ExamplePipelineTaskConfig
88def _makePipeline(tasks):
89 """Generate Pipeline instance.
91 Parameters
92 ----------
93 tasks : list of tuples
94 Each tuple in the list has 3 or 4 items:
95 - input DatasetType name(s), string or tuple of strings
96 - output DatasetType name(s), string or tuple of strings
97 - task label, string
98 - optional task class object, can be None
100 Returns
101 -------
102 Pipeline instance
103 """
104 pipe = Pipeline("test pipeline")
105 for task in tasks:
106 inputs = task[0]
107 outputs = task[1]
108 label = task[2]
109 klass = task[3] if len(task) > 3 else ExamplePipelineTask
110 pipe.addTask(klass, label)
111 _makeConfig(inputs, outputs, pipe, label)
112 return list(pipe.toExpandedPipeline())
115class DotToolsTestCase(unittest.TestCase):
116 """A test case for dotTools
117 """
119 def testPipeline2dot(self):
120 """Tests for dotTools.pipeline2dot method
121 """
122 pipeline = _makePipeline([("A", ("B", "C"), "task1"),
123 ("C", "E", "task2"),
124 ("B", "D", "task3"),
125 (("D", "E"), "F", "task4")])
126 file = io.StringIO()
127 pipeline2dot(pipeline, file)
129 # it's hard to validate complete output, just checking few basic things,
130 # even that is not terribly stable
131 lines = file.getvalue().strip().split('\n')
132 ndatasets = 6
133 ntasks = 4
134 nedges = 10
135 nextra = 2 # graph header and closing
136 self.assertEqual(len(lines), ndatasets + ntasks + nedges + nextra)
139class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
140 pass
143def setup_module(module):
144 lsst.utils.tests.init()
147if __name__ == "__main__": 147 ↛ 148line 147 didn't jump to line 148, because the condition on line 147 was never true
148 lsst.utils.tests.init()
149 unittest.main()