Coverage for tests/test_pre_transform.py : 49%

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_bps.
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/>.
21import os
22import shutil
23import tempfile
24import unittest
26from lsst.ctrl.bps.bps_config import BpsConfig
27from lsst.ctrl.bps.pre_transform import execute, create_quantum_graph
30TESTDIR = os.path.abspath(os.path.dirname(__file__))
33class TestExecute(unittest.TestCase):
35 def setUp(self):
36 self.file = tempfile.NamedTemporaryFile("w+")
38 def tearDown(self):
39 self.file.close()
41 def testSuccessfulExecution(self):
42 """Test exit status if command succeeded."""
43 status = execute('true', self.file.name)
44 self.assertIn('true', self.file.read())
45 self.assertEqual(status, 0)
47 def testFailingExecution(self):
48 """Test exit status if command failed."""
49 status = execute('false', self.file.name)
50 self.assertIn('false', self.file.read())
51 self.assertNotEqual(status, 0)
54class TestCreatingQuantumGraph(unittest.TestCase):
56 def setUp(self):
57 self.tmpdir = tempfile.mkdtemp(dir=TESTDIR)
59 def tearDown(self):
60 shutil.rmtree(self.tmpdir, ignore_errors=True)
62 def testCreatingQuantumGraph(self):
63 """Test if a config command creates appropriately named qgraph file."""
64 settings = {
65 "createQuantumGraph": "touch {qgraphFile}",
66 "submitPath": self.tmpdir,
67 }
68 config = BpsConfig(settings, search_order=[])
69 create_quantum_graph(config, self.tmpdir)
70 self.assertTrue(os.path.exists(os.path.join(self.tmpdir, ".qgraph")))
72 def testCreatingQuantumGraphFailure(self):
73 """Test if an exception is raised when creating qgraph file fails."""
74 settings = {
75 "createQuantumGraph": "false",
76 "submitPath": self.tmpdir,
77 }
78 config = BpsConfig(settings, search_order=[])
79 with self.assertRaises(RuntimeError):
80 create_quantum_graph(config, self.tmpdir)
83if __name__ == "__main__": 83 ↛ 84line 83 didn't jump to line 84, because the condition on line 83 was never true
84 unittest.main()