summaryrefslogtreecommitdiff
path: root/tests/test_ansi.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-06-27 13:37:53 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-06-27 13:37:53 -0400
commit212301954c0584ff250883784463c65252ced63d (patch)
tree39f165f3ec0037cfba790f8854ee6432896e51aa /tests/test_ansi.py
parent0dbb4d208a51b15ca814c00d2eceb43436d15dc1 (diff)
downloadcmd2-git-212301954c0584ff250883784463c65252ced63d.tar.gz
Added unit tests for ansi.py
Diffstat (limited to 'tests/test_ansi.py')
-rw-r--r--tests/test_ansi.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/test_ansi.py b/tests/test_ansi.py
new file mode 100644
index 00000000..0a48d7f5
--- /dev/null
+++ b/tests/test_ansi.py
@@ -0,0 +1,71 @@
+# coding=utf-8
+# flake8: noqa E302
+"""
+Unit testing for cmd2/ansi.py module
+"""
+import pytest
+from colorama import Fore, Back, Style
+
+import cmd2.ansi as ansi
+
+HELLO_WORLD = 'Hello, world!'
+
+
+def test_strip_ansi():
+ base_str = HELLO_WORLD
+ ansi_str = Fore.GREEN + base_str + Fore.RESET
+ 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
+ assert ansi.ansi_safe_wcswidth(ansi_str) != len(ansi_str)
+
+
+def test_style_none():
+ base_str = HELLO_WORLD
+ ansi_str = base_str
+ assert ansi.style(base_str) == ansi_str
+
+
+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
+
+
+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
+
+
+def test_style_bold():
+ base_str = HELLO_WORLD
+ ansi_str = Style.BRIGHT + base_str + Style.NORMAL
+ assert ansi.style(base_str, bold=True) == ansi_str
+
+
+def test_style_underline():
+ base_str = HELLO_WORLD
+ ansi_str = ansi.UNDERLINE_ENABLE + base_str + ansi.UNDERLINE_DISABLE
+ assert ansi.style(base_str, underline=True) == ansi_str
+
+
+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
+
+
+def test_style_color_not_exist():
+ base_str = HELLO_WORLD
+
+ with pytest.raises(ValueError):
+ ansi.style(base_str, fg='fake', bg='green')
+
+ with pytest.raises(ValueError):
+ ansi.style(base_str, fg='blue', bg='fake')