Coverage for tests/test_cli_commands.py: 26%

32 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-20 11:11 +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/>. 

27import unittest 

28 

29from lsst.ctrl.bps.cli import bps 

30from lsst.daf.butler.cli.utils import LogCliRunner 

31 

32 

33class TestCommandPing(unittest.TestCase): 

34 """Test executing the ping subcommand.""" 

35 

36 def setUp(self): 

37 self.runner = LogCliRunner() 

38 

39 def testPingNoArgs(self): 

40 with unittest.mock.patch("lsst.ctrl.bps.cli.cmd.commands.ping_driver") as mock_driver: 

41 mock_driver.return_value = 0 

42 result = self.runner.invoke(bps.cli, ["ping"]) 

43 self.assertEqual(result.exit_code, 0) 

44 mock_driver.assert_called_with(wms_service=None, pass_thru="") 

45 

46 def testPingClass(self): 

47 with unittest.mock.patch("lsst.ctrl.bps.cli.cmd.commands.ping_driver") as mock_driver: 

48 mock_driver.return_value = 0 

49 result = self.runner.invoke( 

50 bps.cli, ["ping", "--wms-service-class", "wms_test_utils.WmsServiceSuccess"] 

51 ) 

52 self.assertEqual(result.exit_code, 0) 

53 mock_driver.assert_called_with(wms_service="wms_test_utils.WmsServiceSuccess", pass_thru="") 

54 

55 def testPingFailure(self): 

56 with unittest.mock.patch("lsst.ctrl.bps.cli.cmd.commands.ping_driver") as mock_driver: 

57 mock_driver.return_value = 64 # avoid 1 and 2 as returned when cli problems 

58 result = self.runner.invoke( 

59 bps.cli, ["ping", "--wms-service-class", "wms_test_utils.WmsServiceFailure"] 

60 ) 

61 self.assertEqual(result.exit_code, 64) 

62 mock_driver.assert_called_with( 

63 wms_service="wms_test_utils.WmsServiceFailure", 

64 pass_thru="", 

65 ) 

66 

67 def testPingPassthru(self): 

68 with unittest.mock.patch("lsst.ctrl.bps.cli.cmd.commands.ping_driver") as mock_driver: 

69 mock_driver.return_value = 0 

70 result = self.runner.invoke( 

71 bps.cli, 

72 [ 

73 "ping", 

74 "--wms-service-class", 

75 "wms_test_utils.WmsServicePassThru", 

76 "--pass-thru", 

77 "EXTRA_VALUES", 

78 ], 

79 ) 

80 self.assertEqual(result.exit_code, 0) 

81 mock_driver.assert_called_with( 

82 wms_service="wms_test_utils.WmsServicePassThru", 

83 pass_thru="EXTRA_VALUES", 

84 ) 

85 

86 

87if __name__ == "__main__": 87 ↛ 88line 87 didn't jump to line 88, because the condition on line 87 was never true

88 unittest.main()