generated from caltechlibrary/py-cli-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_name_utils.py
65 lines (53 loc) · 2 KB
/
test_name_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# =============================================================================
# @file test_name_utils.py
# @brief Py.test cases for parts of name_utils.py
# @created 2023-03-02
# @license Please see the file named LICENSE in the project directory
# @website https://github.com/caltechlibrary/iga
# =============================================================================
from iga.name_utils import (
_plain_name,
_plain_word,
_first_letters_upcased,
contains_cjk,
flattened_name,
)
RAW_NAMES = [
('偏右', ''),
('王爵nice', 'nice'),
('勾三股四', ''),
('TZ | 天猪', 'TZ'),
("Maciej Małecki", "Maciej Małecki"),
("Gabriel Falcão", "Gabriel Falcão"),
('Mu-An ✌️ Chiou', 'Mu-An Chiou'),
('Zip J. Zippy', 'Zip J. Zippy'),
('Zip J. Zippy [the Zip]', 'Zip J. Zippy'),
('Zip J. Zippy-Zip', 'Zip J. Zippy-Zip'),
]
def test_contains_cjk():
assert contains_cjk('偏右')
assert contains_cjk('王爵nice')
assert not contains_cjk('test')
assert not contains_cjk('éä')
def test_flattened_name():
assert flattened_name('foo bar') == 'foo bar'
assert flattened_name(['foo', 'bar']) == 'foo bar'
assert flattened_name(['Foo J.', 'Bar']) == 'Foo J. Bar'
assert flattened_name(['Foo', 'J.', 'Bar']) == 'Foo J. Bar'
def test_plain_name():
for original, cleaned in RAW_NAMES:
assert _plain_name(original) == cleaned
def test_plain_word():
assert _plain_word('foo')
assert _plain_word('FOO')
assert _plain_word('Foo')
assert not _plain_word('foo bar')
assert not _plain_word('foo1')
def test_upcase_first_letter():
assert _first_letters_upcased('aBC dEF') == 'ABC DEF'
assert _first_letters_upcased('Abc Def') == 'Abc Def'
assert _first_letters_upcased('abc def') == 'Abc Def'
assert _first_letters_upcased('abc DEF') == 'Abc DEF'
assert _first_letters_upcased('abc dEF') == 'Abc DEF'
assert _first_letters_upcased('a') == 'A'
assert _first_letters_upcased('A') == 'A'