Coverage for tests/test_pre_transform.py: 46%
37 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-23 10:45 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-23 10:45 +0000
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 """Test execution."""
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):
55 """Test quantum graph creation."""
57 def setUp(self):
58 self.tmpdir = tempfile.mkdtemp(dir=TESTDIR)
60 def tearDown(self):
61 shutil.rmtree(self.tmpdir, ignore_errors=True)
63 def testCreatingQuantumGraph(self):
64 """Test if a config command creates appropriately named qgraph file."""
65 settings = {
66 "createQuantumGraph": "touch {qgraphFile}",
67 "submitPath": self.tmpdir,
68 "whenSaveJobQgraph": "NEVER",
69 "uniqProcName": "my_test",
70 "qgraphFileTemplate": "{uniqProcName}.qgraph",
71 }
72 config = BpsConfig(settings, search_order=[])
73 create_quantum_graph(config, self.tmpdir)
74 self.assertTrue(os.path.exists(os.path.join(self.tmpdir, config["qgraphFileTemplate"])))
76 def testCreatingQuantumGraphFailure(self):
77 """Test if an exception is raised when creating qgraph file fails."""
78 settings = {
79 "createQuantumGraph": "false",
80 "submitPath": self.tmpdir,
81 }
82 config = BpsConfig(settings, search_order=[])
83 with self.assertRaises(RuntimeError):
84 create_quantum_graph(config, self.tmpdir)
87if __name__ == "__main__": 87 ↛ 88line 87 didn't jump to line 88, because the condition on line 87 was never true
88 unittest.main()