<s> import os <EOL> import platform <EOL> import mock <EOL> import twisted <EOL> from twisted . internet import reactor <EOL> from twisted . internet . task import Clock <EOL> from twisted . trial . unittest import TestCase <EOL> from twisted . python . failure import Failure <EOL> from twisted . python . versions import Version <EOL> DEBUG = os . getenv ( "<STR_LIT>" , False ) == "<STR_LIT:true>" <EOL> is_pypy = platform . python_implementation ( ) == '<STR_LIT>' <EOL> if twisted . version < Version ( '<STR_LIT>' , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:0> ) : <EOL> class TestCase ( TestCase ) : <EOL> def successResultOf ( self , d ) : <EOL> results = [ ] <EOL> d . addBoth ( results . append ) <EOL> if isinstance ( results [ <NUM_LIT:0> ] , Failure ) : <EOL> results [ <NUM_LIT:0> ] . raiseException ( ) <EOL> return results [ <NUM_LIT:0> ] <EOL> def failureResultOf ( self , d , * errorTypes ) : <EOL> results = [ ] <EOL> d . addBoth ( results . append ) <EOL> if not isinstance ( results [ <NUM_LIT:0> ] , Failure ) : <EOL> self . fail ( "<STR_LIT>" . format ( <EOL> errorTypes , results [ <NUM_LIT:0> ] ) ) <EOL> self . assertTrue ( results [ <NUM_LIT:0> ] . check ( * errorTypes ) ) <EOL> return results [ <NUM_LIT:0> ] <EOL> def with_clock ( fn ) : <EOL> def wrapper ( * args , ** kwargs ) : <EOL> clock = Clock ( ) <EOL> with mock . patch . object ( reactor , '<STR_LIT>' , clock . callLater ) : <EOL> return fn ( * ( args + ( clock , ) ) , ** kwargs ) <EOL> return wrapper </s>
