| Total Complexity | 3 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from unittest import mock |
||
| 2 | |||
| 3 | from click.testing import CliRunner |
||
| 4 | |||
| 5 | from lagom import Container, injectable |
||
| 6 | from lagom.experimental.integrations.click import ClickIntegration, ClickIO |
||
| 7 | |||
| 8 | container = Container() |
||
| 9 | cli = ClickIntegration(container) |
||
| 10 | |||
| 11 | |||
| 12 | @cli.command() |
||
| 13 | @cli.argument("name") |
||
| 14 | def hello(name, io: ClickIO = injectable): |
||
| 15 | io.echo(f"Hello {name}") |
||
| 16 | |||
| 17 | |||
| 18 | def test_click_io_objected_is_injected_and_proxies_click_as_expected(): |
||
| 19 | runner = CliRunner() |
||
| 20 | result = runner.invoke(hello, args=["Steve"]) |
||
| 21 | assert result.exit_code == 0 |
||
| 22 | assert result.output == "Hello Steve\n" |
||
| 23 | |||
| 24 | |||
| 25 | def test_a_reference_to_the_plain_function_is_exposed_for_testing(): |
||
| 26 | mock_io = mock.create_autospec(ClickIO) |
||
| 27 | hello.plain_function("again", mock_io) |
||
| 28 | mock_io.echo.assert_called_once_with("Hello again") |
||
| 29 |