Coverage for tests/test_cli_commands.py: 26%

32 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-29 02:08 -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, compute_site=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( 

48 wms_service="wms_test_utils.WmsServiceSuccess", compute_site=None, pass_thru="" 

49 ) 

50 

51 def testPingFailure(self): 

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

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

54 result = self.runner.invoke( 

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

56 ) 

57 self.assertEqual(result.exit_code, 64) 

58 mock_driver.assert_called_with( 

59 wms_service="wms_test_utils.WmsServiceFailure", 

60 compute_site=None, 

61 pass_thru="", 

62 ) 

63 

64 def testPingPassthru(self): 

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

66 mock_driver.return_value = 0 

67 result = self.runner.invoke( 

68 bps.cli, 

69 [ 

70 "ping", 

71 "--wms-service-class", 

72 "wms_test_utils.WmsServicePassThru", 

73 "--compute-site", 

74 "MY_COMPUTE_SITE", 

75 "--pass-thru", 

76 "EXTRA_VALUES", 

77 ], 

78 ) 

79 self.assertEqual(result.exit_code, 0) 

80 mock_driver.assert_called_with( 

81 wms_service="wms_test_utils.WmsServicePassThru", 

82 compute_site="MY_COMPUTE_SITE", 

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()