<s> from test . test_support import run_unittest <EOL> import unittest <EOL> import sys <EOL> import dis <EOL> import StringIO <EOL> def _f ( a ) : <EOL> print a <EOL> return <NUM_LIT:1> <EOL> dis_f = """<STR_LIT>""" % ( _f . func_code . co_firstlineno + <NUM_LIT:1> , <EOL> _f . func_code . co_firstlineno + <NUM_LIT:2> ) <EOL> def bug708901 ( ) : <EOL> for res in range ( <NUM_LIT:1> , <EOL> <NUM_LIT:10> ) : <EOL> pass <EOL> dis_bug708901 = """<STR_LIT>""" % ( bug708901 . func_code . co_firstlineno + <NUM_LIT:1> , <EOL> bug708901 . func_code . co_firstlineno + <NUM_LIT:2> , <EOL> bug708901 . func_code . co_firstlineno + <NUM_LIT:3> ) <EOL> def bug1333982 ( x = [ ] ) : <EOL> assert <NUM_LIT:0> , ( [ s for s in x ] + <EOL> <NUM_LIT:1> ) <EOL> pass <EOL> dis_bug1333982 = """<STR_LIT>""" % ( bug1333982 . func_code . co_firstlineno + <NUM_LIT:1> , <EOL> bug1333982 . func_code . co_firstlineno + <NUM_LIT:2> , <EOL> bug1333982 . func_code . co_firstlineno + <NUM_LIT:3> ) <EOL> _BIG_LINENO_FORMAT = """<STR_LIT>""" <EOL> class DisTests ( unittest . TestCase ) : <EOL> def do_disassembly_test ( self , func , expected ) : <EOL> s = StringIO . StringIO ( ) <EOL> save_stdout = sys . stdout <EOL> sys . stdout = s <EOL> dis . dis ( func ) <EOL> sys . stdout = save_stdout <EOL> got = s . getvalue ( ) <EOL> lines = got . split ( '<STR_LIT:\n>' ) <EOL> lines = [ line . rstrip ( ) for line in lines ] <EOL> expected = expected . split ( "<STR_LIT:\n>" ) <EOL> import difflib <EOL> if expected != lines : <EOL> self . fail ( <EOL> "<STR_LIT>" + <EOL> "<STR_LIT:\n>" . join ( difflib . ndiff ( expected , <EOL> lines ) ) ) <EOL> def test_opmap ( self ) : <EOL> self . assertEqual ( dis . opmap [ "<STR_LIT>" ] , <NUM_LIT:0> ) <EOL> self . assertIn ( dis . opmap [ "<STR_LIT>" ] , dis . hasconst ) <EOL> self . assertIn ( dis . opmap [ "<STR_LIT>" ] , dis . hasname ) <EOL> def test_opname ( self ) : <EOL> self . assertEqual ( dis . opname [ dis . opmap [ "<STR_LIT>" ] ] , "<STR_LIT>" ) <EOL> def test_boundaries ( self ) : <EOL> self . assertEqual ( dis . opmap [ "<STR_LIT>" ] , dis . EXTENDED_ARG ) <EOL> self . assertEqual ( dis . opmap [ "<STR_LIT>" ] , dis . HAVE_ARGUMENT ) <EOL> def test_dis ( self ) : <EOL> self . do_disassembly_test ( _f , dis_f ) <EOL> def test_bug_708901 ( self ) : <EOL> self . do_disassembly_test ( bug708901 , dis_bug708901 ) <EOL> def test_bug_1333982 ( self ) : <EOL> if __debug__ : <EOL> self . do_disassembly_test ( bug1333982 , dis_bug1333982 ) <EOL> else : <EOL> self . skipTest ( '<STR_LIT>' ) <EOL> def test_big_linenos ( self ) : <EOL> def func ( count ) : <EOL> namespace = { } <EOL> func = "<STR_LIT>" + "<STR_LIT>" . join ( [ "<STR_LIT>" ] * count + [ "<STR_LIT>" ] ) <EOL> exec func in namespace <EOL> return namespace [ '<STR_LIT:foo>' ] <EOL> for i in xrange ( <NUM_LIT:1> , <NUM_LIT> ) : <EOL> expected = _BIG_LINENO_FORMAT % ( i + <NUM_LIT:2> ) <EOL> self . do_disassembly_test ( func ( i ) , expected ) <EOL> for i in xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:10> ) : <EOL> expected = _BIG_LINENO_FORMAT % ( i + <NUM_LIT:2> ) <EOL> self . do_disassembly_test ( func ( i ) , expected ) <EOL> def test_main ( ) : <EOL> run_unittest ( DisTests ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
