<s> from pypy . jit . metainterp . test . oparser import pure_parse <EOL> from pypy . jit . metainterp import logger <EOL> from pypy . jit . metainterp . typesystem import llhelper <EOL> from StringIO import StringIO <EOL> from pypy . jit . metainterp . test . test_optimizeopt import equaloplists <EOL> from pypy . jit . metainterp . history import AbstractDescr , LoopToken , BasicFailDescr <EOL> class Descr ( AbstractDescr ) : <EOL> pass <EOL> class Logger ( logger . Logger ) : <EOL> def log_loop ( self , loop , namespace = { } ) : <EOL> self . log_stream = StringIO ( ) <EOL> self . namespace = namespace <EOL> logger . Logger . log_loop ( self , loop . inputargs , loop . operations ) <EOL> return self . log_stream . getvalue ( ) <EOL> def repr_of_descr ( self , descr ) : <EOL> for k , v in self . namespace . items ( ) : <EOL> if v == descr : <EOL> return k <EOL> return descr . repr_of_descr ( ) <EOL> class TestLogger ( object ) : <EOL> ts = llhelper <EOL> def reparse ( self , inp , namespace = None , check_equal = True ) : <EOL> """<STR_LIT>""" <EOL> if namespace is None : <EOL> namespace = { } <EOL> loop = pure_parse ( inp , namespace = namespace ) <EOL> logger = Logger ( self . ts ) <EOL> output = logger . log_loop ( loop , namespace ) <EOL> oloop = pure_parse ( output , namespace = namespace ) <EOL> if check_equal : <EOL> equaloplists ( loop . operations , oloop . operations ) <EOL> assert oloop . inputargs == loop . inputargs <EOL> return loop , oloop <EOL> def test_simple ( self ) : <EOL> inp = '''<STR_LIT>''' <EOL> self . reparse ( inp ) <EOL> def test_descr ( self ) : <EOL> inp = '''<STR_LIT>''' <EOL> somedescr = Descr ( ) <EOL> self . reparse ( inp , namespace = locals ( ) ) <EOL> def test_guard ( self ) : <EOL> inp = '''<STR_LIT>''' <EOL> self . reparse ( inp ) <EOL> def test_debug_merge_point ( self ) : <EOL> inp = '''<STR_LIT>''' <EOL> loop , oloop = self . reparse ( inp , check_equal = False ) <EOL> assert loop . operations [ <NUM_LIT:0> ] . args [ <NUM_LIT:0> ] . _get_str ( ) == '<STR_LIT:info>' <EOL> assert oloop . operations [ <NUM_LIT:0> ] . args [ <NUM_LIT:0> ] . _get_str ( ) == '<STR_LIT:info>' <EOL> def test_floats ( self ) : <EOL> inp = '''<STR_LIT>''' <EOL> loop , oloop = self . reparse ( inp ) <EOL> equaloplists ( loop . operations , oloop . operations ) <EOL> def test_jump ( self ) : <EOL> namespace = { '<STR_LIT:target>' : LoopToken ( <NUM_LIT:3> ) } <EOL> inp = '''<STR_LIT>''' <EOL> loop = pure_parse ( inp , namespace = namespace ) <EOL> logger = Logger ( self . ts ) <EOL> output = logger . log_loop ( loop ) <EOL> assert output . splitlines ( ) [ - <NUM_LIT:1> ] == "<STR_LIT>" <EOL> pure_parse ( output ) <EOL> def test_guard ( self ) : <EOL> namespace = { '<STR_LIT>' : BasicFailDescr ( <NUM_LIT:4> ) } <EOL> inp = '''<STR_LIT>''' <EOL> loop = pure_parse ( inp , namespace = namespace ) <EOL> logger = Logger ( self . ts , guard_number = True ) <EOL> output = logger . log_loop ( loop ) <EOL> assert output . splitlines ( ) [ - <NUM_LIT:1> ] == "<STR_LIT>" <EOL> pure_parse ( output ) <EOL> def boom ( ) : <EOL> raise Exception <EOL> namespace [ '<STR_LIT>' ] . get_index = boom <EOL> logger = Logger ( self . ts , guard_number = False ) <EOL> output = logger . log_loop ( loop ) <EOL> assert output . splitlines ( ) [ - <NUM_LIT:1> ] . startswith ( "<STR_LIT>" ) <EOL> def test_intro_loop ( self ) : <EOL> bare_logger = logger . Logger ( self . ts ) <EOL> bare_logger . log_stream = StringIO ( ) <EOL> bare_logger . log_loop ( [ ] , [ ] , <NUM_LIT:1> , "<STR_LIT:foo>" ) <EOL> output = bare_logger . log_stream . getvalue ( ) <EOL> assert output . splitlines ( ) [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> pure_parse ( output ) <EOL> def test_intro_bridge ( self ) : <EOL> bare_logger = logger . Logger ( self . ts ) <EOL> bare_logger . log_stream = StringIO ( ) <EOL> bare_logger . log_bridge ( [ ] , [ ] , <NUM_LIT:3> ) <EOL> output = bare_logger . log_stream . getvalue ( ) <EOL> assert output . splitlines ( ) [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> pure_parse ( output ) </s>
