Skip to content
Myr

Made tests pass on 3.x

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 82d9b0c · Browse files · 3 files+37 added−15 removed
This commit

State

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

Diff stats

3 files+37 added−15 removed

  • tests:+30 added−15 removed
  • other:+7 added−0 removed

3 files+37 added−15 removed

modified:tests/conftest.py+28 added-13 removed
3 unmodified lines
4import shutil5import tempfile6import contextlib78from cStringIO import StringIO98import pytest910PY2 = sys.version_info[0] == 211if PY2:12 from cStringIO import StringIO13 iteritems = lambda x: x.iteritems()14else:15 import io16 iteritems = lambda x: iter(x.items())171819class EchoingStdin(object):2021 def __init__(self, input, output):22 self._input = input
36 unmodified lines
59class CliRunner(object):6061 @contextlib.contextmanager62 def isolation(self, input=None, env=None):57 if isinstance(input, unicode):63 if input is not None and not isinstance(input, bytes):64 input = input.encode('utf-8')59 input = StringIO(input or '')60 output = StringIO()61 sys.stdin = EchoingStdin(input, output)62 sys.stdin.encoding = 'utf-8'6566 old_stdout = sys.stdout67 old_stderr = sys.stderr6869 if PY2:70 input = StringIO(input or '')71 output = StringIO()72 sys.stdin = EchoingStdin(input, output)73 sys.stdin.encoding = 'utf-8'74 sys.stdout = sys.stderr = output75 else:76 real_input = io.BytesIO(input)77 output = io.BytesIO()78 input = io.TextIOWrapper(real_input, encoding='utf-8')79 sys.stdin = EchoingStdin(real_input, output)80 sys.stdout = sys.stderr = io.TextIOWrapper(output,81 encoding='utf-8')8283 def visible_input(prompt=None):84 sys.stdout.write(prompt or '')85 val = input.readline().rstrip('\r\n')86 sys.stdout.write(val + '\n')
4 unmodified lines
91 sys.stdout.write((prompt or '') + '\n')92 sys.stdout.flush()93 return input.readline().rstrip('\r\n')9476 old_stdout = sys.stdout77 sys.stdout = output78 old_stderr = sys.stderr79 sys.stderr = output95 old_visible_prompt_func = click.helpers.visible_prompt_func96 old_hidden_prompt_func = click.helpers.hidden_prompt_func97 click.helpers.visible_prompt_func = visible_input98 click.helpers.hidden_prompt_func = hidden_input99100 old_env = {}101 try:102 if env:88 for key, value in env.iteritems():103 for key, value in iteritems(env):104 old_env[key] = os.environ.get(value)105 os.environ[key] = value106 yield output107 finally:93 for key, value in old_env.iteritems():108 for key, value in iteritems(old_env):109 if value is None:110 try:111 del os.environ[key]112 except Exception:
45 unmodified lines
modified:tests/test_basic.py+2 added-2 removed
145 unmodified lines
146147148def test_file_option(runner):149 @click.command()150 @click.option('--file', type=click.File('wb'))150 @click.option('--file', type=click.File('w'))151 def input(file):152 file.write('Hello World!\n')153154 @click.command()155 @click.option('--file', type=click.File('rb'))155 @click.option('--file', type=click.File('r'))156 def output(file):157 click.echo(file.read())158159 with runner.isolated_filesystem():
7 unmodified lines
modified:LICENSE+7 added
1Copyright (c) 2014 by Armin Ronacher.23Click uses parts of optparse written by Gregory P. Ward and maintained by the4Python software foundation. This is limited to code in the _optparse.py5module:67Copyright (c) 2001-2006 Gregory P. Ward. All rights reserved.8Copyright (c) 2002-2006 Python Software Foundation. All rights reserved.910Some rights reserved.1112Redistribution and use in source and binary forms, with or without13modification, are permitted provided that the following conditions are
25 unmodified lines