diff options
author | xNinjaKittyx <xNinjaKittyx@users.noreply.github.com> | 2020-12-15 17:21:33 -0800 |
---|---|---|
committer | xNinjaKittyx <xNinjaKittyx@users.noreply.github.com> | 2020-12-15 18:20:13 -0800 |
commit | 9aa54a5b27468d61337528cb1e1b5b9b11a80978 (patch) | |
tree | 567693115cc101efb9254a96d96d80e9f9ccd557 /tests/test_ansi.py | |
parent | 03c65c60b39e369958b056c5c844d36d515c8a63 (diff) | |
download | cmd2-git-ci_improvements.tar.gz |
Adds pre-commit config to run various lintersci_improvements
This ads black, isort, pyupgrade, and flake8 to pre-commit-config.yaml
There are also some small changes to travis.yml and tasks.py to reduce
some repeated configurations that should be consolidated into
setup.cfg. Most other changes are automated by the linter scripts.
Diffstat (limited to 'tests/test_ansi.py')
-rw-r--r-- | tests/test_ansi.py | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/tests/test_ansi.py b/tests/test_ansi.py index 4a28b1a0..8051b248 100644 --- a/tests/test_ansi.py +++ b/tests/test_ansi.py @@ -65,11 +65,19 @@ def test_style_multi(): base_str = HELLO_WORLD fg_color = 'blue' bg_color = 'green' - ansi_str = (ansi.fg[fg_color].value + ansi.bg[bg_color].value + - ansi.INTENSITY_BRIGHT + ansi.INTENSITY_DIM + ansi.UNDERLINE_ENABLE + - base_str + - ansi.FG_RESET + ansi.BG_RESET + - ansi.INTENSITY_NORMAL + ansi.INTENSITY_NORMAL + ansi.UNDERLINE_DISABLE) + ansi_str = ( + ansi.fg[fg_color].value + + ansi.bg[bg_color].value + + ansi.INTENSITY_BRIGHT + + ansi.INTENSITY_DIM + + ansi.UNDERLINE_ENABLE + + base_str + + ansi.FG_RESET + + ansi.BG_RESET + + ansi.INTENSITY_NORMAL + + ansi.INTENSITY_NORMAL + + ansi.UNDERLINE_DISABLE + ) assert ansi.style(base_str, fg=fg_color, bg=bg_color, bold=True, dim=True, underline=True) == ansi_str @@ -110,14 +118,23 @@ def test_set_title_str(): assert ansi.set_title_str(title) == OSC + '2;' + title + BEL -@pytest.mark.parametrize('cols, prompt, line, cursor, msg, expected', [ - (127, '(Cmd) ', 'help his', 12, ansi.style('Hello World!', fg='magenta'), '\x1b[2K\r\x1b[35mHello World!\x1b[39m'), - (127, '\n(Cmd) ', 'help ', 5, 'foo', '\x1b[2K\x1b[1A\x1b[2K\rfoo'), - (10, '(Cmd) ', 'help history of the american republic', 4, 'boo', '\x1b[3B\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\rboo') -]) +@pytest.mark.parametrize( + 'cols, prompt, line, cursor, msg, expected', + [ + (127, '(Cmd) ', 'help his', 12, ansi.style('Hello World!', fg='magenta'), '\x1b[2K\r\x1b[35mHello World!\x1b[39m'), + (127, '\n(Cmd) ', 'help ', 5, 'foo', '\x1b[2K\x1b[1A\x1b[2K\rfoo'), + ( + 10, + '(Cmd) ', + 'help history of the american republic', + 4, + 'boo', + '\x1b[3B\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\rboo', + ), + ], +) def test_async_alert_str(cols, prompt, line, cursor, msg, expected): - alert_str = ansi.async_alert_str(terminal_columns=cols, prompt=prompt, line=line, cursor_offset=cursor, - alert_msg=msg) + alert_str = ansi.async_alert_str(terminal_columns=cols, prompt=prompt, line=line, cursor_offset=cursor, alert_msg=msg) assert alert_str == expected @@ -127,19 +144,23 @@ def test_cast_color_as_str(): def test_color_str_building(): - from cmd2.ansi import fg, bg + from cmd2.ansi import bg, fg + assert fg.blue + "hello" == fg.blue.value + "hello" assert bg.blue + "hello" == bg.blue.value + "hello" assert fg.blue + "hello" + fg.reset == fg.blue.value + "hello" + fg.reset.value assert bg.blue + "hello" + bg.reset == bg.blue.value + "hello" + bg.reset.value - assert fg.blue + bg.white + "hello" + fg.reset + bg.reset == \ - fg.blue.value + bg.white.value + "hello" + fg.reset.value + bg.reset.value + assert ( + fg.blue + bg.white + "hello" + fg.reset + bg.reset + == fg.blue.value + bg.white.value + "hello" + fg.reset.value + bg.reset.value + ) def test_color_nonunique_values(): class Matching(ansi.ColorBase): magenta = ansi.fg_lookup('magenta') purple = ansi.fg_lookup('magenta') + assert sorted(Matching.colors()) == ['magenta', 'purple'] |