Coverage for tests/test_drivers.py: 36%
52 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-20 11:12 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-20 11:12 +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 software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <https://www.gnu.org/licenses/>.
27"""Unit tests for drivers.py."""
28import logging
29import os
30import shutil
31import tempfile
32import unittest
34from lsst.ctrl.bps import BpsConfig
35from lsst.ctrl.bps.drivers import _init_submission_driver, ping_driver
37TESTDIR = os.path.abspath(os.path.dirname(__file__))
40class TestInitSubmissionDriver(unittest.TestCase):
41 """Test submission."""
43 def setUp(self):
44 self.cwd = os.getcwd()
45 self.tmpdir = tempfile.mkdtemp(dir=TESTDIR)
47 def tearDown(self):
48 shutil.rmtree(self.tmpdir, ignore_errors=True)
50 def testDeprecatedOutCollection(self):
51 with self.assertRaisesRegex(KeyError, "outCollection"):
52 _init_submission_driver({"payload": {"outCollection": "bad"}})
54 def testMissingOutputRun(self):
55 with self.assertRaisesRegex(KeyError, "outputRun"):
56 _init_submission_driver({"payload": {"inCollection": "bad"}})
58 def testMissingSubmitPath(self):
59 with self.assertRaisesRegex(KeyError, "submitPath"):
60 _init_submission_driver({"payload": {"outputRun": "bad"}})
63class TestPingDriver(unittest.TestCase):
64 """Test ping."""
66 def testWmsServiceSuccess(self):
67 retval = ping_driver("wms_test_utils.WmsServiceSuccess")
68 self.assertEqual(retval, 0)
70 def testWmsServiceFailure(self):
71 with self.assertLogs(level=logging.ERROR) as cm:
72 retval = ping_driver("wms_test_utils.WmsServiceFailure")
73 self.assertNotEqual(retval, 0)
74 self.assertEqual(cm.records[0].getMessage(), "Couldn't contact service X")
76 def testWmsServiceEnvVar(self):
77 with unittest.mock.patch.dict(
78 os.environ, {"BPS_WMS_SERVICE_CLASS": "wms_test_utils.WmsServiceSuccess"}
79 ):
80 retval = ping_driver()
81 self.assertEqual(retval, 0)
83 @unittest.mock.patch.dict(os.environ, {})
84 def testWmsServiceNone(self):
85 # Override default wms to be the test one
86 with unittest.mock.patch.object(BpsConfig, "__getitem__") as mock_function:
87 mock_function.return_value = "wms_test_utils.WmsServiceDefault"
88 with self.assertLogs(level=logging.INFO) as cm:
89 retval = ping_driver()
90 self.assertEqual(retval, 0)
91 self.assertEqual(cm.records[0].getMessage(), "DEFAULT None")
93 def testWmsServicePassThru(self):
94 with self.assertLogs(level=logging.INFO) as cm:
95 retval = ping_driver("wms_test_utils.WmsServicePassThru", "EXTRA_VALUES")
96 self.assertEqual(retval, 0)
97 self.assertRegex(cm.output[0], "INFO.+EXTRA_VALUES")
100if __name__ == "__main__": 100 ↛ 101line 100 didn't jump to line 101, because the condition on line 100 was never true
101 unittest.main()