<s> """<STR_LIT>""" <EOL> import codecs <EOL> import gc <EOL> import os <EOL> import platform <EOL> import re <EOL> import subprocess <EOL> import sys <EOL> import time <EOL> import traceback <EOL> from fnmatch import fnmatch <EOL> from py . builtin import print_ <EOL> from _pytest . _code import Source <EOL> import py <EOL> import pytest <EOL> from _pytest . main import Session , EXIT_OK <EOL> def pytest_addoption ( parser ) : <EOL> parser . addoption ( '<STR_LIT>' , <EOL> action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , <EOL> help = ( "<STR_LIT>" ) ) <EOL> parser . addoption ( '<STR_LIT>' , default = "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> choices = ( "<STR_LIT>" , "<STR_LIT>" , ) , <EOL> help = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> def pytest_configure ( config ) : <EOL> global _pytest_fullpath <EOL> try : <EOL> _pytest_fullpath <EOL> except NameError : <EOL> _pytest_fullpath = os . path . abspath ( pytest . __file__ . rstrip ( "<STR_LIT>" ) ) <EOL> _pytest_fullpath = _pytest_fullpath . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if config . getvalue ( "<STR_LIT>" ) : <EOL> checker = LsofFdLeakChecker ( ) <EOL> if checker . matching_platform ( ) : <EOL> config . pluginmanager . register ( checker ) <EOL> class LsofFdLeakChecker ( object ) : <EOL> def get_open_files ( self ) : <EOL> out = self . _exec_lsof ( ) <EOL> open_files = self . _parse_lsof_output ( out ) <EOL> return open_files <EOL> def _exec_lsof ( self ) : <EOL> pid = os . getpid ( ) <EOL> return py . process . cmdexec ( "<STR_LIT>" % pid ) <EOL> def _parse_lsof_output ( self , out ) : <EOL> def isopen ( line ) : <EOL> return line . startswith ( '<STR_LIT:f>' ) and ( "<STR_LIT>" not in line and <EOL> '<STR_LIT>' not in line and "<STR_LIT>" not in line and '<STR_LIT>' not in line ) <EOL> open_files = [ ] <EOL> for line in out . split ( "<STR_LIT:\n>" ) : <EOL> if isopen ( line ) : <EOL> fields = line . split ( '<STR_LIT>' ) <EOL> fd = fields [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] <EOL> filename = fields [ <NUM_LIT:1> ] [ <NUM_LIT:1> : ] <EOL> if filename . startswith ( '<STR_LIT:/>' ) : <EOL> open_files . append ( ( fd , filename ) ) <EOL> return open_files <EOL> def matching_platform ( self ) : <EOL> try : <EOL> py . process . cmdexec ( "<STR_LIT>" ) <EOL> except ( py . process . cmdexec . Error , UnicodeDecodeError ) : <EOL> return False <EOL> else : <EOL> return True <EOL> @ pytest . hookimpl ( hookwrapper = True , tryfirst = True ) <EOL> def pytest_runtest_item ( self , item ) : <EOL> lines1 = self . get_open_files ( ) <EOL> yield <EOL> if hasattr ( sys , "<STR_LIT>" ) : <EOL> gc . collect ( ) <EOL> lines2 = self . get_open_files ( ) <EOL> new_fds = set ( [ t [ <NUM_LIT:0> ] for t in lines2 ] ) - set ( [ t [ <NUM_LIT:0> ] for t in lines1 ] ) <EOL> leaked_files = [ t for t in lines2 if t [ <NUM_LIT:0> ] in new_fds ] <EOL> if leaked_files : <EOL> error = [ ] <EOL> error . append ( "<STR_LIT>" % len ( leaked_files ) ) <EOL> error . extend ( [ str ( f ) for f in leaked_files ] ) <EOL> error . append ( "<STR_LIT>" ) <EOL> error . extend ( [ str ( f ) for f in lines1 ] ) <EOL> error . append ( "<STR_LIT>" ) <EOL> error . extend ( [ str ( f ) for f in lines2 ] ) <EOL> error . append ( error [ <NUM_LIT:0> ] ) <EOL> error . append ( "<STR_LIT>" % item . location ) <EOL> pytest . fail ( "<STR_LIT:\n>" . join ( error ) , pytrace = False ) <EOL> winpymap = { <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> } <EOL> def getexecutable ( name , cache = { } ) : <EOL> try : <EOL> return cache [ name ] <EOL> except KeyError : <EOL> executable = py . path . local . sysfind ( name ) <EOL> if executable : <EOL> if name == "<STR_LIT>" : <EOL> import subprocess <EOL> popen = subprocess . Popen ( [ str ( executable ) , "<STR_LIT>" ] , <EOL> universal_newlines = True , stderr = subprocess . PIPE ) <EOL> out , err = popen . communicate ( ) <EOL> if not err or "<STR_LIT>" not in err : <EOL> executable = None <EOL> if "<STR_LIT>" in err : <EOL> executable = None <EOL> cache [ name ] = executable <EOL> return executable <EOL> @ pytest . fixture ( params = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" , <EOL> '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def anypython ( request ) : <EOL> name = request . param <EOL> executable = getexecutable ( name ) <EOL> if executable is None : <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> executable = winpymap . get ( name , None ) <EOL> if executable : <EOL> executable = py . path . local ( executable ) <EOL> if executable . check ( ) : <EOL> return executable <EOL> pytest . skip ( "<STR_LIT>" % ( name , ) ) <EOL> return executable <EOL> @ pytest . fixture <EOL> def _pytest ( request ) : <EOL> """<STR_LIT>""" <EOL> return PytestArg ( request ) <EOL> class PytestArg : <EOL> def __init__ ( self , request ) : <EOL> self . request = request <EOL> def gethookrecorder ( self , hook ) : <EOL> hookrecorder = HookRecorder ( hook . _pm ) <EOL> self . request . addfinalizer ( hookrecorder . finish_recording ) <EOL> return hookrecorder <EOL> def get_public_names ( l ) : <EOL> """<STR_LIT>""" <EOL> return [ x for x in l if x [ <NUM_LIT:0> ] != "<STR_LIT:_>" ] <EOL> class ParsedCall : <EOL> def __init__ ( self , name , kwargs ) : <EOL> self . __dict__ . update ( kwargs ) <EOL> self . _name = name <EOL> def __repr__ ( self ) : <EOL> d = self . __dict__ . copy ( ) <EOL> del d [ '<STR_LIT>' ] <EOL> return "<STR_LIT>" % ( self . _name , d ) <EOL> class HookRecorder : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , pluginmanager ) : <EOL> self . _pluginmanager = pluginmanager <EOL> self . calls = [ ] <EOL> def before ( hook_name , hook_impls , kwargs ) : <EOL> self . calls . append ( ParsedCall ( hook_name , kwargs ) ) <EOL> def after ( outcome , hook_name , hook_impls , kwargs ) : <EOL> pass <EOL> self . _undo_wrapping = pluginmanager . add_hookcall_monitoring ( before , after ) <EOL> def finish_recording ( self ) : <EOL> self . _undo_wrapping ( ) <EOL> def getcalls ( self , names ) : <EOL> if isinstance ( names , str ) : <EOL> names = names . split ( ) <EOL> return [ call for call in self . calls if call . _name in names ] <EOL> def assert_contains ( self , entries ) : <EOL> __tracebackhide__ = True <EOL> i = <NUM_LIT:0> <EOL> entries = list ( entries ) <EOL> backlocals = sys . _getframe ( <NUM_LIT:1> ) . f_locals <EOL> while entries : <EOL> name , check = entries . pop ( <NUM_LIT:0> ) <EOL> for ind , call in enumerate ( self . calls [ i : ] ) : <EOL> if call . _name == name : <EOL> print_ ( "<STR_LIT>" , name , call ) <EOL> if eval ( check , backlocals , call . __dict__ ) : <EOL> print_ ( "<STR_LIT>" , repr ( check ) , "<STR_LIT>" , call ) <EOL> else : <EOL> print_ ( "<STR_LIT>" , repr ( check ) , "<STR_LIT:->" , call ) <EOL> continue <EOL> i += ind + <NUM_LIT:1> <EOL> break <EOL> print_ ( "<STR_LIT>" , name , "<STR_LIT>" , call ) <EOL> else : <EOL> pytest . fail ( "<STR_LIT>" % ( name , check ) ) <EOL> def popcall ( self , name ) : <EOL> __tracebackhide__ = True <EOL> for i , call in enumerate ( self . calls ) : <EOL> if call . _name == name : <EOL> del self . calls [ i ] <EOL> return call <EOL> lines = [ "<STR_LIT>" % ( name , ) ] <EOL> lines . extend ( [ "<STR_LIT>" % str ( x ) for x in self . calls ] ) <EOL> pytest . fail ( "<STR_LIT:\n>" . join ( lines ) ) <EOL> def getcall ( self , name ) : <EOL> l = self . getcalls ( name ) <EOL> assert len ( l ) == <NUM_LIT:1> , ( name , l ) <EOL> return l [ <NUM_LIT:0> ] <EOL> def getreports ( self , <EOL> names = "<STR_LIT>" ) : <EOL> return [ x . report for x in self . getcalls ( names ) ] <EOL> def matchreport ( self , inamepart = "<STR_LIT>" , <EOL> names = "<STR_LIT>" , when = None ) : <EOL> """<STR_LIT>""" <EOL> l = [ ] <EOL> for rep in self . getreports ( names = names ) : <EOL> try : <EOL> if not when and rep . when != "<STR_LIT>" and rep . passed : <EOL> continue <EOL> except AttributeError : <EOL> pass <EOL> if when and getattr ( rep , '<STR_LIT>' , None ) != when : <EOL> continue <EOL> if not inamepart or inamepart in rep . nodeid . split ( "<STR_LIT>" ) : <EOL> l . append ( rep ) <EOL> if not l : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( inamepart , ) ) <EOL> if len ( l ) > <NUM_LIT:1> : <EOL> raise ValueError ( <EOL> "<STR_LIT>" % ( inamepart , l ) ) <EOL> return l [ <NUM_LIT:0> ] <EOL> def getfailures ( self , <EOL> names = '<STR_LIT>' ) : <EOL> return [ rep for rep in self . getreports ( names ) if rep . failed ] <EOL> def getfailedcollections ( self ) : <EOL> return self . getfailures ( '<STR_LIT>' ) <EOL> def listoutcomes ( self ) : <EOL> passed = [ ] <EOL> skipped = [ ] <EOL> failed = [ ] <EOL> for rep in self . getreports ( <EOL> "<STR_LIT>" ) : <EOL> if rep . passed : <EOL> if getattr ( rep , "<STR_LIT>" , None ) == "<STR_LIT>" : <EOL> passed . append ( rep ) <EOL> elif rep . skipped : <EOL> skipped . append ( rep ) <EOL> elif rep . failed : <EOL> failed . append ( rep ) <EOL> return passed , skipped , failed <EOL> def countoutcomes ( self ) : <EOL> return [ len ( x ) for x in self . listoutcomes ( ) ] <EOL> def assertoutcome ( self , passed = <NUM_LIT:0> , skipped = <NUM_LIT:0> , failed = <NUM_LIT:0> ) : <EOL> realpassed , realskipped , realfailed = self . listoutcomes ( ) <EOL> assert passed == len ( realpassed ) <EOL> assert skipped == len ( realskipped ) <EOL> assert failed == len ( realfailed ) <EOL> def clear ( self ) : <EOL> self . calls [ : ] = [ ] <EOL> @ pytest . fixture <EOL> def linecomp ( request ) : <EOL> return LineComp ( ) <EOL> def pytest_funcarg__LineMatcher ( request ) : <EOL> return LineMatcher <EOL> @ pytest . fixture <EOL> def testdir ( request , tmpdir_factory ) : <EOL> return Testdir ( request , tmpdir_factory ) <EOL> rex_outcome = re . compile ( "<STR_LIT>" ) <EOL> class RunResult : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ret , outlines , errlines , duration ) : <EOL> self . ret = ret <EOL> self . outlines = outlines <EOL> self . errlines = errlines <EOL> self . stdout = LineMatcher ( outlines ) <EOL> self . stderr = LineMatcher ( errlines ) <EOL> self . duration = duration <EOL> def parseoutcomes ( self ) : <EOL> """<STR_LIT>""" <EOL> for line in reversed ( self . outlines ) : <EOL> if '<STR_LIT>' in line : <EOL> outcomes = rex_outcome . findall ( line ) <EOL> if outcomes : <EOL> d = { } <EOL> for num , cat in outcomes : <EOL> d [ cat ] = int ( num ) <EOL> return d <EOL> def assert_outcomes ( self , passed = <NUM_LIT:0> , skipped = <NUM_LIT:0> , failed = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> d = self . parseoutcomes ( ) <EOL> assert passed == d . get ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> assert skipped == d . get ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> assert failed == d . get ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> class Testdir : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , request , tmpdir_factory ) : <EOL> self . request = request <EOL> basetmp = tmpdir_factory . ensuretemp ( "<STR_LIT>" ) <EOL> name = request . function . __name__ <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> try : <EOL> tmpdir = basetmp . mkdir ( name + str ( i ) ) <EOL> except py . error . EEXIST : <EOL> continue <EOL> break <EOL> self . tmpdir = tmpdir <EOL> self . plugins = [ ] <EOL> self . _savesyspath = ( list ( sys . path ) , list ( sys . meta_path ) ) <EOL> self . _savemodulekeys = set ( sys . modules ) <EOL> self . chdir ( ) <EOL> self . request . addfinalizer ( self . finalize ) <EOL> method = self . request . config . getoption ( "<STR_LIT>" ) <EOL> if method == "<STR_LIT>" : <EOL> self . _runpytest_method = self . runpytest_inprocess <EOL> elif method == "<STR_LIT>" : <EOL> self . _runpytest_method = self . runpytest_subprocess <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . tmpdir , ) <EOL> def finalize ( self ) : <EOL> """<STR_LIT>""" <EOL> sys . path [ : ] , sys . meta_path [ : ] = self . _savesyspath <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> self . _olddir . chdir ( ) <EOL> self . delete_loaded_modules ( ) <EOL> def delete_loaded_modules ( self ) : <EOL> """<STR_LIT>""" <EOL> for name in set ( sys . modules ) . difference ( self . _savemodulekeys ) : <EOL> if name != "<STR_LIT>" : <EOL> del sys . modules [ name ] <EOL> def make_hook_recorder ( self , pluginmanager ) : <EOL> """<STR_LIT>""" <EOL> assert not hasattr ( pluginmanager , "<STR_LIT>" ) <EOL> pluginmanager . reprec = reprec = HookRecorder ( pluginmanager ) <EOL> self . request . addfinalizer ( reprec . finish_recording ) <EOL> return reprec <EOL> def chdir ( self ) : <EOL> """<STR_LIT>""" <EOL> old = self . tmpdir . chdir ( ) <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _olddir = old <EOL> def _makefile ( self , ext , args , kwargs ) : <EOL> items = list ( kwargs . items ( ) ) <EOL> if args : <EOL> source = py . builtin . _totext ( "<STR_LIT:\n>" ) . join ( <EOL> map ( py . builtin . _totext , args ) ) + py . builtin . _totext ( "<STR_LIT:\n>" ) <EOL> basename = self . request . function . __name__ <EOL> items . insert ( <NUM_LIT:0> , ( basename , source ) ) <EOL> ret = None <EOL> for name , value in items : <EOL> p = self . tmpdir . join ( name ) . new ( ext = ext ) <EOL> source = Source ( value ) <EOL> def my_totext ( s , encoding = "<STR_LIT:utf-8>" ) : <EOL> if py . builtin . _isbytes ( s ) : <EOL> s = py . builtin . _totext ( s , encoding = encoding ) <EOL> return s <EOL> source_unicode = "<STR_LIT:\n>" . join ( [ my_totext ( line ) for line in source . lines ] ) <EOL> source = py . builtin . _totext ( source_unicode ) <EOL> content = source . strip ( ) . encode ( "<STR_LIT:utf-8>" ) <EOL> p . write ( content , "<STR_LIT:wb>" ) <EOL> if ret is None : <EOL> ret = p <EOL> return ret <EOL> def makefile ( self , ext , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . _makefile ( ext , args , kwargs ) <EOL> def makeconftest ( self , source ) : <EOL> """<STR_LIT>""" <EOL> return self . makepyfile ( conftest = source ) <EOL> def makeini ( self , source ) : <EOL> """<STR_LIT>""" <EOL> return self . makefile ( '<STR_LIT>' , tox = source ) <EOL> def getinicfg ( self , source ) : <EOL> """<STR_LIT>""" <EOL> p = self . makeini ( source ) <EOL> return py . iniconfig . IniConfig ( p ) [ '<STR_LIT>' ] <EOL> def makepyfile ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . _makefile ( '<STR_LIT>' , args , kwargs ) <EOL> def maketxtfile ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . _makefile ( '<STR_LIT>' , args , kwargs ) <EOL> def syspathinsert ( self , path = None ) : <EOL> """<STR_LIT>""" <EOL> if path is None : <EOL> path = self . tmpdir <EOL> sys . path . insert ( <NUM_LIT:0> , str ( path ) ) <EOL> self . _possibly_invalidate_import_caches ( ) <EOL> def _possibly_invalidate_import_caches ( self ) : <EOL> try : <EOL> import importlib <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> if hasattr ( importlib , "<STR_LIT>" ) : <EOL> importlib . invalidate_caches ( ) <EOL> def mkdir ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . tmpdir . mkdir ( name ) <EOL> def mkpydir ( self , name ) : <EOL> """<STR_LIT>""" <EOL> p = self . mkdir ( name ) <EOL> p . ensure ( "<STR_LIT>" ) <EOL> return p <EOL> Session = Session <EOL> def getnode ( self , config , arg ) : <EOL> """<STR_LIT>""" <EOL> session = Session ( config ) <EOL> assert '<STR_LIT>' not in str ( arg ) <EOL> p = py . path . local ( arg ) <EOL> config . hook . pytest_sessionstart ( session = session ) <EOL> res = session . perform_collect ( [ str ( p ) ] , genitems = False ) [ <NUM_LIT:0> ] <EOL> config . hook . pytest_sessionfinish ( session = session , exitstatus = EXIT_OK ) <EOL> return res <EOL> def getpathnode ( self , path ) : <EOL> """<STR_LIT>""" <EOL> config = self . parseconfigure ( path ) <EOL> session = Session ( config ) <EOL> x = session . fspath . bestrelpath ( path ) <EOL> config . hook . pytest_sessionstart ( session = session ) <EOL> res = session . perform_collect ( [ x ] , genitems = False ) [ <NUM_LIT:0> ] <EOL> config . hook . pytest_sessionfinish ( session = session , exitstatus = EXIT_OK ) <EOL> return res <EOL> def genitems ( self , colitems ) : <EOL> """<STR_LIT>""" <EOL> session = colitems [ <NUM_LIT:0> ] . session <EOL> result = [ ] <EOL> for colitem in colitems : <EOL> result . extend ( session . genitems ( colitem ) ) <EOL> return result <EOL> def runitem ( self , source ) : <EOL> """<STR_LIT>""" <EOL> item = self . getitem ( source ) <EOL> testclassinstance = self . request . instance <EOL> runner = testclassinstance . getrunner ( ) <EOL> return runner ( item ) <EOL> def inline_runsource ( self , source , * cmdlineargs ) : <EOL> """<STR_LIT>""" <EOL> p = self . makepyfile ( source ) <EOL> l = list ( cmdlineargs ) + [ p ] <EOL> return self . inline_run ( * l ) <EOL> def inline_genitems ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> rec = self . inline_run ( "<STR_LIT>" , * args ) <EOL> items = [ x . item for x in rec . getcalls ( "<STR_LIT>" ) ] <EOL> return items , rec <EOL> def inline_run ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> rec = [ ] <EOL> class Collect : <EOL> def pytest_configure ( x , config ) : <EOL> rec . append ( self . make_hook_recorder ( config . pluginmanager ) ) <EOL> plugins = kwargs . get ( "<STR_LIT>" ) or [ ] <EOL> plugins . append ( Collect ( ) ) <EOL> ret = pytest . main ( list ( args ) , plugins = plugins ) <EOL> self . delete_loaded_modules ( ) <EOL> if len ( rec ) == <NUM_LIT:1> : <EOL> reprec = rec . pop ( ) <EOL> else : <EOL> class reprec : <EOL> pass <EOL> reprec . ret = ret <EOL> if ret == <NUM_LIT:2> and not kwargs . get ( "<STR_LIT>" ) : <EOL> calls = reprec . getcalls ( "<STR_LIT>" ) <EOL> if calls and calls [ - <NUM_LIT:1> ] . excinfo . type == KeyboardInterrupt : <EOL> raise KeyboardInterrupt ( ) <EOL> return reprec <EOL> def runpytest_inprocess ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if kwargs . get ( "<STR_LIT>" ) : <EOL> self . syspathinsert ( ) <EOL> now = time . time ( ) <EOL> capture = py . io . StdCapture ( ) <EOL> try : <EOL> try : <EOL> reprec = self . inline_run ( * args , ** kwargs ) <EOL> except SystemExit as e : <EOL> class reprec : <EOL> ret = e . args [ <NUM_LIT:0> ] <EOL> except Exception : <EOL> traceback . print_exc ( ) <EOL> class reprec : <EOL> ret = <NUM_LIT:3> <EOL> finally : <EOL> out , err = capture . reset ( ) <EOL> sys . stdout . write ( out ) <EOL> sys . stderr . write ( err ) <EOL> res = RunResult ( reprec . ret , <EOL> out . split ( "<STR_LIT:\n>" ) , err . split ( "<STR_LIT:\n>" ) , <EOL> time . time ( ) - now ) <EOL> res . reprec = reprec <EOL> return res <EOL> def runpytest ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> args = self . _ensure_basetemp ( args ) <EOL> return self . _runpytest_method ( * args , ** kwargs ) <EOL> def _ensure_basetemp ( self , args ) : <EOL> args = [ str ( x ) for x in args ] <EOL> for x in args : <EOL> if str ( x ) . startswith ( '<STR_LIT>' ) : <EOL> break <EOL> else : <EOL> args . append ( "<STR_LIT>" % self . tmpdir . dirpath ( '<STR_LIT>' ) ) <EOL> return args <EOL> def parseconfig ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> args = self . _ensure_basetemp ( args ) <EOL> import _pytest . config <EOL> config = _pytest . config . _prepareconfig ( args , self . plugins ) <EOL> self . request . addfinalizer ( config . _ensure_unconfigure ) <EOL> return config <EOL> def parseconfigure ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> config = self . parseconfig ( * args ) <EOL> config . _do_configure ( ) <EOL> self . request . addfinalizer ( config . _ensure_unconfigure ) <EOL> return config <EOL> def getitem ( self , source , funcname = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> items = self . getitems ( source ) <EOL> for item in items : <EOL> if item . name == funcname : <EOL> return item <EOL> assert <NUM_LIT:0> , "<STR_LIT>" % ( <EOL> funcname , source , items ) <EOL> def getitems ( self , source ) : <EOL> """<STR_LIT>""" <EOL> modcol = self . getmodulecol ( source ) <EOL> return self . genitems ( [ modcol ] ) <EOL> def getmodulecol ( self , source , configargs = ( ) , withinit = False ) : <EOL> """<STR_LIT>""" <EOL> kw = { self . request . function . __name__ : Source ( source ) . strip ( ) } <EOL> path = self . makepyfile ( ** kw ) <EOL> if withinit : <EOL> self . makepyfile ( __init__ = "<STR_LIT:#>" ) <EOL> self . config = config = self . parseconfigure ( path , * configargs ) <EOL> node = self . getnode ( config , path ) <EOL> return node <EOL> def collect_by_name ( self , modcol , name ) : <EOL> """<STR_LIT>""" <EOL> for colitem in modcol . _memocollect ( ) : <EOL> if colitem . name == name : <EOL> return colitem <EOL> def popen ( self , cmdargs , stdout , stderr , ** kw ) : <EOL> """<STR_LIT>""" <EOL> env = os . environ . copy ( ) <EOL> env [ '<STR_LIT>' ] = os . pathsep . join ( filter ( None , [ <EOL> str ( os . getcwd ( ) ) , env . get ( '<STR_LIT>' , '<STR_LIT>' ) ] ) ) <EOL> kw [ '<STR_LIT>' ] = env <EOL> return subprocess . Popen ( cmdargs , <EOL> stdout = stdout , stderr = stderr , ** kw ) <EOL> def run ( self , * cmdargs ) : <EOL> """<STR_LIT>""" <EOL> return self . _run ( * cmdargs ) <EOL> def _run ( self , * cmdargs ) : <EOL> cmdargs = [ str ( x ) for x in cmdargs ] <EOL> p1 = self . tmpdir . join ( "<STR_LIT>" ) <EOL> p2 = self . tmpdir . join ( "<STR_LIT>" ) <EOL> print_ ( "<STR_LIT>" , '<STR_LIT:U+0020>' . join ( cmdargs ) ) <EOL> print_ ( "<STR_LIT>" , str ( py . path . local ( ) ) ) <EOL> f1 = codecs . open ( str ( p1 ) , "<STR_LIT:w>" , encoding = "<STR_LIT:utf8>" ) <EOL> f2 = codecs . open ( str ( p2 ) , "<STR_LIT:w>" , encoding = "<STR_LIT:utf8>" ) <EOL> try : <EOL> now = time . time ( ) <EOL> popen = self . popen ( cmdargs , stdout = f1 , stderr = f2 , <EOL> close_fds = ( sys . platform != "<STR_LIT:win32>" ) ) <EOL> ret = popen . wait ( ) <EOL> finally : <EOL> f1 . close ( ) <EOL> f2 . close ( ) <EOL> f1 = codecs . open ( str ( p1 ) , "<STR_LIT:r>" , encoding = "<STR_LIT:utf8>" ) <EOL> f2 = codecs . open ( str ( p2 ) , "<STR_LIT:r>" , encoding = "<STR_LIT:utf8>" ) <EOL> try : <EOL> out = f1 . read ( ) . splitlines ( ) <EOL> err = f2 . read ( ) . splitlines ( ) <EOL> finally : <EOL> f1 . close ( ) <EOL> f2 . close ( ) <EOL> self . _dump_lines ( out , sys . stdout ) <EOL> self . _dump_lines ( err , sys . stderr ) <EOL> return RunResult ( ret , out , err , time . time ( ) - now ) <EOL> def _dump_lines ( self , lines , fp ) : <EOL> try : <EOL> for line in lines : <EOL> py . builtin . print_ ( line , file = fp ) <EOL> except UnicodeEncodeError : <EOL> print ( "<STR_LIT>" % ( fp , ) ) <EOL> def _getpytestargs ( self ) : <EOL> return ( sys . executable , _pytest_fullpath , ) <EOL> def runpython ( self , script ) : <EOL> """<STR_LIT>""" <EOL> return self . run ( sys . executable , script ) <EOL> def runpython_c ( self , command ) : <EOL> """<STR_LIT>""" <EOL> return self . run ( sys . executable , "<STR_LIT:-c>" , command ) <EOL> def runpytest_subprocess ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> p = py . path . local . make_numbered_dir ( prefix = "<STR_LIT>" , <EOL> keep = None , rootdir = self . tmpdir ) <EOL> args = ( '<STR_LIT>' % p , ) + args <EOL> plugins = [ x for x in self . plugins if isinstance ( x , str ) ] <EOL> if plugins : <EOL> args = ( '<STR_LIT>' , plugins [ <NUM_LIT:0> ] ) + args <EOL> args = self . _getpytestargs ( ) + args <EOL> return self . run ( * args ) <EOL> def spawn_pytest ( self , string , expect_timeout = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> basetemp = self . tmpdir . mkdir ( "<STR_LIT>" ) <EOL> invoke = "<STR_LIT:U+0020>" . join ( map ( str , self . _getpytestargs ( ) ) ) <EOL> cmd = "<STR_LIT>" % ( invoke , basetemp , string ) <EOL> return self . spawn ( cmd , expect_timeout = expect_timeout ) <EOL> def spawn ( self , cmd , expect_timeout = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> pexpect = pytest . importorskip ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if hasattr ( sys , '<STR_LIT>' ) and '<STR_LIT>' in platform . machine ( ) : <EOL> pytest . skip ( "<STR_LIT>" ) <EOL> if sys . platform == "<STR_LIT>" : <EOL> pytest . xfail ( "<STR_LIT>" ) <EOL> if sys . platform . startswith ( "<STR_LIT>" ) : <EOL> pytest . xfail ( "<STR_LIT>" ) <EOL> logfile = self . tmpdir . join ( "<STR_LIT>" ) . open ( "<STR_LIT:wb>" ) <EOL> child = pexpect . spawn ( cmd , logfile = logfile ) <EOL> self . request . addfinalizer ( logfile . close ) <EOL> child . timeout = expect_timeout <EOL> return child <EOL> def getdecoded ( out ) : <EOL> try : <EOL> return out . decode ( "<STR_LIT:utf-8>" ) <EOL> except UnicodeDecodeError : <EOL> return "<STR_LIT>" % ( <EOL> py . io . saferepr ( out ) , ) <EOL> class LineComp : <EOL> def __init__ ( self ) : <EOL> self . stringio = py . io . TextIO ( ) <EOL> def assert_contains_lines ( self , lines2 ) : <EOL> """<STR_LIT>""" <EOL> __tracebackhide__ = True <EOL> val = self . stringio . getvalue ( ) <EOL> self . stringio . truncate ( <NUM_LIT:0> ) <EOL> self . stringio . seek ( <NUM_LIT:0> ) <EOL> lines1 = val . split ( "<STR_LIT:\n>" ) <EOL> return LineMatcher ( lines1 ) . fnmatch_lines ( lines2 ) <EOL> class LineMatcher : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , lines ) : <EOL> self . lines = lines <EOL> def str ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT:\n>" . join ( self . lines ) <EOL> def _getlines ( self , lines2 ) : <EOL> if isinstance ( lines2 , str ) : <EOL> lines2 = Source ( lines2 ) <EOL> if isinstance ( lines2 , Source ) : <EOL> lines2 = lines2 . strip ( ) . lines <EOL> return lines2 <EOL> def fnmatch_lines_random ( self , lines2 ) : <EOL> """<STR_LIT>""" <EOL> lines2 = self . _getlines ( lines2 ) <EOL> for line in lines2 : <EOL> for x in self . lines : <EOL> if line == x or fnmatch ( x , line ) : <EOL> print_ ( "<STR_LIT>" , repr ( line ) ) <EOL> break <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % line ) <EOL> def get_lines_after ( self , fnline ) : <EOL> """<STR_LIT>""" <EOL> for i , line in enumerate ( self . lines ) : <EOL> if fnline == line or fnmatch ( line , fnline ) : <EOL> return self . lines [ i + <NUM_LIT:1> : ] <EOL> raise ValueError ( "<STR_LIT>" % fnline ) <EOL> def fnmatch_lines ( self , lines2 ) : <EOL> """<STR_LIT>""" <EOL> def show ( arg1 , arg2 ) : <EOL> py . builtin . print_ ( arg1 , arg2 , file = sys . stderr ) <EOL> lines2 = self . _getlines ( lines2 ) <EOL> lines1 = self . lines [ : ] <EOL> nextline = None <EOL> extralines = [ ] <EOL> __tracebackhide__ = True <EOL> for line in lines2 : <EOL> nomatchprinted = False <EOL> while lines1 : <EOL> nextline = lines1 . pop ( <NUM_LIT:0> ) <EOL> if line == nextline : <EOL> show ( "<STR_LIT>" , repr ( line ) ) <EOL> break <EOL> elif fnmatch ( nextline , line ) : <EOL> show ( "<STR_LIT>" , repr ( line ) ) <EOL> show ( "<STR_LIT>" , repr ( nextline ) ) <EOL> break <EOL> else : <EOL> if not nomatchprinted : <EOL> show ( "<STR_LIT>" , repr ( line ) ) <EOL> nomatchprinted = True <EOL> show ( "<STR_LIT>" , repr ( nextline ) ) <EOL> extralines . append ( nextline ) <EOL> else : <EOL> pytest . fail ( "<STR_LIT>" % ( line , ) ) </s>
