<s> import types <EOL> import paver . deps . six as six <EOL> from paver import setuputils , tasks <EOL> class FakeModule ( object ) : <EOL> def __init__ ( self , ** kw ) : <EOL> for name , value in kw . items ( ) : <EOL> setattr ( self , name , value ) <EOL> def patched_print ( self , output ) : <EOL> self . patch_captured . append ( output ) <EOL> class FakeExitException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def patched_exit ( self , code ) : <EOL> self . exit_code = <NUM_LIT:1> <EOL> raise FakeExitException ( code ) <EOL> def _set_environment ( patch_print = False , ** kw ) : <EOL> pavement = FakeModule ( ** kw ) <EOL> env = tasks . Environment ( pavement ) <EOL> tasks . environment = env <EOL> if six . PY3 : <EOL> method_args = ( env , ) <EOL> else : <EOL> method_args = ( env , tasks . Environment ) <EOL> env . _exit = types . MethodType ( patched_exit , * method_args ) <EOL> if patch_print : <EOL> env . _print = types . MethodType ( patched_print , * method_args ) <EOL> env . patch_captured = [ ] <EOL> return env </s>
