Coverage for tests/test_cli_commands.py: 26%

32 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-14 03:01 -0800

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 unittest 

22 

23from lsst.ctrl.bps.cli import bps 

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

25 

26 

27class TestCommandPing(unittest.TestCase): 

28 """Test executing the ping subcommand.""" 

29 

30 def setUp(self): 

31 self.runner = LogCliRunner() 

32 

33 def testPingNoArgs(self): 

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

35 mock_driver.return_value = 0 

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

37 self.assertEqual(result.exit_code, 0) 

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

39 

40 def testPingClass(self): 

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

42 mock_driver.return_value = 0 

43 result = self.runner.invoke( 

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

45 ) 

46 self.assertEqual(result.exit_code, 0) 

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

48 

49 def testPingFailure(self): 

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

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

52 result = self.runner.invoke( 

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

54 ) 

55 self.assertEqual(result.exit_code, 64) 

56 mock_driver.assert_called_with( 

57 wms_service="wms_test_utils.WmsServiceFailure", 

58 pass_thru="", 

59 ) 

60 

61 def testPingPassthru(self): 

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

63 mock_driver.return_value = 0 

64 result = self.runner.invoke( 

65 bps.cli, 

66 [ 

67 "ping", 

68 "--wms-service-class", 

69 "wms_test_utils.WmsServicePassThru", 

70 "--pass-thru", 

71 "EXTRA_VALUES", 

72 ], 

73 ) 

74 self.assertEqual(result.exit_code, 0) 

75 mock_driver.assert_called_with( 

76 wms_service="wms_test_utils.WmsServicePassThru", 

77 pass_thru="EXTRA_VALUES", 

78 ) 

79 

80 

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

82 unittest.main()