Coverage for tests/test_drivers.py: 36%
52 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-02 09:44 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-02 09:44 +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/>.
21"""Unit tests for drivers.py."""
22import logging
23import os
24import shutil
25import tempfile
26import unittest
28from lsst.ctrl.bps import BpsConfig
29from lsst.ctrl.bps.drivers import _init_submission_driver, ping_driver
31TESTDIR = os.path.abspath(os.path.dirname(__file__))
34class TestInitSubmissionDriver(unittest.TestCase):
35 """Test submission."""
37 def setUp(self):
38 self.cwd = os.getcwd()
39 self.tmpdir = tempfile.mkdtemp(dir=TESTDIR)
41 def tearDown(self):
42 shutil.rmtree(self.tmpdir, ignore_errors=True)
44 def testDeprecatedOutCollection(self):
45 with self.assertRaisesRegex(KeyError, "outCollection"):
46 _init_submission_driver({"payload": {"outCollection": "bad"}})
48 def testMissingOutputRun(self):
49 with self.assertRaisesRegex(KeyError, "outputRun"):
50 _init_submission_driver({"payload": {"inCollection": "bad"}})
52 def testMissingSubmitPath(self):
53 with self.assertRaisesRegex(KeyError, "submitPath"):
54 _init_submission_driver({"payload": {"outputRun": "bad"}})
57class TestPingDriver(unittest.TestCase):
58 """Test ping."""
60 def testWmsServiceSuccess(self):
61 retval = ping_driver("wms_test_utils.WmsServiceSuccess")
62 self.assertEqual(retval, 0)
64 def testWmsServiceFailure(self):
65 with self.assertLogs(level=logging.ERROR) as cm:
66 retval = ping_driver("wms_test_utils.WmsServiceFailure")
67 self.assertNotEqual(retval, 0)
68 self.assertEqual(cm.records[0].getMessage(), "Couldn't contact service X")
70 def testWmsServiceEnvVar(self):
71 with unittest.mock.patch.dict(
72 os.environ, {"BPS_WMS_SERVICE_CLASS": "wms_test_utils.WmsServiceSuccess"}
73 ):
74 retval = ping_driver()
75 self.assertEqual(retval, 0)
77 @unittest.mock.patch.dict(os.environ, {})
78 def testWmsServiceNone(self):
79 # Override default wms to be the test one
80 with unittest.mock.patch.object(BpsConfig, "__getitem__") as mock_function:
81 mock_function.return_value = "wms_test_utils.WmsServiceDefault"
82 with self.assertLogs(level=logging.INFO) as cm:
83 retval = ping_driver()
84 self.assertEqual(retval, 0)
85 self.assertEqual(cm.records[0].getMessage(), "DEFAULT None")
87 def testWmsServicePassThru(self):
88 with self.assertLogs(level=logging.INFO) as cm:
89 retval = ping_driver("wms_test_utils.WmsServicePassThru", "EXTRA_VALUES")
90 self.assertEqual(retval, 0)
91 self.assertRegex(cm.output[0], "INFO.+EXTRA_VALUES")
94if __name__ == "__main__": 94 ↛ 95line 94 didn't jump to line 95, because the condition on line 94 was never true
95 unittest.main()