Skip to content
Myr

Added tests for styling

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 22241e4 · Browse files · 2 files+29 added−1 removed
This commit

State

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

Diff stats

2 files+29 added−1 removed

  • tests:+28 added−0 removed
  • other:+1 added−1 removed

2 files+29 added−1 removed

modified:click/termui.py+1 added-1 removed
327 unmodified lines
328 raise TypeError('Unknown color %r' % bg)329 if bold is not None:330 bits.append('\033[%dm' % (1 if bold else 22))331 if dim is not None:332 bits.append('\033[%dm' % (2 if bold else 22))332 bits.append('\033[%dm' % (2 if dim else 22))333 if underline is not None:334 bits.append('\033[%dm' % (4 if underline else 24))335 if blink is not None:336 bits.append('\033[%dm' % (5 if blink else 25))
18 unmodified lines
modified:tests/test_utils.py+28 added
34 unmodified lines
35 click.echo(bytearray(b'\x1b[31mx\x1b[39m'), nl=False)36 assert out.getvalue() == b'\x1b[31mx\x1b[39m'373839def test_styling():40 examples = [41 ('x', dict(fg='black'), '\x1b[30mx\x1b[0m'),42 ('x', dict(fg='red'), '\x1b[31mx\x1b[0m'),43 ('x', dict(fg='green'), '\x1b[32mx\x1b[0m'),44 ('x', dict(fg='yellow'), '\x1b[33mx\x1b[0m'),45 ('x', dict(fg='blue'), '\x1b[34mx\x1b[0m'),46 ('x', dict(fg='magenta'), '\x1b[35mx\x1b[0m'),47 ('x', dict(fg='cyan'), '\x1b[36mx\x1b[0m'),48 ('x', dict(fg='white'), '\x1b[37mx\x1b[0m'),49 ('x', dict(bg='black'), '\x1b[40mx\x1b[0m'),50 ('x', dict(bg='red'), '\x1b[41mx\x1b[0m'),51 ('x', dict(bg='green'), '\x1b[42mx\x1b[0m'),52 ('x', dict(bg='yellow'), '\x1b[43mx\x1b[0m'),53 ('x', dict(bg='blue'), '\x1b[44mx\x1b[0m'),54 ('x', dict(bg='magenta'), '\x1b[45mx\x1b[0m'),55 ('x', dict(bg='cyan'), '\x1b[46mx\x1b[0m'),56 ('x', dict(bg='white'), '\x1b[47mx\x1b[0m'),57 ('foo bar', dict(blink=True), '\x1b[5mfoo bar\x1b[0m'),58 ('foo bar', dict(underline=True), '\x1b[4mfoo bar\x1b[0m'),59 ('foo bar', dict(bold=True), '\x1b[1mfoo bar\x1b[0m'),60 ('foo bar', dict(dim=True), '\x1b[2mfoo bar\x1b[0m'),61 ]62 for text, styles, ref in examples:63 assert click.style(text, **styles) == ref64 assert click.unstyle(ref) == text656667def test_filename_formatting():68 assert click.format_filename(b'foo.txt') == 'foo.txt'69 assert click.format_filename(b'/x/foo.txt') == '/x/foo.txt'70 assert click.format_filename(u'/x/foo.txt') == '/x/foo.txt'
3 unmodified lines