B ^v<c@s dZddlZddlZddlZddlZddlZddlZddlmZm Z ddl m Z ddl m Z ddl mZddZGd d d ejZd d ZGd ddejZGdddZGdddZGdddZGdddeZGdddZGdddejZedkredS)z3 Test cases for the repr module Nick Mathewson N)create_empty_fileverbose)repr)Repr)recursive_reprcCs d}xt|D] }|f}qW|S)N)range)ZnestingZtirr)/usr/lib64/python3.7/test/test_reprlib.py nestedTuples r c@s|eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZdS) ReprTestscCs|j}|tdd|tddd}t|dddt|dd}|t|||td td d }t|dddt|dd}|t||dS) NZabcz'abc'Zabcdefghijklmnopz'abcdefghijklmnop'Zzi ) r ClassWithReprrrClassWithFailingReprZid assertTrue startswithZendswithZassertInZfind)rrZi1Zi2rZi3rrrr test_instances$zReprTests.test_instancecCs"tdd}||d|dS)NcSs|SNrxrrr Zz'ReprTests.test_lambda..z0.Zz*.get_cell..innerr)rBrr;r get_cells z%ReprTests.test_cell..get_cellrz6z)Z __closure__Z assertRegexrr)rrDr<rrr test_cells zReprTests.test_cellcCsd|j}|ttjdGddd}t|j}|t|dt|j}|t|ddS)Nz"c@eZdZddZdS)z%ReprTests.test_descriptors..CcSdSr:r)Zclsrrr foor=z)ReprTests.test_descriptors..C.fooN)__name__ __module__ __qualname__rHrrrr CrLzr?r@rArErNrQrrrr r s 5  r c Cs(t|ddd}||WdQRXdS)NZwZASCII)Zencoding)ZopenZwrite)pathZtextZfprrr write_filesrSc@steZdZdZddZddZddZdd Zd d Ze d d dZ ddZ ddZ ddZe dddZdS) LongReprTest3areallylongpackageandmodulenametotestreprtruncationcCstj|j|_tj|j|j|_tj|jddt|jt tj|jdtj|jddt|jt tj|jdt |_ t j d|j tdS)NT)Z ignore_errorsz __init__.pyr)osrRjoinlongnamepkgname subpkgnameshutilZrmtreeZmkdirrZgetcwdheresysZinsert importlibinvalidate_cachesrrrr setUps   zLongReprTest.setUpcCsg}x@t|jD]0\}}}x$||D]}|tj||q&WqW||j||x.|D]&}tj|rt |qht |qhWt jd=dS)Nr) rVZwalkrYappendrRrWZsortZreverseZisdirZrmdirZremover])rZactionsZdirpathZdirnamesZ filenamesnameZprrr tearDowns    zLongReprTest.tearDowncCst|j}|dt|jd7}|t|dtd7}|ttjdtd}tjdkrv|dkrv|d|ntjdkrt rt d|dS) Nrr.pyzx.pyZntizDtest paths too long (%d characters) for Windows' 260 character limitzcached_path_len =) Zlenr\rXr^ZutilZcache_from_sourcerVrcZskipTestrZprint)rZ module_nameZsource_path_lenZcached_path_lenrrr _check_path_limitationss  z$LongReprTest._check_path_limitationscCstd|_||jttj|j|jdt ddl m }|}| t |d|j|jf| t tddS)Nrer)rUzz)ZmaxDiffrfrYrrVrRrWrZr^r_gareallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncationrUrrrIZ__file__r])rrUZmodulerrr test_modules  zLongReprTest.test_modulecCsT|d|j}ttj|jddtddl m }|t |j d|j dS)NrHzfoo.pyzclass foo(object): pass r)rHz) rfrrSrVrRrWrZr^r_rgrHrrI)rrrHrrr test_types   zLongReprTest.test_typezneed a suitable objectcCrGr:rr`rrr test_object*szLongReprTest.test_objectcCsP|dttj|jddtddlm }| t |j d|j dS)Nbarzbar.pyzclass bar: pass r)rkz) rfrSrVrRrWrZr^r_rgrkrrrI)rrkrrr test_class0s   zLongReprTest.test_classcCsZ|dttj|jddtddlm }| }| t | d|j dS)Nbazzbaz.pyzclass baz: pass r)rmz<%s.baz object at 0x)rfrSrVrRrWrZr^r_rgrmr7rr8rI)rrmZibazrrr r9;s   zLongReprTest.test_instancecCs|d|j}ttj|jddtddl m }t |j j }||d|| }t |j }||d|jf|dS)Nquxzqux.pyzclass aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: def amethod(self): pass r)rnzz)rurvrbrrr})rZmrrr test_recursive_reprs        z%TestRecursiveRepr.test_recursive_reprcCsBddlm}tj}tj}x$|D]}|t||t||qWdS)Nr)WRAPPER_ASSIGNMENTS)Z functoolsrr~rrZassertIsZgetattr)rZassignedrrrcrrr test_assigned_attributess   z*TestRecursiveRepr.test_assigned_attributesN)rIrJrKrrrrrr rs rZ__main__)r|r]rVr[r^Zimportlib.utilrpZ test.supportrrZreprlibrrrrr ZTestCaser rSrTr5r6rur}r~rrIZmainrrrr Zs0   C