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
Provenance
- Commit
262c275- Tree
b7daef7- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
2df17b6
5 files changed+32 added−8 removed
modified:click/_compat.py+12 added-2 removed
454 unmodified lines455 return _AtomicFile(f, tmp_filename, filename), True456 457 458 # Used in a destructor call, needs extra protection from interpreter cleanup.459+if hasattr(os, 'replace'):460+ _replace = os.replace461+ _can_replace = True462+else:459-_rename = os.rename463+ _replace = os.rename464+ _can_replace = not WIN465 466 467 class _AtomicFile(object):468 10 unmodified lines479 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 = True490 491 def __getattr__(self, name):492 return getattr(self._f, name)144 unmodified linesmodified:tests/test_arguments.py+2 added-1 removed
117 unmodified lines118 119 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 linesmodified:tests/test_imports.py+5 added
1 import sys2 import json3 import subprocess4 5+from click._compat import WIN6 7+8 IMPORT_TEST = b'''\9 try:10 import __builtin__ as builtins11 except ImportError:22 unmodified lines34 'functools', 'stat', 're', 'codecs', 'inspect', 'itertools', 'io',35 'threading'36 ])37 38+if WIN:39+ ALLOWED_IMPORTS.update(['ctypes', 'ctypes.wintypes', 'msvcrt'])40 41+42 def 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 linesmodified:tests/test_testing.py+2 added-2 removed
3 unmodified lines4 import click5 6 from click.testing import CliRunner7 8-from click._compat import PY28+from click._compat import PY2, WIN9 10 # Use the most reasonable io that users would use for the python version.11 if PY2:12 from cStringIO import StringIO as ReasonableBytesIO103 unmodified lines116 result = runner.invoke(cli)117 assert result.exit_code == 1118 119 120+@pytest.mark.skipif(WIN, reason='Test does not make sense on Windows.')121 def test_with_color():122 @click.command()123 def cli():124 click.secho('hello world', fg='blue')57 unmodified lines182 183 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 lines5 6 import click7 import click.utils8 import click._termui_impl9+from click._compat import WIN10 11 12 def test_echo(runner):13 with runner.isolation() as out:1 unmodified line15 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'21 22 # If we are in Python 2, we expect that writing bytes into a string io23 # does not do anything crazy. In Python 358 unmodified lines82 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'86 87+ # 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'91 92+93 def test_prompts(runner):94 @click.command()95 def test():96 if click.confirm('Foo'):32 unmodified lines129 assert not result.exception130 assert result.output == 'Foo [Y/n]: n\nno :(\n'131 132 133+@pytest.mark.skipif(WIN, reason='Different behavior on windows.')134 def test_prompts_abort(monkeypatch, capsys):135 def f(_):136 raise KeyboardInterrupt()137 7 unmodified lines145 out, err = capsys.readouterr()146 assert out == 'Password: \nScrew you.\n'147 148 149+@pytest.mark.skipif(WIN, reason='Different behavior on windows.')150 @pytest.mark.parametrize('cat', ['cat', 'cat ', 'cat '])151 def 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 line155 out, err = capfd.readouterr()156 assert out == 'haha\n'157 158 159+@pytest.mark.skipif(WIN, reason='Test does not make sense on Windows.')160 def test_echo_color_flag(monkeypatch, capfd):161 isatty = True162 monkeypatch.setattr(click._compat, 'isatty', lambda x: isatty)163 19 unmodified lines183 out, err = capfd.readouterr()184 assert out == text + '\n'185 186 187+@pytest.mark.skipif(WIN, reason='Test too complex to make work windows.')188 def 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