diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-09-16 09:09:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-09-16 09:09:35 +0000 |
commit | 0dfe1c9e2780469e3a4696e8fb3e6f717a7ebeb7 (patch) | |
tree | a0b651b55ea02e3b00bbc5eedba566fdd6bd7c08 /tests/test_width_and_alignment/test_visible_width.py | |
parent | Initial commit. (diff) | |
download | terminaltables-0dfe1c9e2780469e3a4696e8fb3e6f717a7ebeb7.tar.xz terminaltables-0dfe1c9e2780469e3a4696e8fb3e6f717a7ebeb7.zip |
Adding upstream version 3.1.0.upstream/3.1.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/test_width_and_alignment/test_visible_width.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test_width_and_alignment/test_visible_width.py b/tests/test_width_and_alignment/test_visible_width.py new file mode 100644 index 0000000..79cebcb --- /dev/null +++ b/tests/test_width_and_alignment/test_visible_width.py @@ -0,0 +1,59 @@ +# coding: utf-8 +"""Test function in module.""" + +import pytest +from colorama import Fore +from colorclass import Color +from termcolor import colored + +from terminaltables.width_and_alignment import visible_width + + +@pytest.mark.parametrize('string,expected', [ + # str + ('hello, world', 12), + ('世界你好', 8), + ('蓝色', 4), + ('שלום', 4), + ('معرب', 4), + ('hello 世界', 10), + + # str+ansi + ('\x1b[34mhello, world\x1b[39m', 12), + ('\x1b[34m世界你好\x1b[39m', 8), + ('\x1b[34m蓝色\x1b[39m', 4), + ('\x1b[34mשלום\x1b[39m', 4), + ('\x1b[34mمعرب\x1b[39m', 4), + ('\x1b[34mhello 世界\x1b[39m', 10), + + # colorclass + (Color(u'{blue}hello, world{/blue}'), 12), + (Color(u'{blue}世界你好{/blue}'), 8), + (Color(u'{blue}蓝色{/blue}'), 4), + (Color(u'{blue}שלום{/blue}'), 4), + (Color(u'{blue}معرب{/blue}'), 4), + (Color(u'{blue}hello 世界{/blue}'), 10), + + # colorama + (Fore.BLUE + 'hello, world' + Fore.RESET, 12), + (Fore.BLUE + '世界你好' + Fore.RESET, 8), + (Fore.BLUE + '蓝色' + Fore.RESET, 4), + (Fore.BLUE + 'שלום' + Fore.RESET, 4), + (Fore.BLUE + 'معرب' + Fore.RESET, 4), + (Fore.BLUE + 'hello 世界' + Fore.RESET, 10), + + # termcolor + (colored('hello, world', 'blue'), 12), + (colored('世界你好', 'blue'), 8), + (colored('蓝色', 'blue'), 4), + (colored('שלום', 'blue'), 4), + (colored('معرب', 'blue'), 4), + (colored('hello 世界', 'blue'), 10), +]) +def test(string, expected): + """Test function with different color libraries. + + :param str string: Input string to measure. + :param int expected: Expected visible width of string (some characters are len() == 1 but take up 2 spaces). + """ + assert visible_width(string) == expected |