<s> """<STR_LIT>""" <EOL> import sys <EOL> from twisted . internet import reactor <EOL> from twisted . trial import unittest <EOL> from twisted . internet . defer import waitForDeferred , deferredGenerator , Deferred <EOL> from twisted . internet import defer <EOL> def getThing ( ) : <EOL> d = Deferred ( ) <EOL> reactor . callLater ( <NUM_LIT:0> , d . callback , "<STR_LIT>" ) <EOL> return d <EOL> def getOwie ( ) : <EOL> d = Deferred ( ) <EOL> def CRAP ( ) : <EOL> d . errback ( ZeroDivisionError ( '<STR_LIT>' ) ) <EOL> reactor . callLater ( <NUM_LIT:0> , CRAP ) <EOL> return d <EOL> class TerminalException ( Exception ) : <EOL> pass <EOL> class BaseDefgenTests : <EOL> """<STR_LIT>""" <EOL> def testBasics ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _genBasics ( ) . addCallback ( self . assertEqual , '<STR_LIT>' ) <EOL> def testBuggy ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . assertFailure ( self . _genBuggy ( ) , ZeroDivisionError ) <EOL> def testNothing ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _genNothing ( ) . addCallback ( self . assertEqual , None ) <EOL> def testHandledTerminalFailure ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _genHandledTerminalFailure ( ) . addCallback ( self . assertEqual , None ) <EOL> def testHandledTerminalAsyncFailure ( self ) : <EOL> """<STR_LIT>""" <EOL> d = defer . Deferred ( ) <EOL> deferredGeneratorResultDeferred = self . _genHandledTerminalAsyncFailure ( d ) <EOL> d . errback ( TerminalException ( "<STR_LIT>" ) ) <EOL> return deferredGeneratorResultDeferred . addCallback ( <EOL> self . assertEqual , None ) <EOL> def testStackUsage ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _genStackUsage ( ) . addCallback ( self . assertEqual , <NUM_LIT:0> ) <EOL> def testStackUsage2 ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _genStackUsage2 ( ) . addCallback ( self . assertEqual , <NUM_LIT:0> ) <EOL> class DeferredGeneratorTests ( BaseDefgenTests , unittest . TestCase ) : <EOL> def _genBasics ( self ) : <EOL> x = waitForDeferred ( getThing ( ) ) <EOL> yield x <EOL> x = x . getResult ( ) <EOL> self . assertEqual ( x , "<STR_LIT>" ) <EOL> ow = waitForDeferred ( getOwie ( ) ) <EOL> yield ow <EOL> try : <EOL> ow . getResult ( ) <EOL> except ZeroDivisionError , e : <EOL> self . assertEqual ( str ( e ) , '<STR_LIT>' ) <EOL> yield "<STR_LIT>" <EOL> return <EOL> _genBasics = deferredGenerator ( _genBasics ) <EOL> def _genBuggy ( self ) : <EOL> yield waitForDeferred ( getThing ( ) ) <EOL> <NUM_LIT:1> // <NUM_LIT:0> <EOL> _genBuggy = deferredGenerator ( _genBuggy ) <EOL> def _genNothing ( self ) : <EOL> if <NUM_LIT:0> : yield <NUM_LIT:1> <EOL> _genNothing = deferredGenerator ( _genNothing ) <EOL> def _genHandledTerminalFailure ( self ) : <EOL> x = waitForDeferred ( defer . fail ( TerminalException ( "<STR_LIT>" ) ) ) <EOL> yield x <EOL> try : <EOL> x . getResult ( ) <EOL> except TerminalException : <EOL> pass <EOL> _genHandledTerminalFailure = deferredGenerator ( _genHandledTerminalFailure ) <EOL> def _genHandledTerminalAsyncFailure ( self , d ) : <EOL> x = waitForDeferred ( d ) <EOL> yield x <EOL> try : <EOL> x . getResult ( ) <EOL> except TerminalException : <EOL> pass <EOL> _genHandledTerminalAsyncFailure = deferredGenerator ( _genHandledTerminalAsyncFailure ) <EOL> def _genStackUsage ( self ) : <EOL> for x in range ( <NUM_LIT> ) : <EOL> x = waitForDeferred ( defer . succeed ( <NUM_LIT:1> ) ) <EOL> yield x <EOL> x = x . getResult ( ) <EOL> yield <NUM_LIT:0> <EOL> _genStackUsage = deferredGenerator ( _genStackUsage ) <EOL> def _genStackUsage2 ( self ) : <EOL> for x in range ( <NUM_LIT> ) : <EOL> yield <NUM_LIT:1> <EOL> yield <NUM_LIT:0> <EOL> _genStackUsage2 = deferredGenerator ( _genStackUsage2 ) <EOL> def testDeferredYielding ( self ) : <EOL> """<STR_LIT>""" <EOL> def _genDeferred ( ) : <EOL> yield getThing ( ) <EOL> _genDeferred = deferredGenerator ( _genDeferred ) <EOL> return self . assertFailure ( _genDeferred ( ) , TypeError ) <EOL> inlineCallbacksTestsSource = '''<STR_LIT>''' <EOL> if sys . version_info > ( <NUM_LIT:2> , <NUM_LIT:5> ) : <EOL> exec inlineCallbacksTestsSource <EOL> else : <EOL> class InlineCallbacksTests ( unittest . TestCase ) : <EOL> skip = "<STR_LIT>" <EOL> def test_everything ( self ) : <EOL> pass </s>
