Coverage for tests/test_preExecInit.py : 17%

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 PreExecInit class.
23"""
25import unittest
27from lsst.ctrl.mpexec import PreExecInit
28from testUtil import makeSimpleQGraph, AddTaskFactoryMock
31class PreExecInitTestCase(unittest.TestCase):
32 """A test case for PreExecInit
33 """
35 def test_saveInitOutputs(self):
36 taskFactory = AddTaskFactoryMock()
37 for skipExisting in (False, True):
38 with self.subTest(skipExisting=skipExisting):
39 butler, qgraph = makeSimpleQGraph()
40 preExecInit = PreExecInit(butler=butler, taskFactory=taskFactory, skipExisting=skipExisting)
41 preExecInit.saveInitOutputs(qgraph)
43 def test_saveInitOutputs_twice(self):
44 taskFactory = AddTaskFactoryMock()
45 for skipExisting in (False, True):
46 with self.subTest(skipExisting=skipExisting):
47 butler, qgraph = makeSimpleQGraph()
48 preExecInit = PreExecInit(butler=butler, taskFactory=taskFactory, skipExisting=skipExisting)
49 preExecInit.saveInitOutputs(qgraph)
50 if skipExisting:
51 # will ignore this
52 preExecInit.saveInitOutputs(qgraph)
53 else:
54 # Second time it will fail
55 with self.assertRaises(Exception):
56 preExecInit.saveInitOutputs(qgraph)
58 def test_saveConfigs(self):
59 for skipExisting in (False, True):
60 with self.subTest(skipExisting=skipExisting):
61 butler, qgraph = makeSimpleQGraph()
62 preExecInit = PreExecInit(butler=butler, taskFactory=None, skipExisting=skipExisting)
63 preExecInit.saveConfigs(qgraph)
65 def test_saveConfigs_twice(self):
66 for skipExisting in (False, True):
67 with self.subTest(skipExisting=skipExisting):
68 butler, qgraph = makeSimpleQGraph()
69 preExecInit = PreExecInit(butler=butler, taskFactory=None, skipExisting=skipExisting)
70 preExecInit.saveConfigs(qgraph)
71 if skipExisting:
72 # will ignore this
73 preExecInit.saveConfigs(qgraph)
74 else:
75 # Second time it will fail
76 with self.assertRaises(Exception):
77 preExecInit.saveConfigs(qgraph)
79 def test_savePackageVersions(self):
80 for skipExisting in (False, True):
81 with self.subTest(skipExisting=skipExisting):
82 butler, qgraph = makeSimpleQGraph()
83 preExecInit = PreExecInit(butler=butler, taskFactory=None, skipExisting=skipExisting)
84 preExecInit.savePackageVersions(qgraph)
86 def test_savePackageVersions_twice(self):
87 for skipExisting in (False, True):
88 with self.subTest(skipExisting=skipExisting):
89 butler, qgraph = makeSimpleQGraph()
90 preExecInit = PreExecInit(butler=butler, taskFactory=None, skipExisting=skipExisting)
91 preExecInit.savePackageVersions(qgraph)
92 if skipExisting:
93 # if this is the same packages then it should not attempt to save
94 preExecInit.savePackageVersions(qgraph)
95 else:
96 # second time it will fail
97 with self.assertRaises(Exception):
98 preExecInit.savePackageVersions(qgraph)
101if __name__ == "__main__": 101 ↛ 102line 101 didn't jump to line 102, because the condition on line 101 was never true
102 unittest.main()