Skip to content
Myr

Added a test for pipelines

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 bd61da2 · Browse files · 1 file+51 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+51 added−0 removed

  • tests:+51 added−0 removed

1 file+51 added−0 removed

modified:tests/test_chain.py+51 added
125 unmodified lines
126127 ctx.invoked_subcommands = ['foo', 'bar']128 assert ctx.invoked_subcommand == '*'129 assert ctx.invoked_subcommands == ['foo', 'bar']130131132def test_pipeline(runner):133 @click.group(chain=True, invoke_without_command=True)134 @click.option('-i', '--input', type=click.File('r'))135 def cli(input):136 pass137138 @cli.resultcallback()139 def process_pipeline(processors, input):140 iterator = (x.rstrip('\r\n') for x in input)141 for processor in processors:142 iterator = processor(iterator)143 for item in iterator:144 click.echo(item)145146 @cli.command('uppercase')147 def make_uppercase():148 def processor(iterator):149 for line in iterator:150 yield line.upper()151 return processor152153 @cli.command('strip')154 def make_strip():155 def processor(iterator):156 for line in iterator:157 yield line.strip()158 return processor159160 result = runner.invoke(cli, ['-i', '-'], input='foo\nbar')161 assert not result.exception162 assert result.output.splitlines() == [163 'foo',164 'bar',165 ]166167 result = runner.invoke(cli, ['-i', '-', 'strip'], input='foo \n bar')168 assert not result.exception169 assert result.output.splitlines() == [170 'foo',171 'bar',172 ]173174 result = runner.invoke(cli, ['-i', '-', 'strip', 'uppercase'],175 input='foo \n bar')176 assert not result.exception177 assert result.output.splitlines() == [178 'FOO',179 'BAR',180 ]