Coverage for tests/test_cliOptionTransfer.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 daf_butler transfer CLI option.
23"""
25import click
26import click.testing
27import unittest
29from lsst.obs.base.cli.opt import transfer_option
32class Case(unittest.TestCase):
34 def test_set(self):
36 @click.command()
37 @transfer_option()
38 def cli(transfer):
39 click.echo(transfer, nl=False)
41 runner = click.testing.CliRunner()
42 result = runner.invoke(cli, ["--transfer", "symlink"])
43 self.assertEqual(result.exit_code, 0)
44 self.assertEqual(result.stdout, "symlink")
46 def test_default(self):
48 @click.command()
49 @transfer_option()
50 def cli(transfer):
51 click.echo(transfer, nl=False)
53 runner = click.testing.CliRunner()
54 result = runner.invoke(cli, [])
55 self.assertEqual(result.exit_code, 0)
56 self.assertEqual(result.stdout, "auto")
58 def test_illegal(self):
60 @click.command()
61 @transfer_option()
62 def cli(transfer):
63 click.echo(transfer, nl=False)
65 runner = click.testing.CliRunner()
66 result = runner.invoke(cli, ["--transfer", "foo"])
67 self.assertNotEqual(result.exit_code, 0)
68 self.assertIn("invalid choice: foo", result.output)
70 def test_help(self):
72 @click.command()
73 @transfer_option(help="test transfer option")
74 def cli(transfer):
75 click.echo(transfer, 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 transfer 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()