|
1 | 1 | # coding=utf-8
|
2 | 2 | """
|
3 |
| -Unit/functional testing for cmd2/utils.py module. |
| 3 | +Unit testing for cmd2/utils.py module. |
4 | 4 |
|
5 | 5 | Copyright 2018 Todd Leonhardt <[email protected]>
|
6 | 6 | Released under MIT license, see LICENSE file
|
7 | 7 | """
|
8 | 8 | from colorama import Fore
|
9 | 9 | import cmd2.utils as cu
|
10 | 10 |
|
| 11 | +HELLO_WORLD = 'Hello, world!' |
| 12 | + |
11 | 13 |
|
12 | 14 | def test_strip_ansi():
|
13 |
| - base_str = 'Hello, world!' |
| 15 | + base_str = HELLO_WORLD |
14 | 16 | ansi_str = Fore.GREEN + base_str + Fore.RESET
|
15 | 17 | assert base_str != ansi_str
|
16 | 18 | assert base_str == cu.strip_ansi(ansi_str)
|
| 19 | + |
| 20 | +def test_strip_quotes_no_quotes(): |
| 21 | + base_str = HELLO_WORLD |
| 22 | + stripped = cu.strip_quotes(base_str) |
| 23 | + assert base_str == stripped |
| 24 | + |
| 25 | +def test_strip_quotes_with_quotes(): |
| 26 | + base_str = '"' + HELLO_WORLD + '"' |
| 27 | + stripped = cu.strip_quotes(base_str) |
| 28 | + assert stripped == HELLO_WORLD |
| 29 | + |
| 30 | +def test_remove_duplicates_no_duplicates(): |
| 31 | + no_dups = [5, 4, 3, 2, 1] |
| 32 | + assert cu.remove_duplicates(no_dups) == no_dups |
| 33 | + |
| 34 | +def test_remove_duplicates_with_duplicates(): |
| 35 | + duplicates = [1, 1, 2, 3, 9, 9, 7, 8] |
| 36 | + assert cu.remove_duplicates(duplicates) == [1, 2, 3, 9, 7, 8] |
| 37 | + |
| 38 | +def test_unicode_normalization(): |
| 39 | + s1 = 'café' |
| 40 | + s2 = 'cafe\u0301' |
| 41 | + assert s1 != s2 |
| 42 | + assert cu.norm_fold(s1) == cu.norm_fold(s2) |
| 43 | + |
| 44 | +def test_unicode_casefold(): |
| 45 | + micro = 'µ' |
| 46 | + micro_cf = micro.casefold() |
| 47 | + assert micro != micro_cf |
| 48 | + assert cu.norm_fold(micro) == cu.norm_fold(micro_cf) |
| 49 | + |
| 50 | +def test_alphabetical_sort(): |
| 51 | + my_list = ['café', 'µ', 'A' , 'micro', 'unity', 'cafeteria'] |
| 52 | + assert cu.alphabetical_sort(my_list) == ['A', 'cafeteria', 'café', 'micro', 'unity', 'µ'] |
0 commit comments