Coverage for tests/test_cliOptionInstrument.py : 29%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of obs_base.
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/>.
22"""Unit tests for the butler instrument CLI option.
23"""
25import click
26import click.testing
27import unittest
29from lsst.obs.base.cli.opt import instrument_option
32class Case(unittest.TestCase):
34 def test_set(self):
36 @click.command()
37 @instrument_option()
38 def cli(instrument):
39 click.echo(instrument, nl=False)
41 runner = click.testing.CliRunner()
42 result = runner.invoke(cli, ["--instrument", "myInstr"])
43 self.assertEqual(result.exit_code, 0, f"output: {result.output} exception: {result.exception}")
44 self.assertEqual(result.stdout, "myInstr")
46 def test_required(self):
48 @click.command()
49 @instrument_option(required=True)
50 def cli(instrument):
51 click.echo(instrument, nl=False)
53 runner = click.testing.CliRunner()
54 result = runner.invoke(cli, [])
55 self.assertNotEqual(result.exit_code, 0, f"output: {result.output} exception: {result.exception}")
56 self.assertIn('Missing option "-i" / "--instrument"', result.output)
58 def test_notRequired(self):
60 @click.command()
61 @instrument_option()
62 def cli(instrument):
63 click.echo(instrument, nl=False)
65 runner = click.testing.CliRunner()
66 result = runner.invoke(cli, [])
67 self.assertEqual(result.exit_code, 0, f"output: {result.output} exception: {result.exception}")
68 self.assertEqual(result.stdout, "")
70 def test_help(self):
72 @click.command()
73 @instrument_option(help="test instrument option")
74 def cli(instrument):
75 click.echo(instrument, nl=False)
77 runner = click.testing.CliRunner()
78 result = runner.invoke(cli, ["--help"])
79 self.assertEqual(result.exit_code, 0, f"output: {result.output} exception: {result.exception}")
80 self.assertIn("test instrument option", result.stdout)
83if __name__ == "__main__": 83 ↛ 84line 83 didn't jump to line 84, because the condition on line 83 was never true
84 unittest.main()