Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_code.cpython-34.pyo

�
f f*�@s�dZddlZddlZddlmZmZmZdd�Zdd�ZGdd	�d	ej	�Z
Gd
d�dej	�Zddd
�Ze
dkr�e�ndS)a7This module includes tests of the code object representation.

>>> def f(x):
...     def g(y):
...         return x + y
...     return g
...

>>> dump(f.__code__)
name: f
argcount: 1
kwonlyargcount: 0
names: ()
varnames: ('x', 'g')
cellvars: ('x',)
freevars: ()
nlocals: 2
flags: 3
consts: ('None', '<code object g>', "'f.<locals>.g'")

>>> dump(f(4).__code__)
name: g
argcount: 1
kwonlyargcount: 0
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.__code__)
name: h
argcount: 2
kwonlyargcount: 0
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.__code__)
name: attrs
argcount: 1
kwonlyargcount: 0
names: ('print', 'attr1', 'attr2', 'attr3')
varnames: ('obj',)
cellvars: ()
freevars: ()
nlocals: 1
flags: 67
consts: ('None',)

>>> def optimize_away():
...     'doc string'
...     'not a docstring'
...     53
...     0x53

>>> dump(optimize_away.__code__)
name: optimize_away
argcount: 0
kwonlyargcount: 0
names: ()
varnames: ()
cellvars: ()
freevars: ()
nlocals: 0
flags: 67
consts: ("'doc string'", 'None')

>>> def keywordonly_args(a,b,*,k1):
...     return a,b,k1
...

>>> dump(keywordonly_args.__code__)
name: keywordonly_args
argcount: 2
kwonlyargcount: 1
names: ()
varnames: ('a', 'b', 'k1')
cellvars: ()
freevars: ()
nlocals: 3
flags: 67
consts: ('None',)

�N)�run_doctest�run_unittest�cpython_onlyccsDx=|D]5}t|�}|jd�r7d|jVq|VqWdS)z.Yield a doctest-safe sequence of object reprs.z<code objectz<code object %s>N)�repr�
startswith�co_name)�tZelt�r�r
�3/opt/alt/python34/lib64/python3.4/test/test_code.py�constsns

rc	CsmxJddddddddd	g	D]'}td
|t|d|�f�q"Wtdtt|j���d
S)z1Print out a text representation of a code object.�nameZargcountZkwonlyargcount�namesZvarnamesZcellvarsZfreevarsZnlocals�flagsz%s: %sZco_zconsts:N)�print�getattr�tupler�	co_consts)�co�attrr
r
r�dumpws%rc@s"eZdZedd��ZdS)�CodeTestcCs^ddl}|jddd�}|j|jd�|j|jd�|j|jd�dS)Nr�filenameZfuncname�)�	_testcapiZ
code_newemptyZassertEqual�co_filenamer�co_firstlineno)�selfrrr
r
r�
test_newempty�s
zCodeTest.test_newemptyN)�__name__�
__module__�__qualname__rrr
r
r
rrsrc@seZdZdd�ZdS)�CodeWeakRefTestcs�i}tdt�|�|d}~d�_�fdd�}tj|j|�}�jt|���~�jt|����j�j�dS)Nz
def f(): pass�fFcs
d�_dS)NT)�called)�code)rr
r�callback�sz,CodeWeakRefTest.test_basic.<locals>.callback)	�exec�globalsr$�weakref�ref�__code__Z
assertTrue�boolZassertFalse)r�	namespacer#r&Zcoderefr
)rr�
test_basic�s
	zCodeWeakRefTest.test_basicN)rr r!r.r
r
r
rr"�sr"cCs.ddlm}t||�ttt�dS)Nr)�	test_code)Ztestr/rrrr")�verboser/r
r
r�	test_main�s
r1�__main__)�__doc__Zunittestr)Ztest.supportrrrrrZTestCaserr"r1rr
r
r
r�<module>gs