Skip to content
Myr

Fixed broken tests and behavior on windows.

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 2df17b6 · Browse files · 5 files+32 added−8 removed
This commit

State

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

Diff stats

5 files+32 added−8 removed

  • tests:+20 added−6 removed
  • other:+12 added−2 removed

5 files+32 added−8 removed

modified:click/_compat.py+12 added-2 removed
454 unmodified lines
455 return _AtomicFile(f, tmp_filename, filename), True456457458# Used in a destructor call, needs extra protection from interpreter cleanup.459if hasattr(os, 'replace'):460 _replace = os.replace461 _can_replace = True462else:459_rename = os.rename463 _replace = os.rename464 _can_replace = not WIN465466467class _AtomicFile(object):468
10 unmodified lines
479 def close(self, delete=False):480 if self.closed:481 return482 self._f.close()483 if not _can_replace:484 try:485 os.remove(self._real_filename)486 except OSError:487 pass478 _rename(self._tmp_filename, self._real_filename)488 _replace(self._tmp_filename, self._real_filename)489 self.closed = True490491 def __getattr__(self, name):492 return getattr(self._f, name)
144 unmodified lines
modified:tests/test_arguments.py+2 added-1 removed
117 unmodified lines
118119 with runner.isolated_filesystem():120 with open('foo.txt', 'wb') as f:121 f.write(b'OLD\n')122 result = runner.invoke(inout, ['foo.txt'], input='Hey!')122 result = runner.invoke(inout, ['foo.txt'], input='Hey!',123 catch_exceptions=False)124 assert result.output == ''125 assert result.exit_code == 0126 with open('foo.txt', 'rb') as f:127 assert f.read() == b'Foo bar baz\n'
133 unmodified lines
modified:tests/test_imports.py+5 added
1import sys2import json3import subprocess45from click._compat import WIN678IMPORT_TEST = b'''\9try:10 import __builtin__ as builtins11except ImportError:
22 unmodified lines
34 'functools', 'stat', 're', 'codecs', 'inspect', 'itertools', 'io',35 'threading'36])3738if WIN:39 ALLOWED_IMPORTS.update(['ctypes', 'ctypes.wintypes', 'msvcrt'])404142def test_light_imports():43 c = subprocess.Popen([sys.executable, '-'], stdin=subprocess.PIPE,44 stdout=subprocess.PIPE)45 rv = c.communicate(IMPORT_TEST)[0]
10 unmodified lines
modified:tests/test_testing.py+2 added-2 removed
3 unmodified lines
4import click56from click.testing import CliRunner78from click._compat import PY28from click._compat import PY2, WIN910# Use the most reasonable io that users would use for the python version.11if PY2:12 from cStringIO import StringIO as ReasonableBytesIO
103 unmodified lines
116 result = runner.invoke(cli)117 assert result.exit_code == 1118119120@pytest.mark.skipif(WIN, reason='Test does not make sense on Windows.')121def test_with_color():122 @click.command()123 def cli():124 click.secho('hello world', fg='blue')
57 unmodified lines
182183 result = runner.invoke(cli_no_error)184 assert result.exit_code == 0185 assert result.output == 'hello world\n'185
modified:tests/test_utils.py+11 added-3 removed
4 unmodified lines
56import click7import click.utils8import click._termui_impl9from click._compat import WIN101112def test_echo(runner):13 with runner.isolation() as out:
1 unmodified line
15 click.echo(b'\x44\x44')16 click.echo(42, nl=False)17 click.echo(b'a', nl=False)18 click.echo('\x1b[31mx\x1b[39m', nl=False)18 bytes = out.getvalue()19 bytes = out.getvalue().replace('\r\n', '\n')20 assert bytes == b'\xe2\x98\x83\nDD\n42ax'2122 # If we are in Python 2, we expect that writing bytes into a string io23 # does not do anything crazy. In Python 3
58 unmodified lines
82 assert click.format_filename(b'foo.txt') == 'foo.txt'83 assert click.format_filename(b'/x/foo.txt') == '/x/foo.txt'84 assert click.format_filename(u'/x/foo.txt') == '/x/foo.txt'85 assert click.format_filename(u'/x/foo.txt', shorten=True) == 'foo.txt'85 assert click.format_filename(b'/x/foo\xff.txt', shorten=True) \86 == u'foo\ufffd.txt'8687 # filesystem encoding on windows permits this.88 if not WIN:89 assert click.format_filename(b'/x/foo\xff.txt', shorten=True) \90 == u'foo\ufffd.txt'919293def test_prompts(runner):94 @click.command()95 def test():96 if click.confirm('Foo'):
32 unmodified lines
129 assert not result.exception130 assert result.output == 'Foo [Y/n]: n\nno :(\n'131132133@pytest.mark.skipif(WIN, reason='Different behavior on windows.')134def test_prompts_abort(monkeypatch, capsys):135 def f(_):136 raise KeyboardInterrupt()137
7 unmodified lines
145 out, err = capsys.readouterr()146 assert out == 'Password: \nScrew you.\n'147148149@pytest.mark.skipif(WIN, reason='Different behavior on windows.')150@pytest.mark.parametrize('cat', ['cat', 'cat ', 'cat '])151def test_echo_via_pager(monkeypatch, capfd, cat):152 monkeypatch.setitem(os.environ, 'PAGER', cat)153 monkeypatch.setattr(click._termui_impl, 'isatty', lambda x: True)
1 unmodified line
155 out, err = capfd.readouterr()156 assert out == 'haha\n'157158159@pytest.mark.skipif(WIN, reason='Test does not make sense on Windows.')160def test_echo_color_flag(monkeypatch, capfd):161 isatty = True162 monkeypatch.setattr(click._compat, 'isatty', lambda x: isatty)163
19 unmodified lines
183 out, err = capfd.readouterr()184 assert out == text + '\n'185186187@pytest.mark.skipif(WIN, reason='Test too complex to make work windows.')188def test_echo_writing_to_standard_error(capfd, monkeypatch):189 def emulate_input(text):190 """Emulate keyboard input."""191 if sys.version_info[0] == 2:
92 unmodified lines