Coverage for tests/test_bpscore.py : 44%

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
25import lsst.ctrl.bps.bps_core as bps
28TESTDIR = os.path.abspath(os.path.dirname(__file__))
31class 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 = bps.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 = bps.execute('false', self.file.name)
48 self.assertIn('false', self.file.read())
49 self.assertNotEqual(status, 0)
52class TestPrettyPrinting(unittest.TestCase):
54 def setUp(self):
55 pass
57 def tearDown(self):
58 pass
60 def testDatasetLabelFormatting(self):
61 """Test if a task label is properly formatted."""
62 original = "'raw+{band: i, instrument: HSC, detector: 17}'"
63 expected = "'raw\nband=i\n instrument=HSC\n detector=17'"
64 result = bps.pretty_dataset_label(original)
65 self.assertEqual(result, expected)
68class TestBpsCore(unittest.TestCase):
70 def setUp(self):
71 self.tmpdir = tempfile.mkdtemp(dir=TESTDIR)
73 def tearDown(self):
74 shutil.rmtree(self.tmpdir, ignore_errors=True)
76 def testCreatingQuantumGraph(self):
77 """Test if a config command creates appropriately named pickle file."""
78 settings = {
79 "global": {
80 "createQuantumGraph": "touch {qgraphfile}",
81 "submitPath": self.tmpdir,
82 }
83 }
84 config = bps.BpsConfig(settings, search_order=["global"])
85 core = bps.BpsCore(config)
86 core._create_quantum_graph()
87 self.assertTrue(os.path.exists(os.path.join(self.tmpdir, ".pickle")))
89 def testCreatingQuantumGraphFailure(self):
90 """Test if an exception is raised when creating quantum graph fails."""
91 settings = {
92 "global": {
93 "createQuantumGraph": "false",
94 "submitPath": self.tmpdir,
95 }
96 }
97 config = bps.BpsConfig(settings, search_order=["global"])
98 core = bps.BpsCore(config)
99 with self.assertRaises(RuntimeError):
100 core._create_quantum_graph()
103if __name__ == "__main__": 103 ↛ 104line 103 didn't jump to line 104, because the condition on line 103 was never true
104 unittest.main()