#NEWLINE# def test_domain_validation( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# import DNS #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# pytest . skip ( 'PyDNS not installed.' ) #NEWLINE# #UNINDENT# mock = DomainValidator ( lookup_dns = 'mx' ) #NEWLINE# dataset = [ ( 'example.com' , 'Domain does not seem to exist.' ) , ( '' , 'Invalid domain: It cannot be empty.' ) , ( '-bad.example.com' , 'Invalid domain.' ) , ( 'gothcandy.com' , '' ) , ( ( ( 'a' * 64 ) + '.gothcandy.com' ) , 'Domain does not seem to exist.' ) , ( 'gothcandy.com' , '' ) , ( 'nx.example.com' , 'Domain does not seem to exist.' ) ] #NEWLINE# def closure( domain , expect ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# assert ( mock . validate_domain ( domain ) == ( domain , expect ) ) #NEWLINE# #UNINDENT# except DNS . DNSError : #NEWLINE# #INDENT# pytest . skip ( 'Skipped due to DNS error.' ) #NEWLINE# #UNINDENT# #UNINDENT# for ( domain , expect ) in dataset : #NEWLINE# #INDENT# ( yield ( closure , domain , expect ) )