44"""Tests for the FakeEmailAnalyzer heuristic."""
55
66
7- from unittest .mock import MagicMock
7+ from unittest .mock import MagicMock , patch
88
99import pytest
1010
@@ -19,6 +19,7 @@ def analyzer_() -> FakeEmailAnalyzer:
1919 return FakeEmailAnalyzer ()
2020
2121
22+ @patch ("email_validator.TEST_ENVIRONMENT" , True )
2223def test_missing_info (pypi_package_json : MagicMock , analyzer : FakeEmailAnalyzer ) -> None :
2324 """Test when JSON 'info' key is missing in the PyPI data (should error).
2425
@@ -34,6 +35,7 @@ def test_missing_info(pypi_package_json: MagicMock, analyzer: FakeEmailAnalyzer)
3435 analyzer .analyze (pypi_package_json )
3536
3637
38+ @patch ("email_validator.TEST_ENVIRONMENT" , True )
3739def test_no_emails_present (pypi_package_json : MagicMock , analyzer : FakeEmailAnalyzer ) -> None :
3840 """Test when no author_email or maintainer_email is present (should skip).
3941
@@ -49,6 +51,7 @@ def test_no_emails_present(pypi_package_json: MagicMock, analyzer: FakeEmailAnal
4951 assert result == HeuristicResult .SKIP
5052
5153
54+ @patch ("email_validator.TEST_ENVIRONMENT" , True )
5255def test_non_email (pypi_package_json : MagicMock , analyzer : FakeEmailAnalyzer ) -> None :
5356 """Test with a non-parsable email address (should fail).
5457
@@ -70,32 +73,9 @@ def test_non_email(pypi_package_json: MagicMock, analyzer: FakeEmailAnalyzer) ->
7073 assert "also not an email" in info ["non_emails" ]
7174
7275
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 )
9777def 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).
9979
10080 Parameters
10181 ----------
@@ -107,16 +87,16 @@ def test_valid_email(pypi_package_json: MagicMock, analyzer: FakeEmailAnalyzer)
10787 # TODO: change this to use a test domain instead of turning off deliverability
10888 analyzer .check_deliverability = False
10989 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 " }
11191 }
11292 result , info = analyzer .analyze (pypi_package_json )
11393 assert result == HeuristicResult .PASS
11494
11595 # assert types (for mypy)
11696 assert isinstance (info ["valid_emails" ], list )
11797
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" ]
120100
121101
122102def test_get_emails (analyzer : FakeEmailAnalyzer ) -> None :
0 commit comments