Skip to content
Myr

Added tests for lazy flags

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent f270dd2 · Browse files · 1 file+42 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+42 added−0 removed

  • tests:+42 added−0 removed

1 file+42 added−0 removed

modified:tests/test_basic.py+42 added
1# -*- coding: utf-8 -*-2import os3import uuid4import click56
182 unmodified lines
189 assert not result_out.exception190 assert result_out.output == 'Hello World!\n\n'191192193def test_file_lazy_mode(runner):194 do_io = False195196 @click.command()197 @click.option('--file', type=click.File('w'))198 def input(file):199 if do_io:200 file.write('Hello World!\n')201202 @click.command()203 @click.option('--file', type=click.File('r'))204 def output(file):205 pass206207 with runner.isolated_filesystem():208 os.mkdir('example.txt')209210 do_io = True211 result_in = runner.invoke(input, ['--file=example.txt'])212 assert result_in.exit_code == 1213214 do_io = False215 result_in = runner.invoke(input, ['--file=example.txt'])216 assert result_in.exit_code == 0217218 result_out = runner.invoke(output, ['--file=example.txt'])219 assert result_out.exception220221 @click.command()222 @click.option('--file', type=click.File('w', lazy=False))223 def input_non_lazy(file):224 file.write('Hello World!\n')225226 with runner.isolated_filesystem():227 os.mkdir('example.txt')228 result_in = runner.invoke(input_non_lazy, ['--file=example.txt'])229 assert result_in.exit_code == 2230 assert 'Invalid value for "--file": Could not open file: example.txt' \231 in result_in.output232233234def test_choice_option(runner):235 @click.command()236 @click.option('--method', type=click.Choice(['foo', 'bar', 'baz']))237 def cli(method):
57 unmodified lines