File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from test .test_support import verify , verbose , TestFailed , run_unittest
2+ import sys
3+ import dis
4+ import StringIO
5+
6+ # Minimal tests for dis module
7+
8+ import unittest
9+
10+ # placement is crucial!!! move the start of _f and you have to adjust the
11+ # line numbers in dis_f
12+ def _f (a ):
13+ print a
14+ return 1
15+
16+ dis_f = """\
17+ 13 0 LOAD_FAST 0 (a)
18+ 3 PRINT_ITEM
19+ 4 PRINT_NEWLINE
20+
21+ 14 5 LOAD_CONST 1 (1)
22+ 8 RETURN_VALUE
23+ 9 LOAD_CONST 0 (None)
24+ 12 RETURN_VALUE
25+ """
26+
27+ class DisTests (unittest .TestCase ):
28+ def test_opmap (self ):
29+ self .assertEqual (dis .opmap ["STOP_CODE" ], 0 )
30+ self .assertEqual (dis .opmap ["LOAD_CONST" ] in dis .hasconst , True )
31+ self .assertEqual (dis .opmap ["STORE_NAME" ] in dis .hasname , True )
32+
33+ def test_opname (self ):
34+ self .assertEqual (dis .opname [dis .opmap ["LOAD_FAST" ]], "LOAD_FAST" )
35+
36+ def test_boundaries (self ):
37+ self .assertEqual (dis .opmap ["EXTENDED_ARG" ], dis .EXTENDED_ARG )
38+ self .assertEqual (dis .opmap ["STORE_NAME" ], dis .HAVE_ARGUMENT )
39+
40+ def test_dis (self ):
41+ s = StringIO .StringIO ()
42+ save_stdout = sys .stdout
43+ sys .stdout = s
44+ dis .dis (_f )
45+ sys .stdout = save_stdout
46+ self .assertEqual (dis_f , s .getvalue ())
47+
48+ def test_main ():
49+ run_unittest (DisTests )
50+
51+
52+ if __name__ == "__main__" :
53+ test_main ()
You can’t perform that action at this time.
0 commit comments