<s> """<STR_LIT>""" <EOL> import py <EOL> pydir = py . path . local ( py . __file__ ) . dirpath ( ) <EOL> def configproperty ( name ) : <EOL> def fget ( self ) : <EOL> return self . config . getvalue ( name , self . fspath ) <EOL> return property ( fget ) <EOL> class Node ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , parent = None ) : <EOL> self . name = name <EOL> self . parent = parent <EOL> self . config = getattr ( parent , '<STR_LIT>' , None ) <EOL> self . fspath = getattr ( parent , '<STR_LIT>' , None ) <EOL> def _checkcollectable ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . parent . _memocollect ( ) <EOL> def __getstate__ ( self ) : <EOL> return ( self . name , self . parent ) <EOL> def __setstate__ ( self , ( name , parent ) ) : <EOL> try : <EOL> colitems = parent . _memocollect ( ) <EOL> except KeyboardInterrupt : <EOL> raise <EOL> except Exception : <EOL> self . name = name <EOL> self . parent = parent <EOL> self . config = parent . config <EOL> else : <EOL> for colitem in colitems : <EOL> if colitem . name == name : <EOL> self . __dict__ = colitem . __dict__ <EOL> break <EOL> def __repr__ ( self ) : <EOL> if getattr ( self . config . option , '<STR_LIT>' , False ) : <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , <EOL> getattr ( self , '<STR_LIT:name>' , None ) , id ( self ) ) <EOL> else : <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , <EOL> getattr ( self , '<STR_LIT:name>' , None ) ) <EOL> def __eq__ ( self , other ) : <EOL> if not isinstance ( other , Node ) : <EOL> return False <EOL> return self . name == other . name and self . parent == other . parent <EOL> def __ne__ ( self , other ) : <EOL> return not self == other <EOL> def __hash__ ( self ) : <EOL> return hash ( ( self . name , self . parent ) ) <EOL> def setup ( self ) : <EOL> pass <EOL> def teardown ( self ) : <EOL> pass <EOL> def _memoizedcall ( self , attrname , function ) : <EOL> exattrname = "<STR_LIT>" + attrname <EOL> failure = getattr ( self , exattrname , None ) <EOL> if failure is not None : <EOL> raise failure [ <NUM_LIT:0> ] , failure [ <NUM_LIT:1> ] , failure [ <NUM_LIT:2> ] <EOL> if hasattr ( self , attrname ) : <EOL> return getattr ( self , attrname ) <EOL> try : <EOL> res = function ( ) <EOL> except ( KeyboardInterrupt , SystemExit ) : <EOL> raise <EOL> except : <EOL> failure = py . std . sys . exc_info ( ) <EOL> setattr ( self , exattrname , failure ) <EOL> raise <EOL> setattr ( self , attrname , res ) <EOL> return res <EOL> def listchain ( self , rootfirst = False ) : <EOL> """<STR_LIT>""" <EOL> l = [ self ] <EOL> while <NUM_LIT:1> : <EOL> x = l [ - <NUM_LIT:1> ] <EOL> if x . parent is not None : <EOL> l . append ( x . parent ) <EOL> else : <EOL> if not rootfirst : <EOL> l . reverse ( ) <EOL> return l <EOL> def listnames ( self ) : <EOL> return [ x . name for x in self . listchain ( ) ] <EOL> def getparent ( self , cls ) : <EOL> current = self <EOL> while current and not isinstance ( current , cls ) : <EOL> current = current . parent <EOL> return current <EOL> def _getitembynames ( self , namelist ) : <EOL> cur = self <EOL> for name in namelist : <EOL> if name : <EOL> next = cur . collect_by_name ( name ) <EOL> if next is None : <EOL> existingnames = [ x . name for x in self . _memocollect ( ) ] <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( cur , name , existingnames ) ) <EOL> raise AssertionError ( msg ) <EOL> cur = next <EOL> return cur <EOL> def _getfsnode ( self , path ) : <EOL> if path == self . fspath : <EOL> return self <EOL> basenames = path . relto ( self . fspath ) . split ( path . sep ) <EOL> cur = self <EOL> while basenames : <EOL> basename = basenames . pop ( <NUM_LIT:0> ) <EOL> assert basename <EOL> fspath = cur . fspath . join ( basename ) <EOL> colitems = cur . _memocollect ( ) <EOL> l = [ ] <EOL> for colitem in colitems : <EOL> if colitem . fspath == fspath or colitem . name == basename : <EOL> l . append ( colitem ) <EOL> if not l : <EOL> raise self . config . Error ( "<STR_LIT>" % ( fspath , ) ) <EOL> if basenames : <EOL> if len ( l ) > <NUM_LIT:1> : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( cur , fspath , colitems ) ) <EOL> raise self . config . Error ( "<STR_LIT>" % ( fspath , ) ) <EOL> cur = l [ <NUM_LIT:0> ] <EOL> else : <EOL> if len ( l ) > <NUM_LIT:1> : <EOL> cur = l <EOL> else : <EOL> cur = l [ <NUM_LIT:0> ] <EOL> break <EOL> return cur <EOL> def readkeywords ( self ) : <EOL> return dict ( [ ( x , True ) for x in self . _keywords ( ) ] ) <EOL> def _keywords ( self ) : <EOL> return [ self . name ] <EOL> def _skipbykeyword ( self , keywordexpr ) : <EOL> """<STR_LIT>""" <EOL> if not keywordexpr : <EOL> return <EOL> chain = self . listchain ( ) <EOL> for key in filter ( None , keywordexpr . split ( ) ) : <EOL> eor = key [ : <NUM_LIT:1> ] == '<STR_LIT:->' <EOL> if eor : <EOL> key = key [ <NUM_LIT:1> : ] <EOL> if not ( eor ^ self . _matchonekeyword ( key , chain ) ) : <EOL> return True <EOL> def _matchonekeyword ( self , key , chain ) : <EOL> elems = key . split ( "<STR_LIT:.>" ) <EOL> chain = [ item . readkeywords ( ) for item in chain if item . _keywords ( ) ] <EOL> for start , _ in enumerate ( chain ) : <EOL> if start + len ( elems ) > len ( chain ) : <EOL> return False <EOL> for num , elem in enumerate ( elems ) : <EOL> for keyword in chain [ num + start ] : <EOL> ok = False <EOL> if elem in keyword : <EOL> ok = True <EOL> break <EOL> if not ok : <EOL> break <EOL> if num == len ( elems ) - <NUM_LIT:1> and ok : <EOL> return True <EOL> return False <EOL> def _prunetraceback ( self , traceback ) : <EOL> return traceback <EOL> def _totrail ( self ) : <EOL> """<STR_LIT>""" <EOL> chain = self . listchain ( ) <EOL> topdir = self . config . topdir <EOL> relpath = chain [ <NUM_LIT:0> ] . fspath . relto ( topdir ) <EOL> if not relpath : <EOL> if chain [ <NUM_LIT:0> ] . fspath == topdir : <EOL> relpath = "<STR_LIT:.>" <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" <EOL> % ( chain [ <NUM_LIT:0> ] . fspath , topdir ) ) <EOL> return relpath , tuple ( [ x . name for x in chain [ <NUM_LIT:1> : ] ] ) <EOL> def _fromtrail ( trail , config ) : <EOL> relpath , names = trail <EOL> fspath = config . topdir . join ( relpath ) <EOL> col = config . getfsnode ( fspath ) <EOL> return col . _getitembynames ( names ) <EOL> _fromtrail = staticmethod ( _fromtrail ) <EOL> def _repr_failure_py ( self , excinfo , outerr = None ) : <EOL> assert outerr is None , "<STR_LIT>" <EOL> excinfo . traceback = self . _prunetraceback ( excinfo . traceback ) <EOL> if self . config . option . tbstyle == "<STR_LIT>" : <EOL> style = "<STR_LIT>" <EOL> else : <EOL> style = "<STR_LIT>" <EOL> return excinfo . getrepr ( funcargs = True , <EOL> showlocals = self . config . option . showlocals , <EOL> style = style ) <EOL> repr_failure = _repr_failure_py <EOL> shortfailurerepr = "<STR_LIT:F>" <EOL> class Collector ( Node ) : <EOL> """<STR_LIT>""" <EOL> Directory = configproperty ( '<STR_LIT>' ) <EOL> Module = configproperty ( '<STR_LIT>' ) <EOL> def collect ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def collect_by_name ( self , name ) : <EOL> """<STR_LIT>""" <EOL> for colitem in self . _memocollect ( ) : <EOL> if colitem . name == name : <EOL> return colitem <EOL> def repr_failure ( self , excinfo , outerr = None ) : <EOL> """<STR_LIT>""" <EOL> assert outerr is None , "<STR_LIT>" <EOL> return self . _repr_failure_py ( excinfo ) <EOL> def _memocollect ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _memoizedcall ( '<STR_LIT>' , self . collect ) <EOL> def _deprecated_collect ( self ) : <EOL> attrname = '<STR_LIT>' <EOL> if hasattr ( self , attrname ) : <EOL> return <EOL> setattr ( self , attrname , True ) <EOL> method = getattr ( self . __class__ , '<STR_LIT>' , None ) <EOL> if method is not None and method != Collector . run : <EOL> warnoldcollect ( function = method ) <EOL> names = self . run ( ) <EOL> return filter ( None , [ self . join ( name ) for name in names ] ) <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ colitem . name for colitem in self . _memocollect ( ) ] <EOL> def join ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . collect_by_name ( name ) <EOL> def _prunetraceback ( self , traceback ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> path = self . fspath <EOL> ntraceback = traceback . cut ( path = self . fspath ) <EOL> if ntraceback == traceback : <EOL> ntraceback = ntraceback . cut ( excludepath = pydir ) <EOL> traceback = ntraceback . filter ( ) <EOL> return traceback <EOL> class FSCollector ( Collector ) : <EOL> def __init__ ( self , fspath , parent = None ) : <EOL> fspath = py . path . local ( fspath ) <EOL> super ( FSCollector , self ) . __init__ ( fspath . basename , parent ) <EOL> self . fspath = fspath <EOL> def __getstate__ ( self ) : <EOL> if self . parent is None : <EOL> topdir = self . config . topdir <EOL> relpath = self . fspath . relto ( topdir ) <EOL> if not relpath : <EOL> if self . fspath == topdir : <EOL> relpath = "<STR_LIT:.>" <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" <EOL> % ( self . fspath , topdir ) ) <EOL> return ( self . name , self . config , relpath ) <EOL> else : <EOL> return ( self . name , self . parent ) <EOL> def __setstate__ ( self , picklestate ) : <EOL> if len ( picklestate ) == <NUM_LIT:3> : <EOL> name , config , relpath = picklestate <EOL> fspath = config . topdir . join ( relpath ) <EOL> fsnode = config . getfsnode ( fspath ) <EOL> self . __dict__ . update ( fsnode . __dict__ ) <EOL> else : <EOL> name , parent = picklestate <EOL> self . __init__ ( parent . fspath . join ( name ) , parent = parent ) <EOL> class File ( FSCollector ) : <EOL> """<STR_LIT>""" <EOL> class Directory ( FSCollector ) : <EOL> def recfilter ( self , path ) : <EOL> if path . check ( dir = <NUM_LIT:1> , dotfile = <NUM_LIT:0> ) : <EOL> return path . basename not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def collect ( self ) : <EOL> l = self . _deprecated_collect ( ) <EOL> if l is not None : <EOL> return l <EOL> l = [ ] <EOL> for path in self . fspath . listdir ( sort = True ) : <EOL> res = self . consider ( path ) <EOL> if res is not None : <EOL> if isinstance ( res , ( list , tuple ) ) : <EOL> l . extend ( res ) <EOL> else : <EOL> l . append ( res ) <EOL> return l <EOL> def _ignore ( self , path ) : <EOL> ignore_paths = self . config . getconftest_pathlist ( "<STR_LIT>" , path = path ) <EOL> return ignore_paths and path in ignore_paths <EOL> if ignore_paths : <EOL> for p in ignore_paths : <EOL> if path == p or path . relto ( p ) : <EOL> return True <EOL> def consider ( self , path ) : <EOL> if self . _ignore ( path ) : <EOL> return <EOL> if path . check ( file = <NUM_LIT:1> ) : <EOL> res = self . consider_file ( path ) <EOL> elif path . check ( dir = <NUM_LIT:1> ) : <EOL> res = self . consider_dir ( path ) <EOL> else : <EOL> res = None <EOL> if isinstance ( res , list ) : <EOL> l = [ ] <EOL> for x in res : <EOL> if x not in l : <EOL> assert x . parent == self , "<STR_LIT>" <EOL> l . append ( x ) <EOL> res = l <EOL> return res <EOL> def consider_file ( self , path ) : <EOL> return self . config . hook . pytest_collect_file ( path = path , parent = self ) <EOL> def consider_dir ( self , path , usefilters = None ) : <EOL> if usefilters is not None : <EOL> py . log . _apiwarn ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> return self . config . hook . pytest_collect_directory ( <EOL> path = path , parent = self ) <EOL> class Item ( Node ) : <EOL> """<STR_LIT>""" <EOL> def _deprecated_testexecution ( self ) : <EOL> if self . __class__ . run != Item . run : <EOL> warnoldtestrun ( function = self . run ) <EOL> elif self . __class__ . execute != Item . execute : <EOL> warnoldtestrun ( function = self . execute ) <EOL> else : <EOL> return False <EOL> self . run ( ) <EOL> return True <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . execute ( self . obj ) <EOL> def execute ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> return obj ( ) <EOL> def reportinfo ( self ) : <EOL> return self . fspath , None , "<STR_LIT>" <EOL> def warnoldcollect ( function = None ) : <EOL> py . log . _apiwarn ( "<STR_LIT:1.0>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> stacklevel = <NUM_LIT:2> , function = function ) <EOL> def warnoldtestrun ( function = None ) : <EOL> py . log . _apiwarn ( "<STR_LIT:1.0>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> stacklevel = <NUM_LIT:2> , function = function ) </s>
