Coverage for tests/test_pre_transform.py: 46%
37 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-30 02:09 -0700
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-30 02:09 -0700
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 import BpsConfig
27from lsst.ctrl.bps.pre_transform import create_quantum_graph, execute
29TESTDIR = os.path.abspath(os.path.dirname(__file__))
32class TestExecute(unittest.TestCase):
33 def setUp(self):
34 self.file = tempfile.NamedTemporaryFile("w+")
36 def tearDown(self):
37 self.file.close()
39 def testSuccessfulExecution(self):
40 """Test exit status if command succeeded."""
41 status = execute("true", self.file.name)
42 self.assertIn("true", self.file.read())
43 self.assertEqual(status, 0)
45 def testFailingExecution(self):
46 """Test exit status if command failed."""
47 status = execute("false", self.file.name)
48 self.assertIn("false", self.file.read())
49 self.assertNotEqual(status, 0)
52class TestCreatingQuantumGraph(unittest.TestCase):
53 def setUp(self):
54 self.tmpdir = tempfile.mkdtemp(dir=TESTDIR)
56 def tearDown(self):
57 shutil.rmtree(self.tmpdir, ignore_errors=True)
59 def testCreatingQuantumGraph(self):
60 """Test if a config command creates appropriately named qgraph file."""
61 settings = {
62 "createQuantumGraph": "touch {qgraphFile}",
63 "submitPath": self.tmpdir,
64 "whenSaveJobQgraph": "NEVER",
65 "uniqProcName": "my_test",
66 "qgraphFileTemplate": "{uniqProcName}.qgraph",
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, config["qgraphFileTemplate"])))
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()