<s> """<STR_LIT>""" <EOL> from __future__ import division , absolute_import <EOL> from zope . interface . verify import verifyClass <EOL> from twisted . internet . interfaces import IResolver <EOL> from twisted . trial . unittest import SynchronousTestCase <EOL> from twisted . python . failure import Failure <EOL> from twisted . names . common import ResolverBase <EOL> from twisted . names . dns import EFORMAT , ESERVER , ENAME , ENOTIMP , EREFUSED , Query <EOL> from twisted . names . error import DNSFormatError , DNSServerError , DNSNameError <EOL> from twisted . names . error import DNSNotImplementedError , DNSQueryRefusedError <EOL> from twisted . names . error import DNSUnknownError <EOL> class ExceptionForCodeTests ( SynchronousTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . exceptionForCode = ResolverBase ( ) . exceptionForCode <EOL> def test_eformat ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertIs ( self . exceptionForCode ( EFORMAT ) , DNSFormatError ) <EOL> def test_eserver ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertIs ( self . exceptionForCode ( ESERVER ) , DNSServerError ) <EOL> def test_ename ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertIs ( self . exceptionForCode ( ENAME ) , DNSNameError ) <EOL> def test_enotimp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertIs ( self . exceptionForCode ( ENOTIMP ) , DNSNotImplementedError ) <EOL> def test_erefused ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertIs ( self . exceptionForCode ( EREFUSED ) , DNSQueryRefusedError ) <EOL> def test_other ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertIs ( self . exceptionForCode ( object ( ) ) , DNSUnknownError ) <EOL> class QueryTests ( SynchronousTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_resolverBaseProvidesIResolver ( self ) : <EOL> """<STR_LIT>""" <EOL> verifyClass ( IResolver , ResolverBase ) <EOL> def test_typeToMethodDispatch ( self ) : <EOL> """<STR_LIT>""" <EOL> results = [ ] <EOL> resolver = ResolverBase ( ) <EOL> resolver . typeToMethod = { <EOL> <NUM_LIT> : lambda query , timeout : results . append ( ( query , timeout ) ) } <EOL> query = Query ( name = b"<STR_LIT>" , type = <NUM_LIT> ) <EOL> resolver . query ( query , <NUM_LIT> ) <EOL> self . assertEqual ( [ ( b"<STR_LIT>" , <NUM_LIT> ) ] , results ) <EOL> def test_typeToMethodResult ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = object ( ) <EOL> resolver = ResolverBase ( ) <EOL> resolver . typeToMethod = { <NUM_LIT> : lambda query , timeout : expected } <EOL> query = Query ( name = b"<STR_LIT>" , type = <NUM_LIT> ) <EOL> queryDeferred = resolver . query ( query , <NUM_LIT> ) <EOL> result = [ ] <EOL> queryDeferred . addBoth ( result . append ) <EOL> self . assertEqual ( expected , result [ <NUM_LIT:0> ] ) <EOL> def test_unknownQueryType ( self ) : <EOL> """<STR_LIT>""" <EOL> resolver = ResolverBase ( ) <EOL> resolver . typeToMethod = { } <EOL> query = Query ( name = b"<STR_LIT>" , type = <NUM_LIT> ) <EOL> queryDeferred = resolver . query ( query , <NUM_LIT> ) <EOL> result = [ ] <EOL> queryDeferred . addBoth ( result . append ) <EOL> self . assertIsInstance ( result [ <NUM_LIT:0> ] , Failure ) <EOL> result [ <NUM_LIT:0> ] . trap ( NotImplementedError ) </s>
