python-email-validator/dont-require-resolv-tests.patch

60 lines
2.4 KiB
Diff

Index: python-email-validator-2.0.0/email_validator/deliverability.py
===================================================================
--- python-email-validator-2.0.0.orig/email_validator/deliverability.py
+++ python-email-validator-2.0.0/email_validator/deliverability.py
@@ -6,11 +6,11 @@ import dns.resolver
import dns.exception
-def caching_resolver(*, timeout: Optional[int] = None, cache=None):
+def caching_resolver(*, timeout: Optional[int] = None, cache=None, resolv=None):
if timeout is None:
from . import DEFAULT_TIMEOUT
timeout = DEFAULT_TIMEOUT
- resolver = dns.resolver.Resolver()
+ resolver = dns.resolver.Resolver(filename=resolv or '/etc/resolv.conf')
resolver.cache = cache or dns.resolver.LRUCache() # type: ignore
resolver.lifetime = timeout # type: ignore # timeout, in seconds
return resolver
Index: python-email-validator-2.0.0/tests/mocked_dns_response.py
===================================================================
--- python-email-validator-2.0.0.orig/tests/mocked_dns_response.py
+++ python-email-validator-2.0.0/tests/mocked_dns_response.py
@@ -1,5 +1,6 @@
import dns.resolver
import json
+import os
import os.path
import pytest
@@ -32,7 +33,8 @@ class MockedDnsResponseData:
# Return a new dns.resolver.Resolver configured for caching
# using the singleton instance.
- return caching_resolver(cache=MockedDnsResponseData.INSTANCE)
+ return caching_resolver(cache=MockedDnsResponseData.INSTANCE,
+ resolv=os.environ.get('RESOLV_FILE'))
def __init__(self):
self.data = {}
Index: python-email-validator-2.0.0/tests/test_deliverability.py
===================================================================
--- python-email-validator-2.0.0.orig/tests/test_deliverability.py
+++ python-email-validator-2.0.0/tests/test_deliverability.py
@@ -1,5 +1,6 @@
import pytest
import re
+import os
from email_validator import EmailUndeliverableError, \
validate_email, caching_resolver
@@ -73,7 +74,7 @@ def test_caching_dns_resolver():
self.cache[key] = value
cache = TestCache()
- resolver = caching_resolver(timeout=1, cache=cache)
+ resolver = caching_resolver(timeout=1, cache=cache, resolv=os.environ.get('RESOLV_FILE'))
validate_email("test@gmail.com", dns_resolver=resolver)
assert len(cache.cache) == 1