@@ -28,7 +28,7 @@ def test_domain_extension_is_required(self):
28
28
self .assertFalse (is_email ('name@site' ))
29
29
self .assertFalse (is_email ('name@site.' ))
30
30
31
- def test_domain_extension_must_be_letters_only_from_2_to_4_chars (self ):
31
+ def test_domain_extension_should_be_letters_only_from_2_to_4_chars (self ):
32
32
self .assertFalse (is_email ('me@foo.123' ))
33
33
self .assertFalse (is_email ('me@foo.c' ))
34
34
self .assertFalse (is_email ('me@foo.!!' ))
@@ -128,15 +128,15 @@ def test_string_cannot_be_empty(self):
128
128
def test_string_cannot_contain_letters (self ):
129
129
self .assertFalse (is_credit_card ('not a credit card for sure' ))
130
130
131
- def test_numbers_in_string_must_be_15_at_least (self ):
131
+ def test_numbers_in_string_should_be_15_at_least (self ):
132
132
self .assertFalse (is_credit_card ('1' * 14 ))
133
133
134
- def test_must_accept_any_valid_card_number_if_type_is_not_specified (self ):
134
+ def test_should_accept_any_valid_card_number_if_type_is_not_specified (self ):
135
135
for card_type in self .sample_cards :
136
136
for card_number in self .sample_cards [card_type ]:
137
137
self .assertTrue (is_credit_card (card_number ), 'Invalid card: %s (%s)' % (card_number , card_type ))
138
138
139
- def test_must_validate_only_specific_card_type_if_specified (self ):
139
+ def test_should_validate_only_specific_card_type_if_specified (self ):
140
140
for card_type in self .sample_cards :
141
141
for card_number in self .sample_cards [card_type ]:
142
142
self .assertTrue (
@@ -156,68 +156,89 @@ def test_cannot_provide_unsupported_card_type(self):
156
156
157
157
158
158
class IsCamelCaseTestCase (TestCase ):
159
- def test_raises_type_error_if_provided_object_is_not_a_string (self ):
159
+ def test_cannot_handle_non_string_objects (self ):
160
160
self .assertRaises (TypeError , lambda : is_camel_case (None ))
161
161
self .assertRaises (TypeError , lambda : is_camel_case (False ))
162
162
self .assertRaises (TypeError , lambda : is_camel_case (0 ))
163
163
self .assertRaises (TypeError , lambda : is_camel_case ([]))
164
164
self .assertRaises (TypeError , lambda : is_camel_case ({'a' : 1 }))
165
165
166
- def test_returns_false_for_empty_string (self ):
166
+ def test_string_cannot_be_empty (self ):
167
167
self .assertFalse (is_camel_case ('' ))
168
+ self .assertFalse (is_camel_case (' ' ))
168
169
169
- def test_returns_false_for_lowercase_string (self ):
170
+ def test_string_cannot_be_all_lowercase (self ):
170
171
self .assertFalse (is_camel_case ('lowercase' ))
171
172
172
- def test_returns_false_for_uppercase_string (self ):
173
+ def test_string_cannot_be_all_uppercase (self ):
173
174
self .assertFalse (is_camel_case ('UPPERCASE' ))
174
175
175
- def test_returns_false_if_string_has_spaces (self ):
176
+ def test_string_cannot_contain_spaces (self ):
176
177
self .assertFalse (is_camel_case (' CamelCase ' ))
177
178
178
- def test_returns_false_if_string_starts_with_number (self ):
179
+ def test_string_cannot_start_with_number (self ):
179
180
self .assertFalse (is_camel_case ('1000Times' ))
180
181
181
- def test_returns_false_if_string_contains_invalid_chars (self ):
182
+ def test_string_cannot_contain_invalid_chars (self ):
182
183
self .assertFalse (is_camel_case ('<#NotCamelCaseHere!?>' ))
183
184
184
- def test_returns_true_if_camel_case (self ):
185
+ def test_should_accept_valid_camel_case_string (self ):
185
186
self .assertTrue (is_camel_case ('Camel' ))
186
187
self .assertTrue (is_camel_case ('CamelCase' ))
188
+ self .assertTrue (is_camel_case ('camelCase' ))
187
189
self .assertTrue (is_camel_case ('CamelCaseTOO' ))
188
190
self .assertTrue (is_camel_case ('ACamelCaseIsAlsoAStringLikeThis1' ))
189
191
self .assertTrue (is_camel_case ('camelCaseStartingLowerEndingUPPER' ))
190
192
191
193
192
194
class IsSnakeCaseTestCase (TestCase ):
193
- def test_raises_type_error_if_provided_object_is_not_a_string (self ):
195
+ def test_cannot_handle_non_string_objects (self ):
194
196
self .assertRaises (TypeError , lambda : is_snake_case (None ))
195
197
self .assertRaises (TypeError , lambda : is_snake_case (False ))
196
198
self .assertRaises (TypeError , lambda : is_snake_case (0 ))
197
199
self .assertRaises (TypeError , lambda : is_snake_case ([]))
198
200
self .assertRaises (TypeError , lambda : is_snake_case ({'a' : 1 }))
199
201
200
- def test_returns_true_if_custom_separator_is_used (self ):
201
- s = 'snake-string-with-dashes'
202
- self .assertFalse (is_snake_case (s ))
203
- self .assertTrue (is_snake_case (s , separator = '-' ))
204
-
205
- def test_returns_false_for_no_snake_string (self ):
202
+ def test_string_cannot_be_blank (self ):
206
203
self .assertFalse (is_snake_case ('' ))
207
- self .assertFalse (is_snake_case ('foo' ))
204
+ self .assertFalse (is_snake_case (' ' ))
205
+
206
+ def test_string_cannot_be_lowercase_letters_only (self ):
207
+ self .assertFalse (is_snake_case ('lowercaseonly' ))
208
+
209
+ def test_string_cannot_be_camel_case (self ):
208
210
self .assertFalse (is_snake_case ('Banana' ))
211
+
212
+ def test_string_cannot_be_all_uppercase (self ):
209
213
self .assertFalse (is_snake_case ('HELLO' ))
210
- self . assertFalse ( is_snake_case ( 'HELLO_WORLD' ))
211
- self . assertFalse ( is_snake_case ( '_hello_world_' ))
214
+
215
+ def test_string_cannot_contain_bad_signs ( self ):
212
216
self .assertFalse (is_snake_case ('1_no_snake' ))
213
217
self .assertFalse (is_snake_case ('%_no_snake' ))
218
+ self .assertFalse (is_snake_case ('no_snake#' ))
219
+
220
+ def test_should_consider_single_chars_only_snake_sequence_invalid (self ):
214
221
self .assertFalse (is_snake_case ('a_b_c_d_e' ))
222
+
223
+ def test_snake_string_cannot_be_uppercase (self ):
224
+ self .assertFalse (is_snake_case ('HELLO_WORLD' ))
215
225
216
- def test_returns_true_for_snake_strings (self ):
226
+ def test_string_cannot_start_with_underscore (self ):
227
+ self .assertFalse (is_snake_case ('_hello_world' ))
228
+
229
+ def test_string_cannot_end_with_underscore (self ):
230
+ self .assertFalse (is_snake_case ('hello_world_' ))
231
+
232
+ def test_should_accept_valid_snake_strings (self ):
217
233
self .assertTrue (is_snake_case ('hello_world' ))
218
234
self .assertTrue (is_snake_case ('snake_case_string' ))
219
235
self .assertTrue (is_snake_case ('snake_2' ))
220
236
self .assertTrue (is_snake_case ('a_snake_string_4_you' ))
237
+
238
+ def test_should_consider_custom_separator (self ):
239
+ s = 'snake-string-with-dashes'
240
+ self .assertFalse (is_snake_case (s ))
241
+ self .assertTrue (is_snake_case (s , separator = '-' ))
221
242
222
243
223
244
class ReverseTestCase (TestCase ):
@@ -231,7 +252,7 @@ def test_returns_reversed_string(self):
231
252
232
253
233
254
class CamelCaseToSnakeTestCase (TestCase ):
234
- def test_raises_type_error_if_provided_object_is_not_a_string (self ):
255
+ def test_cannot_handle_non_string_objects (self ):
235
256
self .assertRaises (TypeError , lambda : camel_case_to_snake (None ))
236
257
self .assertRaises (TypeError , lambda : camel_case_to_snake (False ))
237
258
self .assertRaises (TypeError , lambda : camel_case_to_snake (0 ))
@@ -274,7 +295,7 @@ def test_should_use_provided_separator(self):
274
295
275
296
276
297
class SnakeCaseToCamelTestCase (TestCase ):
277
- def test_raises_type_error_if_provided_object_is_not_a_string (self ):
298
+ def test_cannot_handle_non_string_objects (self ):
278
299
self .assertRaises (TypeError , lambda : snake_case_to_camel (None ))
279
300
self .assertRaises (TypeError , lambda : snake_case_to_camel (False ))
280
301
self .assertRaises (TypeError , lambda : snake_case_to_camel (0 ))
@@ -296,7 +317,7 @@ def test_returns_camel_case_from_correct_snake_case(self):
296
317
self .assertEqual (snake_case_to_camel ('the_snake_is_green' ), 'TheSnakeIsGreen' )
297
318
self .assertEqual (snake_case_to_camel ('the_number_of_the_beast_is_666' ), 'TheNumberOfTheBeastIs666' )
298
319
299
- def test_returns_camel_case_for_custom_separator (self ):
320
+ def test_should_consider_custom_separator (self ):
300
321
s = 'snake-case-using-dashes'
301
322
self .assertEqual (snake_case_to_camel (s ), s )
302
323
self .assertEqual (snake_case_to_camel (s , separator = '-' ), 'SnakeCaseUsingDashes' )
0 commit comments