<s> """<STR_LIT>""" <EOL> import py <EOL> def pytest_addoption ( parser ) : <EOL> group = parser . addgroup ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> group . addoption ( '<STR_LIT>' , action = "<STR_LIT:store>" , dest = "<STR_LIT>" , metavar = "<STR_LIT:path>" , default = None , <EOL> help = "<STR_LIT>" ) <EOL> def pytest_configure ( config ) : <EOL> resultlog = config . option . resultlog <EOL> if resultlog : <EOL> logfile = open ( resultlog , '<STR_LIT:w>' , <NUM_LIT:1> ) <EOL> config . _resultlog = ResultLog ( logfile ) <EOL> config . pluginmanager . register ( config . _resultlog ) <EOL> def pytest_unconfigure ( config ) : <EOL> resultlog = getattr ( config , '<STR_LIT>' , None ) <EOL> if resultlog : <EOL> resultlog . logfile . close ( ) <EOL> del config . _resultlog <EOL> config . pluginmanager . unregister ( resultlog ) <EOL> def generic_path ( item ) : <EOL> chain = item . listchain ( ) <EOL> gpath = [ chain [ <NUM_LIT:0> ] . name ] <EOL> fspath = chain [ <NUM_LIT:0> ] . fspath <EOL> fspart = False <EOL> for node in chain [ <NUM_LIT:1> : ] : <EOL> newfspath = node . fspath <EOL> if newfspath == fspath : <EOL> if fspart : <EOL> gpath . append ( '<STR_LIT::>' ) <EOL> fspart = False <EOL> else : <EOL> gpath . append ( '<STR_LIT:.>' ) <EOL> else : <EOL> gpath . append ( '<STR_LIT:/>' ) <EOL> fspart = True <EOL> name = node . name <EOL> if name [ <NUM_LIT:0> ] in '<STR_LIT>' : <EOL> gpath . pop ( ) <EOL> gpath . append ( name ) <EOL> fspath = newfspath <EOL> return '<STR_LIT>' . join ( gpath ) <EOL> class ResultLog ( object ) : <EOL> def __init__ ( self , logfile ) : <EOL> self . logfile = logfile <EOL> def write_log_entry ( self , testpath , shortrepr , longrepr ) : <EOL> print >> self . logfile , "<STR_LIT>" % ( shortrepr , testpath ) <EOL> for line in longrepr . splitlines ( ) : <EOL> print >> self . logfile , "<STR_LIT>" % line <EOL> def log_outcome ( self , node , shortrepr , longrepr ) : <EOL> testpath = generic_path ( node ) <EOL> self . write_log_entry ( testpath , shortrepr , longrepr ) <EOL> def pytest_runtest_logreport ( self , report ) : <EOL> code = report . shortrepr <EOL> if report . passed : <EOL> longrepr = "<STR_LIT>" <EOL> elif report . failed : <EOL> longrepr = str ( report . longrepr ) <EOL> elif report . skipped : <EOL> longrepr = str ( report . longrepr . reprcrash . message ) <EOL> self . log_outcome ( report . item , code , longrepr ) <EOL> def pytest_collectreport ( self , report ) : <EOL> if not report . passed : <EOL> if report . failed : <EOL> code = "<STR_LIT:F>" <EOL> else : <EOL> assert report . skipped <EOL> code = "<STR_LIT:S>" <EOL> longrepr = str ( report . longrepr . reprcrash ) <EOL> self . log_outcome ( report . collector , code , longrepr ) <EOL> def pytest_internalerror ( self , excrepr ) : <EOL> path = excrepr . reprcrash . path <EOL> self . write_log_entry ( path , '<STR_LIT:!>' , str ( excrepr ) ) <EOL> import os , StringIO <EOL> def test_generic_path ( ) : <EOL> from py . __ . test . collect import Node , Item , FSCollector <EOL> p1 = Node ( '<STR_LIT:a>' ) <EOL> assert p1 . fspath is None <EOL> p2 = Node ( '<STR_LIT:B>' , parent = p1 ) <EOL> p3 = Node ( '<STR_LIT>' , parent = p2 ) <EOL> item = Item ( '<STR_LIT:c>' , parent = p3 ) <EOL> res = generic_path ( item ) <EOL> assert res == '<STR_LIT>' <EOL> p0 = FSCollector ( '<STR_LIT>' ) <EOL> p1 = FSCollector ( '<STR_LIT>' , parent = p0 ) <EOL> p2 = Node ( '<STR_LIT:B>' , parent = p1 ) <EOL> p3 = Node ( '<STR_LIT>' , parent = p2 ) <EOL> p4 = Node ( '<STR_LIT:c>' , parent = p3 ) <EOL> item = Item ( '<STR_LIT>' , parent = p4 ) <EOL> res = generic_path ( item ) <EOL> assert res == '<STR_LIT>' <EOL> def test_write_log_entry ( ) : <EOL> reslog = ResultLog ( None ) <EOL> reslog . logfile = StringIO . StringIO ( ) <EOL> reslog . write_log_entry ( '<STR_LIT:name>' , '<STR_LIT:.>' , '<STR_LIT>' ) <EOL> entry = reslog . logfile . getvalue ( ) <EOL> assert entry [ - <NUM_LIT:1> ] == '<STR_LIT:\n>' <EOL> entry_lines = entry . splitlines ( ) <EOL> assert len ( entry_lines ) == <NUM_LIT:1> <EOL> assert entry_lines [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> reslog . logfile = StringIO . StringIO ( ) <EOL> reslog . write_log_entry ( '<STR_LIT:name>' , '<STR_LIT:s>' , '<STR_LIT>' ) <EOL> entry = reslog . logfile . getvalue ( ) <EOL> assert entry [ - <NUM_LIT:1> ] == '<STR_LIT:\n>' <EOL> entry_lines = entry . splitlines ( ) <EOL> assert len ( entry_lines ) == <NUM_LIT:2> <EOL> assert entry_lines [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> assert entry_lines [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> reslog . logfile = StringIO . StringIO ( ) <EOL> reslog . write_log_entry ( '<STR_LIT:name>' , '<STR_LIT:s>' , '<STR_LIT>' ) <EOL> entry = reslog . logfile . getvalue ( ) <EOL> assert entry [ - <NUM_LIT:1> ] == '<STR_LIT:\n>' <EOL> entry_lines = entry . splitlines ( ) <EOL> assert len ( entry_lines ) == <NUM_LIT:2> <EOL> assert entry_lines [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> assert entry_lines [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> reslog . logfile = StringIO . StringIO ( ) <EOL> longrepr = '<STR_LIT>' <EOL> reslog . write_log_entry ( '<STR_LIT:name>' , '<STR_LIT:F>' , longrepr ) <EOL> entry = reslog . logfile . getvalue ( ) <EOL> assert entry [ - <NUM_LIT:1> ] == '<STR_LIT:\n>' <EOL> entry_lines = entry . splitlines ( ) <EOL> assert len ( entry_lines ) == <NUM_LIT:5> <EOL> assert entry_lines [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> assert entry_lines [ <NUM_LIT:1> : ] == [ '<STR_LIT:U+0020>' + line for line in longrepr . splitlines ( ) ] <EOL> class TestWithFunctionIntegration : <EOL> def getresultlog ( self , testdir , arg ) : <EOL> resultlog = testdir . tmpdir . join ( "<STR_LIT>" ) <EOL> testdir . plugins . append ( "<STR_LIT>" ) <EOL> args = [ "<STR_LIT>" % resultlog ] + [ arg ] <EOL> testdir . runpytest ( * args ) <EOL> return filter ( None , resultlog . readlines ( cr = <NUM_LIT:0> ) ) <EOL> def test_collection_report ( self , testdir ) : <EOL> ok = testdir . makepyfile ( test_collection_ok = "<STR_LIT>" ) <EOL> skip = testdir . makepyfile ( test_collection_skip = "<STR_LIT>" ) <EOL> fail = testdir . makepyfile ( test_collection_fail = "<STR_LIT>" ) <EOL> lines = self . getresultlog ( testdir , ok ) <EOL> assert not lines <EOL> lines = self . getresultlog ( testdir , skip ) <EOL> assert len ( lines ) == <NUM_LIT:2> <EOL> assert lines [ <NUM_LIT:0> ] . startswith ( "<STR_LIT>" ) <EOL> assert lines [ <NUM_LIT:0> ] . endswith ( "<STR_LIT>" ) <EOL> assert lines [ <NUM_LIT:1> ] . startswith ( "<STR_LIT:U+0020>" ) <EOL> assert lines [ <NUM_LIT:1> ] . endswith ( "<STR_LIT>" ) <EOL> lines = self . getresultlog ( testdir , fail ) <EOL> assert lines <EOL> assert lines [ <NUM_LIT:0> ] . startswith ( "<STR_LIT>" ) <EOL> assert lines [ <NUM_LIT:0> ] . endswith ( "<STR_LIT>" ) , lines [ <NUM_LIT:0> ] <EOL> for x in lines [ <NUM_LIT:1> : ] : <EOL> assert x . startswith ( "<STR_LIT:U+0020>" ) <EOL> assert "<STR_LIT>" in "<STR_LIT>" . join ( lines [ <NUM_LIT:1> : ] ) <EOL> def test_log_test_outcomes ( self , testdir ) : <EOL> mod = testdir . makepyfile ( test_mod = """<STR_LIT>""" ) <EOL> lines = self . getresultlog ( testdir , mod ) <EOL> assert len ( lines ) >= <NUM_LIT:3> <EOL> assert lines [ <NUM_LIT:0> ] . startswith ( "<STR_LIT>" ) <EOL> assert lines [ <NUM_LIT:0> ] . endswith ( "<STR_LIT>" ) <EOL> assert lines [ <NUM_LIT:1> ] . startswith ( "<STR_LIT>" ) , lines [ <NUM_LIT:1> ] <EOL> assert lines [ <NUM_LIT:1> ] . endswith ( "<STR_LIT>" ) <EOL> assert lines [ <NUM_LIT:2> ] . find ( "<STR_LIT:hello>" ) != - <NUM_LIT:1> <EOL> assert lines [ <NUM_LIT:3> ] . startswith ( "<STR_LIT>" ) <EOL> assert lines [ <NUM_LIT:3> ] . endswith ( "<STR_LIT>" ) <EOL> tb = "<STR_LIT>" . join ( lines [ <NUM_LIT:4> : ] ) <EOL> assert tb . find ( "<STR_LIT>" ) != - <NUM_LIT:1> <EOL> def test_internal_exception ( self ) : <EOL> try : <EOL> raise ValueError <EOL> except ValueError : <EOL> excinfo = py . code . ExceptionInfo ( ) <EOL> reslog = ResultLog ( StringIO . StringIO ( ) ) <EOL> reslog . pytest_internalerror ( excinfo . getrepr ( ) ) <EOL> entry = reslog . logfile . getvalue ( ) <EOL> entry_lines = entry . splitlines ( ) <EOL> assert entry_lines [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) <EOL> assert os . path . basename ( __file__ ) [ : - <NUM_LIT:1> ] in entry_lines [ <NUM_LIT:0> ] <EOL> assert entry_lines [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] == '<STR_LIT:U+0020>' <EOL> assert '<STR_LIT>' in entry <EOL> def test_generic ( testdir , LineMatcher ) : <EOL> testdir . plugins . append ( "<STR_LIT>" ) <EOL> testdir . makepyfile ( """<STR_LIT>""" ) <EOL> testdir . runpytest ( "<STR_LIT>" ) <EOL> lines = testdir . tmpdir . join ( "<STR_LIT>" ) . readlines ( cr = <NUM_LIT:0> ) <EOL> LineMatcher ( lines ) . fnmatch_lines ( [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] ) </s>
