ó {G_Tc@s¤dZddlZddlZddlmZmZmZd„Zd„Zdej fd„ƒYZ dej fd „ƒYZ dd „Z ed kr e ƒndS( sÃThis module includes tests of the code object representation. >>> def f(x): ... def g(y): ... return x + y ... return g ... >>> dump(f.func_code) name: f argcount: 1 names: () varnames: ('x', 'g') cellvars: ('x',) freevars: () nlocals: 2 flags: 3 consts: ('None', '') >>> dump(f(4).func_code) name: g argcount: 1 names: () varnames: ('y',) cellvars: () freevars: ('x',) nlocals: 1 flags: 19 consts: ('None',) >>> def h(x, y): ... a = x + y ... b = x - y ... c = a * b ... return c ... >>> dump(h.func_code) name: h argcount: 2 names: () varnames: ('x', 'y', 'a', 'b', 'c') cellvars: () freevars: () nlocals: 5 flags: 67 consts: ('None',) >>> def attrs(obj): ... print obj.attr1 ... print obj.attr2 ... print obj.attr3 >>> dump(attrs.func_code) name: attrs argcount: 1 names: ('attr1', 'attr2', 'attr3') varnames: ('obj',) cellvars: () freevars: () nlocals: 1 flags: 67 consts: ('None',) >>> def optimize_away(): ... 'doc string' ... 'not a docstring' ... 53 ... 53L >>> dump(optimize_away.func_code) name: optimize_away argcount: 0 names: () varnames: () cellvars: () freevars: () nlocals: 0 flags: 67 consts: ("'doc string'", 'None') iÿÿÿÿN(t run_doctestt run_unittestt cpython_onlyccsDx=|D]5}t|ƒ}|jdƒr7d|jVq|VqWdS(s.Yield a doctest-safe sequence of object reprs.s N(treprt startswithtco_name(tttelttr((s*/usr/local/lib/python2.7/test/test_code.pytconstsXs   cCsaxBddddddddgD]"}d |t|d |ƒfGHqWd Gtt|jƒƒGHd S( s1Print out a text representation of a code object.tnametargcounttnamestvarnamestcellvarstfreevarstnlocalstflagss%s: %stco_sconsts:N(tgetattrttupleR t co_consts(tcotattr((s*/usr/local/lib/python2.7/test/test_code.pytdumpas tCodeTestcBseZed„ƒZRS(cCs^ddl}|jdddƒ}|j|jdƒ|j|jdƒ|j|jdƒdS(Niÿÿÿÿtfilenametfuncnamei(t _testcapit code_newemptyt assertEqualt co_filenameRtco_firstlineno(tselfRR((s*/usr/local/lib/python2.7/test/test_code.pyt test_newemptyks  (t__name__t __module__RR"(((s*/usr/local/lib/python2.7/test/test_code.pyRistCodeWeakRefTestcBseZd„ZRS(csi}deƒ|U|d}~eˆ_‡fd†}ej|j|ƒ}ˆje|ƒƒƒ~ˆje|ƒƒƒˆjˆjƒdS(Ns def f(): passtfcs tˆ_dS(N(tTruetcalled(tcode(R!(s*/usr/local/lib/python2.7/test/test_code.pytcallbacks( tglobalstFalseR(tweakreftreft__code__t assertTruetboolt assertFalse(R!t namespaceR&R*tcoderef((R!s*/usr/local/lib/python2.7/test/test_code.pyt test_basicvs   (R#R$R5(((s*/usr/local/lib/python2.7/test/test_code.pyR%tscCs.ddlm}t||ƒtttƒdS(Niÿÿÿÿ(t test_code(ttestR6RRRR%(tverboseR6((s*/usr/local/lib/python2.7/test/test_code.pyt test_mains t__main__(t__doc__tunittestR-ttest.test_supportRRRR RtTestCaseRR%tNoneR9R#(((s*/usr/local/lib/python2.7/test/test_code.pytQs