4
4
"""Tests for the FakeEmailAnalyzer heuristic."""
5
5
6
6
7
- from unittest .mock import MagicMock
7
+ from unittest .mock import MagicMock , patch
8
8
9
9
import pytest
10
10
@@ -19,6 +19,7 @@ def analyzer_() -> FakeEmailAnalyzer:
19
19
return FakeEmailAnalyzer ()
20
20
21
21
22
+ @patch ("email_validator.TEST_ENVIRONMENT" , True )
22
23
def test_missing_info (pypi_package_json : MagicMock , analyzer : FakeEmailAnalyzer ) -> None :
23
24
"""Test when JSON 'info' key is missing in the PyPI data (should error).
24
25
@@ -34,6 +35,7 @@ def test_missing_info(pypi_package_json: MagicMock, analyzer: FakeEmailAnalyzer)
34
35
analyzer .analyze (pypi_package_json )
35
36
36
37
38
+ @patch ("email_validator.TEST_ENVIRONMENT" , True )
37
39
def test_no_emails_present (pypi_package_json : MagicMock , analyzer : FakeEmailAnalyzer ) -> None :
38
40
"""Test when no author_email or maintainer_email is present (should skip).
39
41
@@ -49,6 +51,7 @@ def test_no_emails_present(pypi_package_json: MagicMock, analyzer: FakeEmailAnal
49
51
assert result == HeuristicResult .SKIP
50
52
51
53
54
+ @patch ("email_validator.TEST_ENVIRONMENT" , True )
52
55
def test_non_email (pypi_package_json : MagicMock , analyzer : FakeEmailAnalyzer ) -> None :
53
56
"""Test with a non-parsable email address (should fail).
54
57
@@ -70,32 +73,9 @@ def test_non_email(pypi_package_json: MagicMock, analyzer: FakeEmailAnalyzer) ->
70
73
assert "also not an email" in info ["non_emails" ]
71
74
72
75
73
- def test_invalid_email (pypi_package_json : MagicMock , analyzer : FakeEmailAnalyzer ) -> None :
74
- """Test with an invalid email address that doesn't accept mail (should fail).
75
-
76
- Parameters
77
- ----------
78
- pypi_package_json: MagicMock
79
- The PyPIPackageJsonAsset MagicMock fixture.
80
- analyzer: FakeEmailAnalyzer
81
- An initialized FakeEmailAnalyzer instance.
82
- """
83
- pypi_package_json .package_json = {
84
- "info" : {"author_email" : "user@example.com" , "maintainer_email" : "other@example.com" }
85
- }
86
-
87
- result , info = analyzer .analyze (pypi_package_json )
88
- assert result == HeuristicResult .FAIL
89
-
90
- # assert types (for mypy)
91
- assert isinstance (info ["invalid_emails" ], list )
92
-
93
- assert "user@example.com" in info ["invalid_emails" ]
94
- assert "other@example.com" in info ["invalid_emails" ]
95
-
96
-
76
+ @patch ("email_validator.TEST_ENVIRONMENT" , True )
97
77
def test_valid_email (pypi_package_json : MagicMock , analyzer : FakeEmailAnalyzer ) -> None :
98
- """Test with valid email address that does accept mail (should pass).
78
+ """Test with valid email address format (should pass).
99
79
100
80
Parameters
101
81
----------
@@ -107,16 +87,16 @@ def test_valid_email(pypi_package_json: MagicMock, analyzer: FakeEmailAnalyzer)
107
87
# TODO: change this to use a test domain instead of turning off deliverability
108
88
analyzer .check_deliverability = False
109
89
pypi_package_json .package_json = {
110
- "info" : {"author_email" : "user@example.net " , "maintainer_email" : "other@example.net " }
90
+ "info" : {"author_email" : "user@example.test " , "maintainer_email" : "other@example.test " }
111
91
}
112
92
result , info = analyzer .analyze (pypi_package_json )
113
93
assert result == HeuristicResult .PASS
114
94
115
95
# assert types (for mypy)
116
96
assert isinstance (info ["valid_emails" ], list )
117
97
118
- assert "user@example.net " in info ["valid_emails" ]
119
- assert "other@example.net " in info ["valid_emails" ]
98
+ assert "user@example.test " in info ["valid_emails" ]
99
+ assert "other@example.test " in info ["valid_emails" ]
120
100
121
101
122
102
def test_get_emails (analyzer : FakeEmailAnalyzer ) -> None :
0 commit comments