test_utils.py
This file
Path
tests/test_utils.py
45 lines · 1.5 KiB · Python
Last changed by
Fixed a test on python 3Armin Ronacherbefore adoptionb24e004
History of this fileTake it
Unbroke colorama integrated echo for unicode.Armin Ronacherbefore adoption537d6d5
line 1why, one step back1import sysAdded echo testsArmin Ronacherbefore adoption159ffc5
lines 2–10why, one step back2import click345def test_echo(runner):6 with runner.isolation() as out:7 click.echo(u'\N{SNOWMAN}')8 click.echo(b'\x44\x44')9 click.echo(42, nl=False)10 click.echo(b'a', nl=False)Refactored pager support to not rely on pydocArmin Ronacherbefore adoptionaef1650
line 11why, one step back11 click.echo('\x1b[31mx\x1b[39m', nl=False)Added echo testsArmin Ronacherbefore adoption159ffc5
line 12why, one step back12 bytes = out.getvalue()Refactored pager support to not rely on pydocArmin Ronacherbefore adoptionaef1650
line 13why, one step back13 assert bytes == b'\xe2\x98\x83\nDD\n42ax'Unbroke colorama integrated echo for unicode.Armin Ronacherbefore adoption537d6d5
lines 14–31why, one step back1415 # If we are on python 2 we expect that writing bytes into a string io16 # does not do anything crazy. On Python 317 if sys.version_info[0] == 2:18 import StringIO19 sys.stdout = x = StringIO.StringIO()20 try:21 click.echo('\xf6')22 finally:23 sys.stdout = sys.__stdout__24 assert x.getvalue() == '\xf6\n'2526 # And in any case, if wrapped, we expect bytes to survive.27 @click.command()28 def cli():29 click.echo(b'\xf6')30 result = runner.invoke(cli, [])31 assert result.output_bytes == b'\xf6\n'Added filename format functionArmin Ronacherbefore adoption31043c3
line 32why, one step back32Ensure we do not strip color codes for bytes.Armin Ronacherbefore adoption427492b
lines 33–35why, one step back33 # Ensure we do not strip for bytes.34 with runner.isolation() as out:35 click.echo(bytearray(b'\x1b[31mx\x1b[39m'), nl=False)Fixed a test on python 3Armin Ronacherbefore adoptionb24e004
line 36why, one step back36 assert out.getvalue() == b'\x1b[31mx\x1b[39m'Ensure we do not strip color codes for bytes.Armin Ronacherbefore adoption427492b
line 37why, one step back37Added filename format functionArmin Ronacherbefore adoption31043c3
lines 38–43why, one step back3839def test_filename_formatting():40 assert click.format_filename(b'foo.txt') == 'foo.txt'41 assert click.format_filename(b'/x/foo.txt') == '/x/foo.txt'42 assert click.format_filename(u'/x/foo.txt') == '/x/foo.txt'43 assert click.format_filename(u'/x/foo.txt', shorten=True) == 'foo.txt'Merge branch '1.0-maintenance'Armin Ronacherbefore adoptionf36e404
line 44why, one step back44 assert click.format_filename(b'/x/foo\xff.txt', shorten=True) \Added filename format functionArmin Ronacherbefore adoption31043c3
line 45why, one step back45 == u'foo\ufffd.txt'