-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_methods.py
302 lines (187 loc) · 6.76 KB
/
test_methods.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import pytest
from cstring import cstring
def test_count():
target = cstring('hello, world')
assert target.count(cstring('l')) == 3
def test_count_start():
target = cstring('hello, world')
assert target.count(cstring('l'), 10) == 1
def test_count_end():
target = cstring('hello, world')
assert target.count(cstring('l'), 0, 4) == 2
def test_count_str_unicode():
target = cstring('🙂 🙃 🙂 🙂 🙃 🙂 🙂')
assert target.count('🙂') == 5
def test_find():
target = cstring('hello')
assert target.find('lo') == 3
def test_find_with_start():
target = cstring('hello')
assert target.find('lo', 3) == 3
def test_find_missing():
target = cstring('hello')
assert target.find('lo', 0, 4) == -1
def test_index():
target = cstring('hello')
assert target.index('lo') == 3
def test_index_with_start():
target = cstring('hello')
assert target.index('lo', 3) == 3
def test_index_missing():
target = cstring('hello')
with pytest.raises(ValueError):
return target.index('lo', 0, 4)
def test_isalnum_True():
target = cstring('hello123')
assert target.isalnum() == True
def test_isalnum_False():
target = cstring('hello_123')
assert target.isalnum() == False
def test_isalpha_True():
target = cstring('hello')
assert target.isalpha() == True
def test_isalpha_False():
target = cstring('hello123')
assert target.isalpha() == False
def test_isdigit_True():
target = cstring('123')
assert target.isdigit() == True
def test_isdigit_False():
target = cstring('123.4')
assert target.isdigit() == False
def test_islower_numeric():
target = cstring('123')
assert target.islower() == False
def test_islower_alnum_lc():
target = cstring('hello123')
assert target.islower() == True
def test_islower_alnum_uc():
target = cstring('Hello123')
assert target.islower() == False
def test_isprintable_True():
target = cstring('hello, world')
assert target.isprintable() == True
def test_isprintable_False():
target = cstring(b'hello, world\x01')
assert target.isprintable() == False
def test_isspace_empty():
target = cstring('')
assert target.isspace() == False
def test_isspace_True():
target = cstring('\t\n ')
assert target.isspace() == True
def test_isspace_False():
target = cstring('hello, world\n')
assert target.isspace() == False
def test_isupper_numeric():
target = cstring('123')
assert target.isupper() == False
def test_isupper_alnum_uc():
target = cstring('HELLO123')
assert target.isupper() == True
def test_isupper_alnum_lc():
target = cstring('HELLo123')
assert target.isupper() == False
def test_join():
sep = cstring(', ')
items = [cstring('hello'), cstring('world')]
assert sep.join(items) == cstring('hello, world')
def test_lower():
target = cstring('HELLO123')
assert target.lower() == cstring('hello123')
def test_rfind():
target = cstring('hello')
assert target.rfind('o') == 4
def test_rfind_empty():
target = cstring('hello')
assert target.rfind('') == 5
def test_rfind_with_start():
target = cstring('hello')
assert target.rfind('lo', 3) == 3
def test_rfind_missing():
target = cstring('hello')
assert target.rfind('lo', 0, 4) == -1
def test_rindex():
target = cstring('hello')
assert target.rindex('o') == 4
def test_rindex_empty():
target = cstring('hello')
assert target.rindex('') == 5
def test_rindex_with_start():
target = cstring('hello')
assert target.rindex('lo', 3) == 3
def test_rindex_missing():
target = cstring('hello')
with pytest.raises(ValueError):
return target.rindex('lo', 0, 4)
def test_strip_noargs():
target = cstring('\r\n\n\n\t hello, world \t\r\n\n ')
assert target.strip() == cstring('hello, world')
def test_strip_None():
target = cstring('\r\n\n\n\t hello, world \t\r\n\n ')
assert target.strip(None) == cstring('hello, world')
def test_strip_arg():
target = cstring('hello, world')
assert target.strip('held') == cstring('o, wor')
def test_lstrip_arg():
target = cstring('hello, world')
assert target.lstrip('held') == cstring('o, world')
def test_rstrip_arg():
target = cstring('hello, world')
assert target.rstrip('held') == cstring('hello, wor')
def test_partition():
target = cstring('hello, world')
result = (cstring('hello'), cstring(', '), cstring('world'))
assert target.partition(cstring(', ')) == result
def test_partition_sep_not_found():
target = cstring('hello, world')
result = (cstring('hello, world'), cstring(''), cstring(''))
assert target.partition(cstring(': ')) == result
def test_rpartition():
target = cstring('hello, world')
result = (cstring('hello, wor'), cstring('l'), cstring('d'))
assert target.rpartition(cstring('l')) == result
def test_rpartition_sep_not_found():
target = cstring('hello, world')
result = (cstring(''), cstring(''), cstring('hello, world'))
assert target.rpartition(cstring(': ')) == result
def test_split():
assert cstring('hello, world').split(cstring(', ')) == [cstring('hello'), cstring('world')]
assert cstring('1,2,3').split(cstring(',')) == [
cstring('1'), cstring('2'), cstring('3')]
assert cstring('hello, world').split() == [cstring('hello,'), cstring('world')]
assert cstring('hello\t \n world').split() == [cstring('hello'), cstring('world')]
assert cstring('1,2,3').split(cstring(','), maxsplit=1) == [
cstring('1'), cstring('2,3')]
assert cstring('1 2 3').split(maxsplit=1) == [
cstring('1'), cstring('2 3')]
def test_startswith():
target = cstring('hello, world')
assert target.startswith('hello,') is True
def test_startswith_not():
target = cstring('hello, world')
assert target.startswith('world') is False
def test_startswith_with_start():
target = cstring('hello, world')
assert target.startswith('world', 7) is True
def test_startswith_with_start_and_end():
target = cstring('hello, world')
assert target.startswith('wo', 7, 8) is False
def test_endswith():
target = cstring('hello, world')
assert target.endswith('world') is True
def test_endswith_not():
target = cstring('hello, world')
assert target.endswith('hello') is False
def test_endswith_with_start():
target = cstring('hello, world')
assert target.endswith('world', 8) is False
def test_endswith_with_start_and_end():
target = cstring('hello, world')
assert target.endswith('wo', 7, 9) is True
def test_upper():
target = cstring('hello123')
assert target.upper() == cstring('HELLO123')
def test_swapcase():
target = cstring('hElLo, WoRlD 123')
assert target.swapcase() == cstring('HeLlO, wOrLd 123')