<s> import py , sys , os <EOL> from py . __ . test . outcome import Failed <EOL> from pypy . interpreter . gateway import app2interp_temp <EOL> from pypy . interpreter . error import OperationError <EOL> from pypy . tool . pytest import appsupport <EOL> from pypy . tool . option import make_config , make_objspace <EOL> from pypy . config . config import ConflictConfigError <EOL> from inspect import isclass , getmro <EOL> from pypy . tool . udir import udir <EOL> from pypy . tool . autopath import pypydir <EOL> rootdir = py . magic . autopath ( ) . dirpath ( ) <EOL> pytest_plugins = "<STR_LIT>" , <EOL> rsyncdirs = [ '<STR_LIT:.>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> rsyncignore = [ '<STR_LIT>' ] <EOL> empty_conftest = type ( sys ) ( '<STR_LIT>' ) <EOL> empty_conftest . __file__ = "<STR_LIT:?>" <EOL> sys . modules [ '<STR_LIT>' ] = empty_conftest <EOL> def _set_platform ( opt , opt_str , value , parser ) : <EOL> from pypy . config . translationoption import PLATFORMS <EOL> from pypy . translator . platform import set_platform <EOL> if value not in PLATFORMS : <EOL> raise ValueError ( "<STR_LIT>" % ( value , PLATFORMS ) ) <EOL> set_platform ( value , None ) <EOL> option = py . test . config . option <EOL> def pytest_addoption ( parser ) : <EOL> group = parser . addgroup ( "<STR_LIT>" ) <EOL> group . addoption ( '<STR_LIT>' , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> group . addoption ( '<STR_LIT>' , '<STR_LIT>' , action = "<STR_LIT:store_true>" , <EOL> default = False , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> group . addoption ( '<STR_LIT>' , action = "<STR_LIT:store_true>" , <EOL> default = False , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> group . addoption ( '<STR_LIT>' , '<STR_LIT>' , action = "<STR_LIT>" , type = "<STR_LIT:string>" , <EOL> default = "<STR_LIT:host>" , callback = _set_platform , <EOL> help = "<STR_LIT>" ) <EOL> def pytest_funcarg__space ( request ) : <EOL> return gettestobjspace ( ) <EOL> _SPACECACHE = { } <EOL> def gettestobjspace ( name = None , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> config = make_config ( option , objspace = name , ** kwds ) <EOL> except ConflictConfigError , e : <EOL> py . test . skip ( str ( e ) ) <EOL> key = config . getkey ( ) <EOL> try : <EOL> return _SPACECACHE [ key ] <EOL> except KeyError : <EOL> if option . runappdirect : <EOL> if name not in ( None , '<STR_LIT>' ) : <EOL> myname = getattr ( sys , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not myname . lower ( ) . startswith ( name ) : <EOL> py . test . skip ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( name , ) ) <EOL> return TinyObjSpace ( ** kwds ) <EOL> space = maketestobjspace ( config ) <EOL> _SPACECACHE [ key ] = space <EOL> return space <EOL> def maketestobjspace ( config = None ) : <EOL> if config is None : <EOL> config = make_config ( option ) <EOL> try : <EOL> space = make_objspace ( config ) <EOL> except OperationError , e : <EOL> check_keyboard_interrupt ( e ) <EOL> if option . verbose : <EOL> import traceback <EOL> traceback . print_exc ( ) <EOL> py . test . fail ( "<STR_LIT>" % <EOL> ( config . objspace . name , ) ) <EOL> space . startup ( ) <EOL> space . setitem ( space . builtin . w_dict , space . wrap ( '<STR_LIT>' ) , <EOL> appsupport . build_pytest_assertion ( space ) ) <EOL> space . setitem ( space . builtin . w_dict , space . wrap ( '<STR_LIT>' ) , <EOL> space . wrap ( appsupport . app_raises ) ) <EOL> space . setitem ( space . builtin . w_dict , space . wrap ( '<STR_LIT>' ) , <EOL> space . wrap ( appsupport . app_skip ) ) <EOL> space . raises_w = appsupport . raises_w . __get__ ( space ) <EOL> space . eq_w = appsupport . eq_w . __get__ ( space ) <EOL> return space <EOL> class TinyObjSpace ( object ) : <EOL> def __init__ ( self , ** kwds ) : <EOL> import sys <EOL> info = getattr ( sys , '<STR_LIT>' , None ) <EOL> for key , value in kwds . iteritems ( ) : <EOL> if key == '<STR_LIT>' : <EOL> if info is not None : <EOL> for modname in value : <EOL> ok = info . get ( '<STR_LIT>' % modname , <EOL> False ) <EOL> if not ok : <EOL> py . test . skip ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( modname , ) ) <EOL> else : <EOL> if '<STR_LIT>' in value : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> continue <EOL> if info is None : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> has = info . get ( key , None ) <EOL> if has != value : <EOL> py . test . skip ( "<STR_LIT>" "<STR_LIT>" % ( key , value , has ) ) <EOL> def appexec ( self , args , body ) : <EOL> body = body . lstrip ( ) <EOL> assert body . startswith ( '<STR_LIT:(>' ) <EOL> src = py . code . Source ( "<STR_LIT>" + body ) <EOL> d = { } <EOL> exec src . compile ( ) in d <EOL> return d [ '<STR_LIT>' ] ( * args ) <EOL> def wrap ( self , obj ) : <EOL> return obj <EOL> def unpackiterable ( self , itr ) : <EOL> return list ( itr ) <EOL> def is_true ( self , obj ) : <EOL> return bool ( obj ) <EOL> def newdict ( self ) : <EOL> return { } <EOL> def newtuple ( self , iterable ) : <EOL> return tuple ( iterable ) <EOL> def newlist ( self , iterable ) : <EOL> return list ( iterable ) <EOL> def call_function ( self , func , * args , ** kwds ) : <EOL> return func ( * args , ** kwds ) <EOL> def call_method ( self , obj , name , * args , ** kwds ) : <EOL> return getattr ( obj , name ) ( * args , ** kwds ) <EOL> def getattr ( self , obj , name ) : <EOL> return getattr ( obj , name ) <EOL> def setattr ( self , obj , name , value ) : <EOL> setattr ( obj , name , value ) <EOL> def getbuiltinmodule ( self , name ) : <EOL> return __import__ ( name ) <EOL> def translation_test_so_skip_if_appdirect ( ) : <EOL> if option . runappdirect : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> class OpErrKeyboardInterrupt ( KeyboardInterrupt ) : <EOL> pass <EOL> def check_keyboard_interrupt ( e ) : <EOL> try : <EOL> if e . w_type . name == '<STR_LIT>' : <EOL> tb = sys . exc_info ( ) [ <NUM_LIT:2> ] <EOL> raise OpErrKeyboardInterrupt , OpErrKeyboardInterrupt ( ) , tb <EOL> except AttributeError : <EOL> pass <EOL> def ensure_pytest_builtin_helpers ( helpers = '<STR_LIT>' . split ( ) ) : <EOL> """<STR_LIT>""" <EOL> import __builtin__ <EOL> for helper in helpers : <EOL> if not hasattr ( __builtin__ , helper ) : <EOL> setattr ( __builtin__ , helper , getattr ( py . test , helper ) ) <EOL> class Module ( py . test . collect . Module ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> if hasattr ( sys , '<STR_LIT>' ) : <EOL> option . conf_iocapture = "<STR_LIT>" <EOL> super ( Module , self ) . __init__ ( * args , ** kwargs ) <EOL> def accept_regular_test ( self ) : <EOL> if option . runappdirect : <EOL> return "<STR_LIT>" in self . listnames ( ) <EOL> else : <EOL> return True <EOL> def funcnamefilter ( self , name ) : <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> return self . accept_regular_test ( ) <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> return True <EOL> return False <EOL> def classnamefilter ( self , name ) : <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> return self . accept_regular_test ( ) <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> return True <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> return True <EOL> return False <EOL> def setup ( self ) : <EOL> ensure_pytest_builtin_helpers ( ) <EOL> super ( Module , self ) . setup ( ) <EOL> def makeitem ( self , name , obj ) : <EOL> if isclass ( obj ) and self . classnamefilter ( name ) : <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> return AppClassCollector ( name , parent = self ) <EOL> elif name . startswith ( '<STR_LIT>' ) : <EOL> if option . rundirect : <EOL> return py . test . collect . Class ( name , parent = self ) <EOL> return ExpectClassCollector ( name , parent = self ) <EOL> else : <EOL> return IntClassCollector ( name , parent = self ) <EOL> elif hasattr ( obj , '<STR_LIT>' ) and self . funcnamefilter ( name ) : <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> assert not obj . func_code . co_flags & <NUM_LIT:32> , "<STR_LIT>" <EOL> return AppTestFunction ( name , parent = self ) <EOL> elif obj . func_code . co_flags & <NUM_LIT:32> : <EOL> return self . Generator ( name , parent = self ) <EOL> else : <EOL> return IntTestFunction ( name , parent = self ) <EOL> def skip_on_missing_buildoption ( ** ropts ) : <EOL> __tracebackhide__ = True <EOL> import sys <EOL> options = getattr ( sys , '<STR_LIT>' , None ) <EOL> if options is None : <EOL> py . test . skip ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( ropts , ) ) <EOL> for opt in ropts : <EOL> if not options . has_key ( opt ) or options [ opt ] != ropts [ opt ] : <EOL> break <EOL> else : <EOL> return <EOL> py . test . skip ( "<STR_LIT>" <EOL> % ( ropts , options ) ) <EOL> def getwithoutbinding ( x , name ) : <EOL> try : <EOL> return x . __dict__ [ name ] <EOL> except ( AttributeError , KeyError ) : <EOL> for cls in getmro ( x . __class__ ) : <EOL> if name in cls . __dict__ : <EOL> return cls . __dict__ [ name ] <EOL> return getattr ( x , name ) <EOL> class LazyObjSpaceGetter ( object ) : <EOL> def __get__ ( self , obj , cls = None ) : <EOL> space = gettestobjspace ( ) <EOL> if cls : <EOL> cls . space = space <EOL> return space <EOL> class AppError ( Exception ) : <EOL> def __init__ ( self , excinfo ) : <EOL> self . excinfo = excinfo <EOL> class PyPyTestFunction ( py . test . collect . Function ) : <EOL> def execute_appex ( self , space , target , * args ) : <EOL> try : <EOL> target ( * args ) <EOL> except OperationError , e : <EOL> tb = sys . exc_info ( ) [ <NUM_LIT:2> ] <EOL> if e . match ( space , space . w_KeyboardInterrupt ) : <EOL> raise OpErrKeyboardInterrupt , OpErrKeyboardInterrupt ( ) , tb <EOL> appexcinfo = appsupport . AppExceptionInfo ( space , e ) <EOL> if appexcinfo . traceback : <EOL> raise AppError , AppError ( appexcinfo ) , tb <EOL> raise <EOL> def repr_failure ( self , excinfo ) : <EOL> if excinfo . errisinstance ( AppError ) : <EOL> excinfo = excinfo . value . excinfo <EOL> return super ( PyPyTestFunction , self ) . repr_failure ( excinfo ) <EOL> _pygame_imported = False <EOL> class IntTestFunction ( PyPyTestFunction ) : <EOL> def _haskeyword ( self , keyword ) : <EOL> return keyword == '<STR_LIT>' or super ( IntTestFunction , self ) . _haskeyword ( keyword ) <EOL> def _keywords ( self ) : <EOL> return super ( IntTestFunction , self ) . _keywords ( ) + [ '<STR_LIT>' ] <EOL> def runtest ( self ) : <EOL> try : <EOL> super ( IntTestFunction , self ) . runtest ( ) <EOL> except OperationError , e : <EOL> check_keyboard_interrupt ( e ) <EOL> raise <EOL> except Exception , e : <EOL> cls = e . __class__ <EOL> while cls is not Exception : <EOL> if cls . __name__ == '<STR_LIT>' : <EOL> from distutils . errors import DistutilsPlatformError <EOL> if isinstance ( e , DistutilsPlatformError ) : <EOL> py . test . skip ( '<STR_LIT>' % ( e . __class__ . __name__ , e ) ) <EOL> cls = cls . __bases__ [ <NUM_LIT:0> ] <EOL> raise <EOL> if '<STR_LIT>' in sys . modules : <EOL> global _pygame_imported <EOL> if not _pygame_imported : <EOL> _pygame_imported = True <EOL> assert option . view , ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> class AppTestFunction ( PyPyTestFunction ) : <EOL> def _prunetraceback ( self , traceback ) : <EOL> return traceback <EOL> def _haskeyword ( self , keyword ) : <EOL> return keyword == '<STR_LIT>' or super ( AppTestFunction , self ) . _haskeyword ( keyword ) <EOL> def _keywords ( self ) : <EOL> return [ '<STR_LIT>' ] + super ( AppTestFunction , self ) . _keywords ( ) <EOL> def runtest ( self ) : <EOL> target = self . obj <EOL> if option . runappdirect : <EOL> return target ( ) <EOL> space = gettestobjspace ( ) <EOL> func = app2interp_temp ( target ) <EOL> print "<STR_LIT>" , func <EOL> self . execute_appex ( space , func , space ) <EOL> class AppTestMethod ( AppTestFunction ) : <EOL> def setup ( self ) : <EOL> super ( AppTestMethod , self ) . setup ( ) <EOL> instance = self . parent . obj <EOL> w_instance = self . parent . w_instance <EOL> space = instance . space <EOL> for name in dir ( instance ) : <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> if option . runappdirect : <EOL> obj = getwithoutbinding ( instance , name ) <EOL> setattr ( instance , name [ <NUM_LIT:2> : ] , obj ) <EOL> else : <EOL> space . setattr ( w_instance , space . wrap ( name [ <NUM_LIT:2> : ] ) , <EOL> getattr ( instance , name ) ) <EOL> def runtest ( self ) : <EOL> target = self . obj <EOL> if option . runappdirect : <EOL> return target ( ) <EOL> space = target . im_self . space <EOL> func = app2interp_temp ( target . im_func ) <EOL> w_instance = self . parent . w_instance <EOL> self . execute_appex ( space , func , space , w_instance ) <EOL> class PyPyClassCollector ( py . test . collect . Class ) : <EOL> def setup ( self ) : <EOL> cls = self . obj <EOL> cls . space = LazyObjSpaceGetter ( ) <EOL> super ( PyPyClassCollector , self ) . setup ( ) <EOL> class IntClassCollector ( PyPyClassCollector ) : <EOL> Function = IntTestFunction <EOL> def _haskeyword ( self , keyword ) : <EOL> return keyword == '<STR_LIT>' or super ( IntClassCollector , self ) . _haskeyword ( keyword ) <EOL> def _keywords ( self ) : <EOL> return super ( IntClassCollector , self ) . _keywords ( ) + [ '<STR_LIT>' ] <EOL> class AppClassInstance ( py . test . collect . Instance ) : <EOL> Function = AppTestMethod <EOL> def setup ( self ) : <EOL> super ( AppClassInstance , self ) . setup ( ) <EOL> instance = self . obj <EOL> space = instance . space <EOL> w_class = self . parent . w_class <EOL> if option . runappdirect : <EOL> self . w_instance = instance <EOL> else : <EOL> self . w_instance = space . call_function ( w_class ) <EOL> class AppClassCollector ( PyPyClassCollector ) : <EOL> Instance = AppClassInstance <EOL> def _haskeyword ( self , keyword ) : <EOL> return keyword == '<STR_LIT>' or super ( AppClassCollector , self ) . _haskeyword ( keyword ) <EOL> def _keywords ( self ) : <EOL> return super ( AppClassCollector , self ) . _keywords ( ) + [ '<STR_LIT>' ] <EOL> def setup ( self ) : <EOL> super ( AppClassCollector , self ) . setup ( ) <EOL> cls = self . obj <EOL> space = cls . space <EOL> clsname = cls . __name__ <EOL> if option . runappdirect : <EOL> w_class = cls <EOL> else : <EOL> w_class = space . call_function ( space . w_type , <EOL> space . wrap ( clsname ) , <EOL> space . newtuple ( [ ] ) , <EOL> space . newdict ( ) ) <EOL> self . w_class = w_class <EOL> class ExpectTestMethod ( py . test . collect . Function ) : <EOL> def safe_name ( target ) : <EOL> s = "<STR_LIT:_>" . join ( target ) <EOL> s = s . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> s = s . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> s = s . replace ( "<STR_LIT:.>" , "<STR_LIT:_>" ) <EOL> return s <EOL> safe_name = staticmethod ( safe_name ) <EOL> def safe_filename ( self ) : <EOL> name = self . safe_name ( self . listnames ( ) ) <EOL> num = <NUM_LIT:0> <EOL> while udir . join ( name + '<STR_LIT>' ) . check ( ) : <EOL> num += <NUM_LIT:1> <EOL> name = self . safe_name ( self . listnames ( ) ) + "<STR_LIT:_>" + str ( num ) <EOL> return name + '<STR_LIT>' <EOL> def _spawn ( self , * args , ** kwds ) : <EOL> import pexpect <EOL> child = pexpect . spawn ( * args , ** kwds ) <EOL> child . logfile = sys . stdout <EOL> return child <EOL> def spawn ( self , argv ) : <EOL> return self . _spawn ( sys . executable , argv ) <EOL> def runtest ( self ) : <EOL> target = self . obj <EOL> import pexpect <EOL> source = py . code . Source ( target ) [ <NUM_LIT:1> : ] . deindent ( ) <EOL> filename = self . safe_filename ( ) <EOL> source . lines = [ '<STR_LIT>' , <EOL> '<STR_LIT>' % repr ( os . path . dirname ( pypydir ) ) <EOL> ] + source . lines <EOL> source . lines . append ( '<STR_LIT>' % filename ) <EOL> f = udir . join ( filename ) <EOL> f . write ( source ) <EOL> child = self . spawn ( [ str ( f ) ] ) <EOL> import re <EOL> child . expect ( re . escape ( filename + "<STR_LIT>" ) ) <EOL> class ExpectClassInstance ( py . test . collect . Instance ) : <EOL> Function = ExpectTestMethod <EOL> class ExpectClassCollector ( py . test . collect . Class ) : <EOL> Instance = ExpectClassInstance <EOL> def setup ( self ) : <EOL> super ( ExpectClassCollector , self ) . setup ( ) <EOL> try : <EOL> import pexpect <EOL> except ImportError : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> class Directory ( py . test . collect . Directory ) : <EOL> def consider_dir ( self , path ) : <EOL> if path == rootdir . join ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:test>" ) : <EOL> py . test . skip ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return super ( Directory , self ) . consider_dir ( path ) <EOL> def recfilter ( self , path ) : <EOL> return ( py . test . collect . Directory . recfilter ( self , path ) <EOL> and path . check ( link = <NUM_LIT:0> ) ) </s>
