a  zeK@s\ddlmZddlZddlmZGdddejZGdddejZedkrXej d d dS) )pyparseN) namedtuplec@seZdZddZddZdS) ParseMapTestcCs`dddD}t|}||tdtd||tdtd||dtddS)NcSsi|]}t|t|qS)ord).0crrR/opt/bitninja-python-dojo/embedded/lib/python3.9/idlelib/idle_test/test_pyparse.py z.ParseMapTest.test_parsemap..z  axi)rZParseMap assertEqualr)selfZ keepwhitemappingrrr test_parsemap s  zParseMapTest.test_parsemapcCs$tdd}|dtjddS)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)rrrclsrrr setUpClassszPyParseTest.setUpClasscCs|`dSN)rrrrr tearDownClassszPyParseTest.tearDownClasscCs$||jjd||jjddS)Nr)rrrr)rrrr test_init"szPyParseTest.test_initc Cs|j}|j}|j}|t|dWdn1s:0Yd}|D]P}|j|d0||||j|||jdWdqL1s0YqLdS)Nr )a stringr)rrset_code assertRaisesAssertionErrorsubTestcode study_level)reqpsetcodetestsr'rrr test_set_code&s & zPyParseTest.test_set_codecs|j}|j}|j}|j}dd}|d|||d|d|||d|dd\}|t|Wdn1s0Y|t|dWdn1s0Y||d d d |||||fd d d ||fd d d |||fdd d d|d|||||fdd d ||fdd d |||fdd d dS)NcSsdS)NFrindexrrr char_in_string_false=r zDPyParseTest.test_find_good_parse_start..char_in_string_falsez def spam(): rzclass spam( k"""This is a module docstring""" class C: def __init__(self, a, b=True): pass )!*FcSsdS)NTrr3rrr [r z8PyParseTest.test_find_good_parse_start..)Zis_char_in_stringcs|kSr!rr3posrr r9cr cs|kSr!rr3r:rr r9fr cs|kSr!rr3r:rr r9ir zZ"""This is a module docstring""" class C: def __init__(self, a, b=True): pass cs|kSr!rr3r:rr r9sr cs|kSr!rr3r:rr r9tr cs|kSr!rr3r:rr r9wr )rrr(Zfind_good_parse_startr) TypeError assertIsNone)rr.r/r0startr5Zpos0rr:r test_find_good_parse_start8s2 $ &z&PyParseTest.test_find_good_parse_startcCsd}d}|j}|||t|dWdn1sB0Y|d||j|||||j||ddS)Nr6r8r)rr(r)r*Zset_lorr,)rr,r;r/rrr test_set_loys  (  zPyParseTest.test_set_loc Cs|j}|j}|j}|j}td\}}}}} tdgd} | ddg|| dddg|| dddg|| d ddg|| d ddg|| d ddg|| d ddg|| d ddg|| dddg|| dddg|| dgd|| dddg|| dddg| | dddg|| dddg|| dgd|| dgd| | dgd| | dddg|| dddg| | dddg|f} | D]n} |j| jdH|| j|||jd||j | j ||j | j Wdn1s0Yqd| |dS)Nr@TestInfo)r' 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. )rrErFz # Comment\ z"("""Complete string in bracket""" z("""Open string in bracket a = (1 + 2) - 5 *\ 0 def function1(self, a, b): )rrE def function1(self, a,\  def function1(self, a, ()) )( {)(] r&) rrr(Z_study1rangerr+r'r-rCrDr=) rr.r/r0studyNONE BACKSLASHFIRSTNEXTBRACKETrBr1testrrr test_study1sL   2zPyParseTest.test_study1c Cs|j}|j}|j}|j}td\}}}}} tdddg} | d|| d|| d|| d|| d | f} | D]J} |j| jd (|| j||| jWdqh1s0YqhdS) Nr@rBr'rDr$z%"""This is a continuation docstring. z-'''This is a multiline-continued docstring. rGrJr&) rrr(Zget_continuation_typerOrr+r'rD) rr.r/r0ZgettyperQrRrSrTrUrBr1rVrrr test_get_continuation_types  z&PyParseTest.test_get_continuation_typecCs|j}|j}|j}|j}tdgd}|dddddd|dddddd |d dd ddd |d ddddd|dddddd|dddddd|dddddd|dddddd|dddddd|d dd!dd"d#|d$dd%d&dd'|d(dd)d*dd+|d,dd-d.dd/|d0dd%d1dd|d2dddddf}|D]}|j|jd3r||j|||jd4||j|j ||j |j ||j |j ||j |j||j|jWdn1s0Yq||dS)5NrB)r'r>endlastch openbracket bracketingr$rrrz0'''This is a multiline continuation docstring. 0')r^rrE)r_rz # Comment\ )r^rErE)rbrz #Comment\ rG*)r^rrE) rrHrE:)rErrE).rrJ,rk)rirjrKz3 def function1(self, a, # End of line comment. 3)rirj)rmrF)rprEz7 a = ["first item", # Comment line "next item", 7)r^)rrrE)rF)rdrE)rF)&rE)r8rF)5rErLr))r^rarFrrIrrMrI()r^rircrNr@]r^rarxrFrErrz:\a z\a r&rF)rrr(Z_study2rr+r'r-Z stmt_startr>Zstmt_endrYrZZlastopenbracketposr[Zstmt_bracketingr\r=)rr.r/r0rPrBr1rVrrr test_study2sl           '  2zPyParseTest.test_study2c Cs|j}|j}|j}|j}tdddg}|dd|dd|dd|d d |d d|d d|d d|ddf}|d|t|Wdn1s0Y|D]J}|j|jd(||j|||j Wdq1s0YqdS)NrBr'linesz[x for x in a] rEz[x for x in a rFz[x\ for x in a\ z[x for x in a ] rIz% """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\ """ r@r$r&) rrr(Zget_num_lines_in_stmtrr) IndexErrorr+r'r)rr.r/r0getlinesrBr1rVrrr 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|t|Wdn1s0Y|D]}||j|||jqdS)NrBr'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", rFz1["first item", # Comment line "next item", rEz( rz(a zdef function1(self, a, b): ) rrr(Zcompute_bracket_indentrr)r*r'r)rr.r/r0indentrBr1rVrrr test_compute_bracket_indent1s. $ z'PyParseTest.test_compute_bracket_indentc Cs`|j}|j}|j}|j}d}|D]h}|j|dH|||t|Wdn1s`0YWdq 1s~0Yq tdd}|dd|dd|dd |d d |d d|d d|dd|dd|dd|dd |dd |dd|dd|ddf}|D]N} |j| jd(|| j||| j Wdn1sN0Yq dS)N)zdef function1(self, a, b\ z """ (\ za = #\ r&rB)r'rrGrza = 1 + 2 - 5 *\ z a = 1 + 2 - 5 *\ rz a = "spam"\ rrz a = \ "a"\ z a = #\ "a"\ r@za == \ rFza != \ z\ z \ z \ za\ rIz{}\ z(1 + 2) - 5 *\ ) rrr(Zcompute_backslash_indentr+r)r*rr'r) rr.r/r0rerrorsr'rBr1rVrrr test_compute_backslash_indentQs< D  z)PyParseTest.test_compute_backslash_indentc Cs|j}|j}|j}|j}tdddg}|dd|dd|dd|dd |d d |d d |d d f}|D]J}|j|jd (||j|||jWdqf1s0YqfdS)NrBr'rr$ 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/r0Z baseindentrBr1rVrrr test_get_base_indent_stringxs"  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 }|D]H}|j|jd&||j||Wdq1s0YqdS)NrBr'assert_rrHz: za: z): z(: z": rK!def function1(self, a): pass z # A comment: z"""A docstring: r&) assertTrue assertFalserr(Zis_block_openerrr+r'r) ryesnor/r0openerrBr1rVrrr test_is_block_openers. 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 }|D]H}|j|jd&||j||Wdq1s0YqdS)NrBr'rzreturn z break z continue z raise z pass zpass z return # zraised z returning z # return z """break z "continue rr&) rrrr(Zis_block_closerrr+r'r) rrrr/r0ZcloserrBr1rVrrr test_is_block_closers0 z PyParseTest.test_is_block_closerc Cs|j}|j}|j}|j}tdddg}|dd|dd|dd|d d |d d |d d|dd|dd|dd|ddf }|D]J}|j|jd(||j|||jWdq~1s0Yq~dS)NrBr'bracketr$r]r%z()() r|z( )() )r^raryrIrEr@rz() () )ryrrz()( ) )r^rarxr}rz(()) )r^rarErFrr~z( ()) )r^ra)rFrFrfrrNz(((()) )r^rar)rFrI)rIr)r@rI)rrrFr&)rrr(Zget_last_stmt_bracketingrr+r'r)rr.r/r0r\rBr1rVrrr test_get_last_stmt_bracketings, z)PyParseTest.test_get_last_stmt_bracketingN)rrr classmethodr r"r#r2r?rArWrXrrrrrrrrrrrr rs$  A2= 'r__main__rF) verbosity) ZidlelibrZunittest collectionsrZTestCaserrrmainrrrr s  M