diff options
author | Armin Ronacher <armin.ronacher@active-4.com> | 2014-05-12 01:43:55 +0200 |
---|---|---|
committer | Armin Ronacher <armin.ronacher@active-4.com> | 2014-05-12 01:43:57 +0200 |
commit | 4fd19ce097576072020084a61b6172bfb9b07f26 (patch) | |
tree | 85d47cc3393db7b4abc98073be141af3b982aa4f /tests/test_arguments.py | |
parent | ed9594d32060466a1c5763fb36e39e5dbec51306 (diff) | |
download | click-4fd19ce097576072020084a61b6172bfb9b07f26.tar.gz |
Fixed argument handling for "-" and added test. This fixes #77
Diffstat (limited to 'tests/test_arguments.py')
-rw-r--r-- | tests/test_arguments.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/test_arguments.py b/tests/test_arguments.py index c8d33e1..6040621 100644 --- a/tests/test_arguments.py +++ b/tests/test_arguments.py @@ -47,3 +47,26 @@ def test_nargs_err(runner): result = runner.invoke(copy, ['foo', 'bar']) assert result.exit_code == 2 assert 'Got unexpected extra argument (bar)' in result.output + + +def test_file_args(runner): + @click.command() + @click.argument('input', type=click.File('rb')) + @click.argument('output', type=click.File('wb')) + def inout(input, output): + while True: + chunk = input.read(1024) + if not chunk: + break + output.write(chunk) + + with runner.isolated_filesystem(): + result = runner.invoke(inout, ['-', 'hello.txt'], input='Hey!') + assert result.output == '' + assert result.exit_code == 0 + with open('hello.txt', 'rb') as f: + assert f.read() == b'Hey!' + + result = runner.invoke(inout, ['hello.txt', '-']) + assert result.output == 'Hey!' + assert result.exit_code == 0 |