<s> from tests import requires_twisted <EOL> import unittest <EOL> try : <EOL> from twisted . internet import reactor <EOL> from twisted . internet . error import DNSLookupError <EOL> from twisted . internet import defer <EOL> from twisted . python . failure import Failure <EOL> from eventlet . twistedutil import block_on <EOL> except ImportError : <EOL> pass <EOL> class Test ( unittest . TestCase ) : <EOL> @ requires_twisted <EOL> def test_block_on_success ( self ) : <EOL> from twisted . internet import reactor <EOL> d = reactor . resolver . getHostByName ( '<STR_LIT>' ) <EOL> ip = block_on ( d ) <EOL> assert len ( ip . split ( '<STR_LIT:.>' ) ) == <NUM_LIT:4> , ip <EOL> ip2 = block_on ( d ) <EOL> assert ip == ip2 , ( ip , ip2 ) <EOL> @ requires_twisted <EOL> def test_block_on_fail ( self ) : <EOL> from twisted . internet import reactor <EOL> d = reactor . resolver . getHostByName ( '<STR_LIT>' ) <EOL> self . assertRaises ( DNSLookupError , block_on , d ) <EOL> @ requires_twisted <EOL> def test_block_on_already_succeed ( self ) : <EOL> d = defer . succeed ( '<STR_LIT>' ) <EOL> res = block_on ( d ) <EOL> assert res == '<STR_LIT>' , repr ( res ) <EOL> @ requires_twisted <EOL> def test_block_on_already_failed ( self ) : <EOL> d = defer . fail ( Failure ( ZeroDivisionError ( ) ) ) <EOL> self . assertRaises ( ZeroDivisionError , block_on , d ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
