diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-06-30 17:59:38 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-06-30 17:59:38 -0400 |
commit | 5074f2573b08f4f44ab3a41ac7a450c4844dcd3d (patch) | |
tree | 731897fe25f9fd3beaeb3e8541a16a8226558545 /tests | |
parent | 6787a3d412a1fba8783dc393d8d4af124220f4b9 (diff) | |
download | cmd2-git-5074f2573b08f4f44ab3a41ac7a450c4844dcd3d.tar.gz |
Initial changes for encapsulation of colorama usage within ansi.py
Changes include:
- ansi.py is now the only cmd2 code which depends on colorama
- cmd2 tests no longer rely on colorama
- Added new functions to ansi.py:
- async_alert_str()
- set_title_str
- Added unit test for set_title_str
TODO:
- Refactor async_alert_str so cursor position is passed in and import from rl_utils is no longer required
- Add unit test(s) for async_alert_str
- Refactor FG_COLORS and BG_COLORS in ansi.py to not use constants from colorama
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_ansi.py | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/tests/test_ansi.py b/tests/test_ansi.py index bf628ef0..53c917d5 100644 --- a/tests/test_ansi.py +++ b/tests/test_ansi.py @@ -4,7 +4,6 @@ Unit testing for cmd2/ansi.py module """ import pytest -from colorama import Fore, Back, Style import cmd2.ansi as ansi @@ -13,14 +12,14 @@ HELLO_WORLD = 'Hello, world!' def test_strip_ansi(): base_str = HELLO_WORLD - ansi_str = Fore.GREEN + base_str + Fore.RESET + ansi_str = ansi.style(base_str, fg='green') assert base_str != ansi_str assert base_str == ansi.strip_ansi(ansi_str) def test_ansi_safe_wcswidth(): base_str = HELLO_WORLD - ansi_str = Fore.GREEN + base_str + Fore.RESET + ansi_str = ansi.style(base_str, fg='green') assert ansi.ansi_safe_wcswidth(ansi_str) != len(ansi_str) @@ -32,19 +31,21 @@ def test_style_none(): def test_style_fg(): base_str = HELLO_WORLD - ansi_str = Fore.BLUE + base_str + Fore.RESET - assert ansi.style(base_str, fg='blue') == ansi_str + fg_color = 'blue' + ansi_str = ansi.FG_COLORS[fg_color] + base_str + ansi.FG_RESET + assert ansi.style(base_str, fg=fg_color) == ansi_str def test_style_bg(): base_str = HELLO_WORLD - ansi_str = Back.GREEN + base_str + Back.RESET - assert ansi.style(base_str, bg='green') == ansi_str + bg_color = 'green' + ansi_str = ansi.BG_COLORS[bg_color] + base_str + ansi.BG_RESET + assert ansi.style(base_str, bg=bg_color) == ansi_str def test_style_bold(): base_str = HELLO_WORLD - ansi_str = Style.BRIGHT + base_str + Style.NORMAL + ansi_str = ansi.BRIGHT + base_str + ansi.NORMAL assert ansi.style(base_str, bold=True) == ansi_str @@ -56,9 +57,11 @@ def test_style_underline(): def test_style_multi(): base_str = HELLO_WORLD - ansi_str = Fore.BLUE + Back.GREEN + Style.BRIGHT + ansi.UNDERLINE_ENABLE + \ - base_str + Fore.RESET + Back.RESET + Style.NORMAL + ansi.UNDERLINE_DISABLE - assert ansi.style(base_str, fg='blue', bg='green', bold=True, underline=True) == ansi_str + fg_color = 'blue' + bg_color = 'green' + ansi_str = ansi.FG_COLORS[fg_color] + ansi.BG_COLORS[bg_color] + ansi.BRIGHT + ansi.UNDERLINE_ENABLE + \ + base_str + ansi.FG_RESET + ansi.BG_RESET + ansi.NORMAL + ansi.UNDERLINE_DISABLE + assert ansi.style(base_str, fg=fg_color, bg=bg_color, bold=True, underline=True) == ansi_str def test_style_color_not_exist(): @@ -72,7 +75,8 @@ def test_style_color_not_exist(): def test_fg_lookup_exist(): - assert ansi.fg_lookup('green') == Fore.GREEN + fg_color = 'green' + assert ansi.fg_lookup(fg_color) == ansi.FG_COLORS[fg_color] def test_fg_lookup_nonexist(): @@ -81,9 +85,17 @@ def test_fg_lookup_nonexist(): def test_bg_lookup_exist(): - assert ansi.bg_lookup('green') == Back.GREEN + bg_color = 'green' + assert ansi.bg_lookup(bg_color) == ansi.BG_COLORS[bg_color] def test_bg_lookup_nonexist(): with pytest.raises(ValueError): ansi.bg_lookup('bar') + + +def test_set_title_str(): + OSC = '\033]' + BEL = '\007' + title = HELLO_WORLD + assert ansi.set_title_str(title) == OSC + '2;' + title + BEL |