Coverage for tests/test_cliUtilToUpper.py: 48%

27 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-28 10:10 +0000

1# This file is part of daf_butler. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://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 <http://www.gnu.org/licenses/>. 

21 

22"""Unit tests for the daf_butler shared CLI options. 

23""" 

24 

25import unittest 

26 

27import click 

28from lsst.daf.butler.cli.utils import LogCliRunner, to_upper 

29 

30 

31@click.command() 

32@click.option("--value", callback=to_upper) 

33def cli(value): 

34 """Run mock command.""" 

35 click.echo(value) 

36 

37 

38class ToUpperTestCase(unittest.TestCase): 

39 """Test the to_upper function.""" 

40 

41 def setUp(self): 

42 self.runner = LogCliRunner() 

43 

44 def test_isolated(self): 

45 """Test the to_upper callback by itself.""" 

46 ctx = "unused" 

47 param = "unused" 

48 self.assertEqual(to_upper(ctx, param, "debug"), "DEBUG") 

49 

50 def test_lowerToUpper(self): 

51 """Test the to_upper callback in an option with a lowercase value.""" 

52 result = self.runner.invoke(cli, ["--value", "debug"]) 

53 self.assertEqual(result.exit_code, 0) 

54 self.assertEqual(result.stdout, "DEBUG\n") 

55 

56 def test_upperToUpper(self): 

57 """Test the to_upper callback in an option with a uppercase value.""" 

58 result = self.runner.invoke(cli, ["--value", "DEBUG"]) 

59 self.assertEqual(result.exit_code, 0) 

60 self.assertEqual(result.stdout, "DEBUG\n") 

61 

62 def test_mixedToUpper(self): 

63 """Test the to_upper callback in an option with a mixed-case value.""" 

64 result = self.runner.invoke(cli, ["--value", "DeBuG"]) 

65 self.assertEqual(result.exit_code, 0) 

66 self.assertEqual(result.stdout, "DEBUG\n") 

67 

68 

69if __name__ == "__main__": 

70 unittest.main()