Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_diagnosis(tag):
"""Create a Diagnosis for a given tag.
Keyword arguments:
tag --- the tag string to create a Diagnosis for
"""
split_tag = tag.split("_")
d_class = _get_diagnosis_class(split_tag[1])
diagnosis_type = "_".join(split_tag[2:])
if diagnosis_type == "" and d_class == ValidDiagnosis:
diagnosis_type = "VALID"
return d_class(diagnosis_type)
def test_without_diagnosis(self):
result = is_email(self.address)
expected = create_diagnosis(self.diagnosis) < self.threshold
self.assertEqual(
result,
expected,
("%s (%s): Got %s, but expected %s."
% (self.id, self.address, result, expected))
)
def _get_diagnosis_class(tag):
"""Get class of the Diagnosis to use for a given tag.
Keyword arguments:
tag --- the tag string to look up
"""
if tag == "ERR":
d_class = InvalidDiagnosis
elif tag == "DNSWARN":
d_class = DNSDiagnosis
elif tag == "VALID":
d_class = ValidDiagnosis
elif tag == "RFC5321":
d_class = RFC5321Diagnosis
elif tag == "VALID":
d_class = ValidDiagnosis
elif tag == "RFC5321":
d_class = RFC5321Diagnosis
elif tag == "RFC5322":
d_class = RFC5322Diagnosis
elif tag == "CFWS":
d_class = CFWSDiagnosis
elif tag == "DEPREC":
d_class = DeprecatedDiagnosis
def test_lt(self):
d1 = BaseDiagnosis("test")
d1.code = 1
d2 = BaseDiagnosis("test")
d2.code = 2
self.assertLess(d1, d2)
self.assertLess(d1, 3)
from testscenarios import TestWithScenarios
from unittest import TestCase
try:
from unittest.mock import patch
except ImportError:
from mock import patch
import dns.resolver
from pyisemail import is_email
from pyisemail.diagnosis import BaseDiagnosis, DNSDiagnosis
from tests.validators import create_diagnosis, get_scenarios
class IsEmailTest(TestWithScenarios):
scenarios = get_scenarios("tests.xml")
threshold = BaseDiagnosis.CATEGORIES['THRESHOLD']
def test_without_diagnosis(self):
result = is_email(self.address)
expected = create_diagnosis(self.diagnosis) < self.threshold
self.assertEqual(
result,
expected,
("%s (%s): Got %s, but expected %s."
% (self.id, self.address, result, expected))
)
def test_with_diagnosis(self):
result = is_email(self.address, diagnose=True)
expected = create_diagnosis(self.diagnosis)
def test_gt(self):
d1 = BaseDiagnosis("test")
d1.code = 1
d2 = BaseDiagnosis("test")
d2.code = 2
self.assertGreater(d2, d1)
self.assertGreater(3, d1)
def test_lt(self):
d1 = BaseDiagnosis("test")
d1.code = 1
d2 = BaseDiagnosis("test")
d2.code = 2
self.assertLess(d1, d2)
self.assertLess(d1, 3)
def test_hash(self):
d1 = BaseDiagnosis("test")
d2 = BaseDiagnosis("test")
self.assertEqual(hash(d1), hash(d2))
def test_gt(self):
d1 = BaseDiagnosis("test")
d1.code = 1
d2 = BaseDiagnosis("test")
d2.code = 2
self.assertGreater(d2, d1)
self.assertGreater(3, d1)
"""
if tag == "ERR":
d_class = InvalidDiagnosis
elif tag == "DNSWARN":
d_class = DNSDiagnosis
elif tag == "VALID":
d_class = ValidDiagnosis
elif tag == "RFC5321":
d_class = RFC5321Diagnosis
elif tag == "VALID":
d_class = ValidDiagnosis
elif tag == "RFC5321":
d_class = RFC5321Diagnosis
elif tag == "RFC5322":
d_class = RFC5322Diagnosis
elif tag == "CFWS":
d_class = CFWSDiagnosis
elif tag == "DEPREC":
d_class = DeprecatedDiagnosis
else:
d_class = ""
return d_class