Please tell me what you think. Is my code bad?
Function checking
#-*- coding: utf-8 -*-
import re
import unittest
def email_check(mail): # E-mail as argument func
compil = re.compile(r"""
^([-a-z0-9_]+
((?![.][.])|([.]))
((["]["])|(["][!:,]+["]))?
([-a-z0-9_]+)?)
@
[-a-z0-9_]+
[.]
([-a-z0-9_]+
([.][-a-z0-9_]+)?
)$
""", re.X)
result = compil.search(mail)
if result:
length = mail.split('@')
if len(length[0]) <= 128 and len(length[1]) <= 256:
print mail, 'correct' if not '-.' in length[1] and not '.-' in length[1] else 'Incorrect value'
else:
print 'Length string is not mathing'
else:
print 'Incorrect data'
return result.group()
And unit-test
class TestCorrectEmail(unittest.TestCase):
def setUp(self):
self.mails = ['[email protected]', '[email protected]', '[email protected]', '01mail""[email protected]', '01mail"!,:"[email protected]', '[email protected]']
def test_email_check(self):
for i in self.mails:
self.assertTrue(i == email_check(i), 'Incorrect value')
def tearDown(self):
self.mails = None
if __name__ == '__main__':
unittest.main()