1- # -*- coding: utf-8 -*-
2-
1+ # pylint: disable=missing-docstring
32import cmudict
43
54
65def test_dict_stream ():
7- EXPECTED_LENGTH = 135166
6+ expected_length = 135166
87 # borrowed from pronouncingpy to ensure compatibility
98 pronunciations = list ()
109 filehandle = cmudict .dict_stream ()
@@ -15,24 +14,22 @@ def test_dict_stream():
1514 word , phones = line .split (" " , 1 )
1615 pronunciations .append ((word .split ("(" , 1 )[0 ].lower (), phones ))
1716 filehandle .close ()
18- assert len (pronunciations ) == EXPECTED_LENGTH
17+ assert len (pronunciations ) == expected_length
1918
2019
2120def test_dict_string ():
22- EXPECTED_LENGTH = 3618488
21+ expected_length = 3618488
2322 dict_string = cmudict .dict_string ()
24- LENGTH = len (dict_string )
25- if EXPECTED_LENGTH != LENGTH :
23+ actual_length = len (dict_string )
24+ if expected_length != actual_length :
2625 raise AssertionError (
27- "cmudict.dict_string(): Expected {0} length, got {1}." .format (
28- EXPECTED_LENGTH , LENGTH
29- )
26+ f"cmudict.dict_string(): Expected { expected_length } length, got { actual_length } ."
3027 )
3128
3229
3330def test_dict_comments ():
34- DICT = cmudict .dict ()
35- EXPECTED_DICT = {
31+ actual_dict = cmudict .dict ()
32+ expected_dict = {
3633 "d'artagnan" : [["D" , "AH0" , "R" , "T" , "AE1" , "NG" , "Y" , "AH0" , "N" ]],
3734 "danglar" : [["D" , "AH0" , "NG" , "L" , "AA1" , "R" ]],
3835 "danglars" : [["D" , "AH0" , "NG" , "L" , "AA1" , "R" , "Z" ]],
@@ -41,86 +38,79 @@ def test_dict_comments():
4138 "porthos" : [["P" , "AO0" , "R" , "T" , "AO1" , "S" ]],
4239 "spieth" : [["S" , "P" , "IY1" , "TH" ], ["S" , "P" , "AY1" , "AH0" , "TH" ]],
4340 }
44- for TEST_WORD in EXPECTED_DICT :
45- EXPECTED_PRONOUNCIATION = EXPECTED_DICT [TEST_WORD ]
46- PRONUNCIATION = DICT [TEST_WORD ]
47- if EXPECTED_PRONOUNCIATION != PRONUNCIATION :
41+ for test_word , expected_pronunciation in expected_dict .items ():
42+ actual_pronunciation = actual_dict [test_word ]
43+ if expected_pronunciation != actual_pronunciation :
4844 raise AssertionError (
49- 'cmudict.dict(): Expected "{0}", got "{1}".' . format (
50- EXPECTED_PRONOUNCIATION , PRONUNCIATION
51- )
45+ f"""
46+ cmudict.dict(): Expected " { expected_pronunciation } ", got " { actual_pronunciation } ".
47+ """
5248 )
5349
5450
5551def test_phones ():
56- EXPECTED_SIZE = 39
52+ expected_size = 39
5753 phones = cmudict .phones ()
58- SIZE = len (phones )
59- if EXPECTED_SIZE != SIZE :
54+ actual_size = len (phones )
55+ if expected_size != actual_size :
6056 raise AssertionError (
61- "cmudict.phones(): Expected {0 } keys, got {1 }." . format ( EXPECTED_SIZE , SIZE )
57+ f "cmudict.phones(): Expected { expected_size } keys, got { actual_size } ."
6258 )
6359
6460
6561def test_phones_string ():
66- EXPECTED_LENGTH = 382
62+ expected_length = 382
6763 phones_string = cmudict .phones_string ()
68- LENGTH = len (phones_string )
69- if EXPECTED_LENGTH != LENGTH :
64+ actual_length = len (phones_string )
65+ if expected_length != actual_length :
7066 raise AssertionError (
71- "cmudict.phones_string(): Expected {0} length, got {1}." .format (
72- EXPECTED_LENGTH , LENGTH
73- )
67+ f"cmudict.phones_string(): Expected { expected_length } length, got { actual_length } ."
7468 )
7569
7670
7771def test_symbols ():
78- EXPECTED_SIZE = 84
72+ expected_size = 84
7973 symbols = cmudict .symbols ()
80- SIZE = len (symbols )
81- if EXPECTED_SIZE != SIZE :
74+ actual_size = len (symbols )
75+ if expected_size != actual_size :
8276 raise AssertionError (
83- "cmudict.symbols(): Expected {0 } keys, got {1 }." . format ( EXPECTED_SIZE , SIZE )
77+ f "cmudict.symbols(): Expected { expected_size } keys, got { actual_size } ."
8478 )
8579
8680
8781def test_symbols_string ():
88- EXPECTED_LENGTH = 281
82+ expected_length = 281
8983 symbols_string = cmudict .symbols_string ()
90- LENGTH = len (symbols_string )
91- if EXPECTED_LENGTH != LENGTH :
84+ actual_length = len (symbols_string )
85+ if expected_length != actual_length :
9286 raise AssertionError (
93- "cmudict.symbols_string(): Expected {0} length, got {1}." .format (
94- EXPECTED_LENGTH , LENGTH
95- )
87+ f"cmudict.symbols_string(): Expected { expected_length } length, got { actual_length } ."
9688 )
9789
9890
9991def test_vp ():
100- EXPECTED_SIZE = 52
92+ expected_size = 52
10193 vp = cmudict .vp ()
102- SIZE = len (vp )
103- if EXPECTED_SIZE != SIZE :
94+ actual_size = len (vp )
95+ if expected_size != actual_size :
10496 raise AssertionError (
105- "cmudict.vp(): Expected {0 } keys, got {1 }." . format ( EXPECTED_SIZE , SIZE )
97+ f "cmudict.vp(): Expected { expected_size } keys, got { actual_size } ."
10698 )
10799
108100
109101def test_vp_string ():
110- EXPECTED_LENGTH = 1747
102+ expected_length = 1747
111103 vp_string = cmudict .vp_string ()
112- LENGTH = len (vp_string )
113- if EXPECTED_LENGTH != LENGTH :
104+ actual_length = len (vp_string )
105+ if expected_length != actual_length :
114106 raise AssertionError (
115- "cmudict.vp_string(): Expected {0} length, got {1}." .format (
116- EXPECTED_LENGTH , LENGTH
117- )
107+ f"cmudict.vp_string(): Expected { expected_length } length, got { actual_length } ."
118108 )
119109
120110
121111def test_vp_comments ():
122- VP = cmudict .vp ()
123- EXPECTED_VP = {
112+ actual_vp = cmudict .vp ()
113+ expected_vp = {
124114 "!exclamation-point" : [
125115 [
126116 "EH2" ,
@@ -226,24 +216,21 @@ def test_vp_comments():
226216 "'quote" : [["K" , "W" , "OW1" , "T" ]],
227217 "'apostrophe" : [["AH0" , "P" , "AA1" , "S" , "T" , "R" , "AH0" , "F" , "IY0" ]],
228218 }
229- for PUNCTUATION in EXPECTED_VP :
230- EXPECTED_PRONOUNCIATION = EXPECTED_VP [PUNCTUATION ]
231- PRONUNCIATION = VP [PUNCTUATION ]
232- if EXPECTED_PRONOUNCIATION != PRONUNCIATION :
219+ for test_punctuation , expected_pronounciation in expected_vp .items ():
220+ actual_pronounciation = actual_vp [test_punctuation ]
221+ if expected_pronounciation != actual_pronounciation :
233222 raise AssertionError (
234- 'cmudict.vp(): Expected "{0}", got "{1}".' . format (
235- EXPECTED_PRONOUNCIATION , PRONUNCIATION
236- )
223+ f"""
224+ cmudict.vp(): Expected " { expected_pronounciation } ", got " { actual_pronounciation } ".
225+ """
237226 )
238227
239228
240229def test_license_string ():
241- EXPECTED_LENGTH = 1754
230+ expected_length = 1754
242231 license_string = cmudict .license_string ()
243- LENGTH = len (license_string )
244- if EXPECTED_LENGTH != LENGTH :
232+ actual_length = len (license_string )
233+ if expected_length != actual_length :
245234 raise AssertionError (
246- "cmudict.license_string(): Expected {0} length, got {1}." .format (
247- EXPECTED_LENGTH , LENGTH
248- )
235+ f"cmudict.license_string(): Expected { expected_length } length, got { actual_length } ."
249236 )
0 commit comments