Skip to content

Commit a78e931

Browse files
committed
Added more unit tests for utils.py
1 parent ca27fac commit a78e931

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

tests/test_utils.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,52 @@
11
# coding=utf-8
22
"""
3-
Unit/functional testing for cmd2/utils.py module.
3+
Unit testing for cmd2/utils.py module.
44
55
Copyright 2018 Todd Leonhardt <[email protected]>
66
Released under MIT license, see LICENSE file
77
"""
88
from colorama import Fore
99
import cmd2.utils as cu
1010

11+
HELLO_WORLD = 'Hello, world!'
12+
1113

1214
def test_strip_ansi():
13-
base_str = 'Hello, world!'
15+
base_str = HELLO_WORLD
1416
ansi_str = Fore.GREEN + base_str + Fore.RESET
1517
assert base_str != ansi_str
1618
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

Comments
 (0)