1+ import typing
12import pytest
23
34from email_validator import validate_email , EmailSyntaxError
@@ -16,6 +17,14 @@ def test_dict_accessor() -> None:
1617 assert valid_email .as_dict ()["original" ] == input_email
1718
1819
20+ def test_dict_accessor_with_domain_address () -> None :
21+ input_email = "me@[127.0.0.1]"
22+ valid_email = validate_email (input_email , check_deliverability = False , allow_domain_literal = True )
23+ assert valid_email .domain == "[127.0.0.1]"
24+ assert isinstance (valid_email .as_dict (), dict )
25+ assert valid_email .as_dict ()["domain_address" ] == '"IPv4Address(\' 127.0.0.1\' )"'
26+
27+
1928def test_main_single_good_input (monkeypatch : pytest .MonkeyPatch , capsys : pytest .CaptureFixture [str ]) -> None :
2029 import json
2130 test_email = "google@google.com"
@@ -65,3 +74,21 @@ def test_deprecation() -> None:
6574 valid_email = validate_email (input_email , check_deliverability = False )
6675 with pytest .deprecated_call ():
6776 assert valid_email .email is not None
77+
78+
79+ @pytest .mark .parametrize ('invalid_email' , [
80+ None ,
81+ 12345 ,
82+ [],
83+ {},
84+ lambda x : x ,
85+ ])
86+ def test_invalid_type (invalid_email : typing .Any ) -> None :
87+ with pytest .raises (TypeError , match = "email must be str or bytes" ):
88+ validate_email (invalid_email , check_deliverability = False )
89+
90+
91+ def test_invalid_ascii () -> None :
92+ invalid_email = b'\xd0 \xba \xd0 \xb2 \xd1 \x96 \xd1 \x82 \xd0 \xbe \xd1 \x87 \xd0 \xba \xd0 \xb0 @\xd0 \xbf \xd0 \xbe \xd1 \x88 \xd1 \x82 \xd0 \xb0 .test'
93+ with pytest .raises (EmailSyntaxError , match = "The email address is not valid ASCII." ):
94+ validate_email (invalid_email , check_deliverability = False )
0 commit comments