def setUp(self) -> None: self._runner = testing.CliRunner() components._DOCKER_IS_PRESENT = True patcher = mock.patch('docker.from_env') self._docker_client = patcher.start().return_value self._docker_client.images.build.return_value = [{ 'stream': 'Build logs' }] self._docker_client.images.push.return_value = [{'status': 'Pushed'}] self.addCleanup(patcher.stop) self._app = components.app with contextlib.ExitStack() as stack: stack.enter_context(self._runner.isolated_filesystem()) self._working_dir = pathlib.Path.cwd() self.addCleanup(stack.pop_all().close) return super().setUp()
import jsonplaceholder.cmd.photos as photos import typer.testing as test runner = test.CliRunner() def test_app(): result = runner.invoke(photos.app, []) assert result.exit_code == 0 assert 'Usage: ' in result.output def test_help(): result = runner.invoke(photos.app, ['--help']) assert result.exit_code == 0 assert 'Usage: ' in result.output def test_list(): result = runner.invoke(photos.app, ['list']) assert result.exit_code == 0 def test_list_extra_args(): result = runner.invoke(photos.app, ['list', 'asadf']) assert result.exit_code == 2 def test_list_albumid(): result = runner.invoke(photos.app, ['list', '--albumid', '1']) assert result.exit_code == 0