3 2aH@s\ddlmZddlZddlmZGdddejZGdddejZedkrXej d d dS) )pyparseN) namedtuplec@seZdZddZddZdS) ParseMapTestcCs`dddD}tj|}|j|tdtd|j|tdtd|j|dtddS)NcSsi|]}t|t|qS)ord).0crr1/opt/alt/python36/lib64/python3.6/test_pyparse.py sz.ParseMapTest.test_parsemap..z  axi)rZParseMap assertEqualr)selfZ keepwhitemappingrrr test_parsemap s  zParseMapTest.test_parsemapcCs$tjdd}|jdjtjddS)Nz a([{b}])b"c'd zxxx(((x)))x"x'x )rParserr translateZtrans)rparserrrr test_transs zParseMapTest.test_transN)__name__ __module__ __qualname__rrrrrr rsrc@seZdZeddZeddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZddZddZddZdd Zd!S)" PyParseTestcCstjddd|_dS)Nr) indentwidthtabwidth)rrr)clsrrr setUpClassszPyParseTest.setUpClasscCs|`dS)N)r)rrrr tearDownClassszPyParseTest.tearDownClasscCs$|j|jjd|j|jjddS)Nr)rrrr)rrrr test_init"szPyParseTest.test_initcCs~|j}|j}|j}|jt|dWdQRXd}xD|D]<}|j|d&||||j|||jdWdQRXq:WdS)Nr a )stringr)r!r")rrset_code assertRaisesAssertionErrorsubTestcode study_level)reqpsetcodetestsr#rrr test_set_code&s   zPyParseTest.test_set_codecCs|j}|j}|j}|j}|d|j||j|ddd||dddd||dddd||dddd ||d ddd|d ||d ddd||d ddd||dddd ||dddddS)Nzm"""This is a module docstring""" class C(): def __init__(self, a, b=True): pass cSsdS)NTr)indexrrr Ksz8PyParseTest.test_find_good_parse_start..)Zis_char_in_stringcSsdS)NFr)r/rrr r0Os,cSs|dkS)Nr1r)r/rrr r0SscSs|dkS)Nr1r)r/rrr r0Vs!cSs|dkS)Nr1r)r/rrr r0Ysz\"""This is a module docstring""" class C(): def __init__(self, a, b=True): pass cSsdS)NFr)r/rrr r0bscSs|dkS)Nr1r)r/rrr r0cscSs|dkS)Nr1r)r/rrr r0dscSs|dkS)Nr1r)r/rrr r0gs)rrr$Zfind_good_parse_start assertIsNone)rr*r+r,startrrr test_find_good_parse_start8s  z&PyParseTest.test_find_good_parse_startc Cspd}|j}|j||jt|jdWdQRX|jd|j|j||jd|j|j|dddS)Nzm"""This is a module docstring""" class C(): def __init__(self, a, b=True): pass rr1)rr$r%r&Zset_lorr()rr(r+rrr test_set_lois    zPyParseTest.test_set_loc Cs|j}|j}|j}|j}td\}}}}} tddddg} | ddg|| ddd g|| d dd g|| d dd g|| d dd g|| d dd g|| ddd g|| dddg|| ddd g|| ddd g|| ddd dg|| ddd g|| ddd g| | ddd g|| ddd g|| ddd dg|| ddd dg| | ddd dg| | ddd g|| ddd g| | ddd g|f} x`| D]X} |j| jd>|| j|||jd ||j | j ||j | j WdQRXqpW|j |dS) Nr6TestInfor# goodlines continuationr!rz$"""This is a complete docstring.""" z$'''This is a complete docstring.''' z""""This is a continued docstring. z"'''This is a continued docstring. z""""Closing quote does not match." z"""Bracket in docstring [ z#'''Incomplete two line docstring. z"This is a complete string." z"This is an incomplete string. z'This is more incomplete. z # Comment\ z"("""Complete string in bracket""" z("""Open string in bracket za = (1 + 2) - 5 *\ z0 def function1(self, a, b): z def function1(self, a,\ z def function1(self, a, z()) z)( z{)(] )r#) rrr$Z_study1rangerr'r#r)r9r:r3) rr*r+r,studyNONE BACKSLASHFIRSTNEXTBRACKETr8r-testrrr test_study1sJ     zPyParseTest.test_study1c Cs|j}|j}|j}|j}td\}}}}} tdddg} | d|| d|| d|| d|| d | f} x>| D]6} |j| jd || j||| jWdQRXqjWdS) Nr6r8r#r:r!z%"""This is a continuation docstring. z-'''This is a multiline-continued docstring. za = (1 + 2) - 5 *\ z def function1(self, a,\ )r#) rrr$Zget_continuation_typer>rr'r#r:) rr*r+r,Zgettyper@rArBrCrDr8r-rErrr test_get_continuation_types   z&PyParseTest.test_get_continuation_typecCs|j}|j}|j}|j}tdddddddg}|dd d ddd8|d d d d dd<|dd dddd@|dd d dddB|dd ddddF|dd ddddJ|dd ddddM|dd ddddP|d d d!dddU|d#d d$dd%d^|d+d dd,ddc|d.d d-d/d dg|d0d d1d2ddm|d3d dd4ddo|d5d d dddqf}x|D]}|j|jd6h||j|||jd"||j|j ||j |j ||j |j ||j |j||j|jWdQRXq(W|j|dS)rNr8r#r4endlastch openbracket bracketingr!rz1'''This is a multiline continutation docstring. 1'r;z # Comment\ z #Comment\ za = (1 + 2) - 5 *\ *r z0 def function1(self, a, b): 0:.z def function1(self, a,\ ,z def function1(self, a, z3 def function1(self, a, # End of line comment. 3r<z7 a = ["first item", # Comment line "next item", 7&*5z()) )r=z)( (z{)(] r6]z:\a z\a )r#rr)rerrrr;rLr)rfrgrhrrr;r;rNr)rirjrkrr)rlrrrr;rQr)rmrnror;rrTr;rUr)rprqrrr;rrTr;)rsrtr;rrTr;)rurvr;rrTr;rVr<rYr;)rwrxryrzrrr[r;r\r<rOr;r]r<r^r;r_r<r`r;)r{r|r}r~rrrrrrrr;r<rr=r)rrrrrrr;rr;r;)rrrrrrr;r<rr<r;rr)rrrrrrr)rrr)r)rrr$Z_study2rr'r#r)Z stmt_startr4Zstmt_endrHrIZlastopenbracketposrJZstmt_bracketingrKr3)rr*r+r,r?r8r-rErrr test_study2sX               zPyParseTest.test_study2cCs|j}|j}|j}|j}tdddg}|dd|dd|dd|d d |d d|d d|d d|ddf}|d|jt |WdQRXx>|D]6}|j|jd||j|||j WdQRXqWdS)Nr8r#linesz[x for x in a] r;z[x for x in a r<z[x\ for x in a\ z[x for x in a ] r=z% """Docstring comment L1""" L2 L3 L4 z% """Docstring comment L1 L2""" L3 L4 z& """Docstring comment L1\ L2\ L3\ L4\ rz+ """Docstring comment L1\ L2\ L3\ L4\ """ r6r!)r#) rrr$Zget_num_lines_in_stmtrr% IndexErrorr'r#r)rr*r+r,getlinesr8r-rErrr test_get_num_lines_in_stmts(    z&PyParseTest.test_get_num_lines_in_stmtc Cs|j}|j}|j}|j}tdddg}|dd|dd|dd|d d |d d |d d |d d|dd|dd|dd|ddf }|d|jt |WdQRXx$|D]}||j|||jqWdS)Nr8r#spaceszdef function1(self, a, z def function1(self, a, z def function1(self, a, z def function1( z def function1( z def function1( z2[ "first item", # Comment line "next item", rz4[ "first item", # Comment line "next item", r<z1["first item", # Comment line "next item", r;z( rz(a zdef function1(self, a, b): ) rrr$Zcompute_bracket_indentrr%r&r#r)rr*r+r,indentr8r-rErrr test_compute_bracket_indent s,    z'PyParseTest.test_compute_bracket_indentc Cs(|j}|j}|j}|j}d}xH|D]@}|j|d*|||jt |WdQRXWdQRXq"Wtdd}|dd |d d |d d |d d|dd |dd|dd|dd|dd|dd|dd|dd|dd |ddf}x>|D]6} |j| jd|| j||| j WdQRXqWdS)Ndef function1(self, a, b\ """ (\ a = #\ )r#r8r#rza = (1 + 2) - 5 *\ rza = 1 + 2 - 5 *\ z a = 1 + 2 - 5 *\ rz a = "spam"\ r[z a = \ "a"\ z a = #\ "a"\ r6za == \ r<za != \ z\ z \ z \ za\ r=z{}\ z(1 + 2) - 5 *\ )rrr)r#r) rrr$Zcompute_backslash_indentr'r%r&rr#r) rr*r+r,rerrorsr#r8r-rErrr test_compute_backslash_indent@s>      z)PyParseTest.test_compute_backslash_indentc Cs|j}|j}|j}|j}tdddg}|dd|dd|dd|dd |d d |d d |d d f}x>|D]6}|j|jd ||j|||jWdQRXqhWdS)Nr8r#rr!z def a(): z def a(): r z def a(): z z def a( z def a( z # Comment. )r#)rrr$Zget_base_indent_stringrr'r#r)rr*r+r,Z baseindentr8r-rErrr test_get_base_indent_stringgs    z'PyParseTest.test_get_base_indent_stringc Cs|j}|j}|j}|j}|j}tdddg}|d||d||d||d||d||d ||d ||d ||d ||d ||d||d|f }x<|D]4}|j|jd||j|j|WdQRXqWdS)Nr8r#assert_z def a(): z0 def function1(self, a, b): z: za: z): z(: z": z def function1(self, a, z!def function1(self, a): pass z # A comment: z"""A docstring: )r#) assertTrue assertFalserr$Zis_block_openerrr'r#r) ryesnor+r,openerr8r-rErrr test_is_block_opener|s,   z PyParseTest.test_is_block_openerc Cs|j}|j}|j}|j}|j}tdddg}|d||d||d||d||d||d ||d ||d ||d ||d ||d||d||d|f }x<|D]4}|j|jd||j|j|WdQRXqWdS)Nr8r#rzreturn z break z continue z raise z pass zpass z return # zraised z returning z # return z """break z "continue z!def function1(self, a): pass )r#) rrrr$Zis_block_closerrr'r#r) rrrr+r,Zcloserr8r-rErrr test_is_block_closers.   z PyParseTest.test_is_block_closercCs|j}|j}|j}|j}tdddg}|dd|dd|dd|d d%|dd)|dd/|dd5|dd;|ddA|ddIf }x@|D]8}|j|jd||j|||jWdQRXqWdS)JNr8r#bracketr!rza z()() r;r<rz( )() r=r6z() () z()( ) z(()) z( ()) z{)(] z(((()) r[)r#rr)rrr)rrrrr;r<rr<r;rr)rrrrrrrrr;r=rr=r;r6r)rrrrrr=rr=r;r6r)rrrrrrr;r<rr<r;r6r)rrrrrrrrr;r;r<r=r;rr)rrrrrrrrr;r<r<rr;r6r)rrrrrrrrr;r<rr<r;rr)rrrrrrrrr;r;r<r<r=r=rr6r=r[r<)rrrrrrr)rrr$Zget_last_stmt_bracketingrr'r#r)rr*r+r,rKr8r-rErrr test_get_last_stmt_bracketings(  z)PyParseTest.test_get_last_stmt_bracketingN)rrr classmethodrrr r.r5r7rFrGrrrrrrrrrrrr rs   12= 'r__main__r<) verbosity) ZidlelibrZunittest collectionsrZTestCaserrrmainrrrr s  <