56
56
ascii_email = "!#$%&'*+-/=?^_`.{|}~@example.tld" ,
57
57
),
58
58
),
59
+ (
60
+ 'jeff@臺網中心.tw' ,
61
+ ValidatedEmail (
62
+ local_part = 'jeff' ,
63
+ ascii_local_part = 'jeff' ,
64
+ smtputf8 = False ,
65
+ ascii_domain = 'xn--fiqq24b10vi0d.tw' ,
66
+ domain = '臺網中心.tw' ,
67
+ email = 'jeff@臺網中心.tw' ,
68
+ ascii_email = 'jeff@xn--fiqq24b10vi0d.tw' ,
69
+ ),
70
+ ),
71
+ ],
72
+ )
73
+ def test_email_valid (email_input , output ):
74
+ # These addresses do not require SMTPUTF8. See test_email_valid_intl_local_part
75
+ # for addresses that are valid but require SMTPUTF8. Check that it passes with
76
+ # allow_smtput8 both on and off.
77
+ assert validate_email (email_input , check_deliverability = False , allow_smtputf8 = False ) == output
78
+ assert validate_email (email_input , check_deliverability = False , allow_smtputf8 = True ) == output
79
+
80
+
81
+ @pytest .mark .parametrize (
82
+ 'email_input,output' ,
83
+ [
59
84
(
60
85
'伊昭傑@郵件.商務' ,
61
86
ValidatedEmail (
106
131
email = '葉士豪@臺網中心.tw' ,
107
132
),
108
133
),
109
- (
110
- 'jeff@臺網中心.tw' ,
111
- ValidatedEmail (
112
- local_part = 'jeff' ,
113
- ascii_local_part = 'jeff' ,
114
- smtputf8 = False ,
115
- ascii_domain = 'xn--fiqq24b10vi0d.tw' ,
116
- domain = '臺網中心.tw' ,
117
- email = 'jeff@臺網中心.tw' ,
118
- ascii_email = 'jeff@xn--fiqq24b10vi0d.tw' ,
119
- ),
120
- ),
121
134
(
122
135
'葉士豪@臺網中心.台灣' ,
123
136
ValidatedEmail (
200
213
),
201
214
],
202
215
)
203
- def test_email_valid (email_input , output ):
204
- # print(f'({email_input!r}, {validate_email(email_input, check_deliverability=False)!r}),')
216
+ def test_email_valid_intl_local_part (email_input , output ):
217
+ # Check that it passes when allow_smtputf8 is True.
205
218
assert validate_email (email_input , check_deliverability = False ) == output
206
219
220
+ # Check that it fails when allow_smtputf8 is False.
221
+ with pytest .raises (EmailSyntaxError ) as exc_info :
222
+ validate_email (email_input , allow_smtputf8 = False , check_deliverability = False )
223
+ assert "Internationalized characters before the @-sign are not supported: " in str (exc_info .value )
224
+
207
225
208
226
@pytest .mark .parametrize (
209
227
'email_input,error_msg' ,
@@ -263,7 +281,6 @@ def test_email_invalid_syntax(email_input, error_msg):
263
281
# checks do not arise.
264
282
with pytest .raises (EmailSyntaxError ) as exc_info :
265
283
validate_email (email_input )
266
- # print(f'({email_input!r}, {str(exc_info.value)!r}),')
267
284
assert str (exc_info .value ) == error_msg
268
285
269
286
@@ -283,7 +300,6 @@ def test_email_invalid_reserved_domain(email_input):
283
300
# DNS deliverability checks do not arise.
284
301
with pytest .raises (EmailSyntaxError ) as exc_info :
285
302
validate_email (email_input )
286
- # print(f'({email_input!r}, {str(exc_info.value)!r}),')
287
303
assert "is a special-use or reserved name" in str (exc_info .value )
288
304
289
305
@@ -317,16 +333,31 @@ def test_email_unsafe_character(s, expected_error):
317
333
('email_input' , 'expected_error' ),
318
334
[
319
335
('white space@test' , 'The email address contains invalid characters before the @-sign: SPACE.' ),
336
+ ('test@white space' , 'The part after the @-sign contains invalid characters: SPACE.' ),
320
337
('\n @test' , 'The email address contains invalid characters before the @-sign: U+000A.' ),
338
+ ('test@\n ' , 'The part after the @-sign contains invalid characters: U+000A.' ),
321
339
],
322
340
)
323
341
def test_email_invalid_character (email_input , expected_error ):
324
- # Check for various unsafe characters :
342
+ # Check for various unsafe test_email_invalid_character_smtputf8 :
325
343
with pytest .raises (EmailSyntaxError ) as exc_info :
326
344
validate_email (email_input , test_environment = True )
327
345
assert str (exc_info .value ) == expected_error
328
346
329
347
348
+ @pytest .mark .parametrize (
349
+ ('email_input' , 'expected_error' ),
350
+ [
351
+ ('λambdaツ@test' , 'Internationalized characters before the @-sign are not supported: \' λ\' , \' ツ\' .' ),
352
+ ],
353
+ )
354
+ def test_email_invalid_character_smtputf8 (email_input , expected_error ):
355
+ # Check for various unsafe characters:
356
+ with pytest .raises (EmailSyntaxError ) as exc_info :
357
+ validate_email (email_input , allow_smtputf8 = False , test_environment = True )
358
+ assert str (exc_info .value ) == expected_error
359
+
360
+
330
361
def test_email_test_domain_name_in_test_environment ():
331
362
validate_email ("anything@test" , test_environment = True )
332
363
validate_email ("anything@mycompany.test" , test_environment = True )
0 commit comments