a ze V@sdddlmZmZddlmZddlZddlZddlZddl Z ddlZe de d$ddl Z ddl m Z Wdn1s0YGdddZGdd d ZGd d d Ze jd d dZGdddZGdddeZGdddeZGdddeZGdddZGdddZGdddeZGdddeZGdd d eZed!kr`edS)")support test_tools)TestCaseNclinic) DSLParserc@seZdZddZdS) FakeConvertercCs||_||_dSN)nameargsselfr r r D/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_clinic.py__init__szFakeConverter.__init__N)__name__ __module__ __qualname__rr r r rrsrc@seZdZddZddZdS)FakeConverterFactorycCs ||_dSrr r r r r rrszFakeConverterFactory.__init__cKs t|j|Sr)rr )r r defaultkwargsr r r__call__szFakeConverterFactory.__call__N)rrrrrr r r rrsrc@seZdZddZddZdS)FakeConvertersDictcCs i|_dSr)used_convertersr r r rr"szFakeConvertersDict.__init__cCs|j|t|Sr)r setdefaultr)r r rr r rget%szFakeConvertersDict.getN)rrrrrr r r rr!srCfile)languagefilenamec@s<eZdZddZddZddZddZd d Zej j Z d S) FakeClinicc Cst|_t|_td|_d|_i|_td|j|_ t |_ t |_ |t_d|_d|_|_i|_|dd|dd|dd|jj}t d|dfd|dfd |dfd |dfd |dfd |dfd |dff|_dS)Nr"blockbufferrsuppressZdocstring_prototypeZdocstring_definitionZmethoddef_defineZimpl_prototypeZparser_prototypeZparser_definitionZimpl_definition)rZ convertersZlegacy_convertersr CLanguager r!Zdestination_buffers BlockParserZ block_parser collections OrderedDictmodulesclassesr Z line_prefixZ line_suffix destinationsadd_destinationrZfield_destinations)r dr r rr+s2              zFakeClinic.__init__cCs&|j|}|s"tdt||S)NzDestination does not exist: )r-rsysexitrepr)r r r/r r rget_destinationFs zFakeClinic.get_destinationcGs<||jvrtdt|tj|||g|R|j|<dS)NzDestination already exists: )r-r0r1r2rZ Destination)r r typer r r rr.Ls zFakeClinic.add_destinationcCs|dkS)Nmoduler rr r r is_directiveQszFakeClinic.is_directivecCs||j|<dSr)Zcalled_directivesr r r r directiveTszFakeClinic.directiveN) rrrrr3r.r6r7rClinicZ_module_and_classr r r rr"*s r"c@seZdZddZdS)ClinicWholeFileTestcCsNtjtddd}d}||}|d}||d||ddS)Nrr!z/*[clinic] foo [clinic]*/z[clinic]*/[clinic]*/z [clinic]*/)rr8r'parse splitlinesrstripZassertNotEqual assertEqual)r crawZcookedZend_liner r rtest_eolZs   zClinicWholeFileTest.test_eolN)rrrrBr r r rr9Ysr9c@s<eZdZddZddZddZddZd d Zd d Zd S)ClinicGroupPermuterTestcCst|||}|||dSr)rpermute_optional_groupsr?)r lmroutputcomputedr r r_testoszClinicGroupPermuterTest._testcCs|dggdgdggddS)Nstartstopstep))rL)rKrL)rKrLrMrJrr r r test_rangessz"ClinicGroupPermuterTest.test_rangecCs |ddggdgdggddS)Nxychattr))rR)rRrS)rPrQrR)rPrQrRrSrNrr r rtest_add_window{sz'ClinicGroupPermuterTest.test_add_windowcCs.|gdddggdgddggdgddS) N)a1a2a3b1b2c1d1d2)e1e2e3))rZ)rXrYrZ)rXrYrZr[r\)rUrVrWrXrYrZ)rUrVrWrXrYrZr[r\) rUrVrWrXrYrZr[r\r]r^r_rNrr r rtest_ludicrouss$z&ClinicGroupPermuterTest.test_ludicrouscCs |ggdgdgdggddS)Nabr@)r )ra)rarb)rarbr@rNrr r rtest_right_onlysz'ClinicGroupPermuterTest.test_right_onlycCsdd}|t|dS)NcSstdgggdS)Nra)rrDr r r rfnszPClinicGroupPermuterTest.test_have_left_options_but_required_is_empty..fn) assertRaisesAssertionError)r rdr r r,test_have_left_options_but_required_is_emptyszDClinicGroupPermuterTest.test_have_left_options_but_required_is_emptyN) rrrrJrOrTr`rcrgr r r rrCns    rCc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)ClinicLinearFormatTestcKs"tj|fi|}|||dSr)rZ linear_formatr?)r inputrHrrIr r rrJszClinicLinearFormatTest._testcCs|dddS)Nr#rNrr r rtest_empty_stringssz)ClinicLinearFormatTest.test_empty_stringscCs|dddS)N rNrr r rtest_solo_newlinesz(ClinicLinearFormatTest.test_solo_newlinecCs|dddS)Nz abc rNrr r rtest_no_substitutionsz+ClinicLinearFormatTest.test_no_substitutioncCs|jdddddS)N8 abc {name} def z' abc def r#rrNrr r rtest_empty_substitutionsz.ClinicLinearFormatTest.test_empty_substitutioncCs|jdddddS)Nrnz8 abc GARGLE def ZGARGLErrNrr r rtest_single_line_substitutionsz4ClinicLinearFormatTest.test_single_line_substitutioncCs|jdddddS)NrnzJ abc bingle bungle def zbingle bungle rrNrr r rtest_multiline_substitutionsz2ClinicLinearFormatTest.test_multiline_substitutionN) rrrrJrjrlrmrorprqr r r rrhs  rhc@seZdZddZddZdS) InertParsercCsdSrr r rr r rrszInertParser.__init__cCsdSrr r r$r r rr<szInertParser.parseNrrrrr<r r r rrrsrrc@seZdZddZddZdS) CopyParsercCsdSrr rsr r rrszCopyParser.__init__cCs |j|_dSr)rirHrtr r rr<szCopyParser.parseNrur r r rrvsrvc@s<eZdZddZddZddZddZd d Zd d Zd S)ClinicBlockParserTestcCsFtd}tt||}t|}|D]}||q(|j}dSr)rr'listr(Z BlockPrinterZ print_blockfgetvalue)r rirHr Zblockswriterr$r r rrJs    zClinicBlockParserTest._testcCs |||SrrN)r rir r r round_tripsz ClinicBlockParserTest.round_tripcCs|ddS)Nz( verbatim text here lah dee dah r|rr r rtest_round_trip_1sz'ClinicBlockParserTest.test_round_trip_1cCs|ddS)Nz verbatim text here lah dee dah /*[inert] abc [inert]*/ def /*[inert checksum: 7b18d017f89f61cf17d47f92749ea6930a3f1deb]*/ xyz r}rr r rtest_round_trip_2sz'ClinicBlockParserTest.test_round_trip_2cCsNtd}tj|dd}t||jd<t||jd<||}|||dS)Nrr:Zinertcopy)rr'r8rrparsersrvr<r?)r rirHr r@rIr r r _test_clinics   z"ClinicBlockParserTest._test_cliniccCs|dddS)Nz verbatim text here lah dee dah /*[copy input] def [copy start generated code]*/ abc /*[copy end generated code: output=03cfd743661f0797 input=7b18d017f89f61cf]*/ xyz z verbatim text here lah dee dah /*[copy input] def [copy start generated code]*/ def /*[copy end generated code: output=7b18d017f89f61cf input=7b18d017f89f61cf]*/ xyz )rrr r r test_clinic_1s z#ClinicBlockParserTest.test_clinic_1N) rrrrJr|r~rrrr r r rrws   rwc@sfeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#dCdDZ$dEdFZ%dGdHZ&dIdJZ'dKdLZ(dMdNZ)dOdPZ*dQdRZ+dZdUdVZ,dWdXZ-dYS)[ClinicParserTestcCsHtt}td}|||j\}}|d|j|d|jdS)Nzmodule os os.accessaccessos)rr"rBlockr< signaturesr?r )r parserr$r5functionr r r test_trivials     zClinicParserTest.test_trivialcCs4|d}|j\}}|d|j|d|jdS)Nz# module os os.accessrr)r<rr?r r r$r5rr r rtest_ignore_line's  z!ClinicParserTest.test_ignore_linecCsV|d}|d|j|dt|j|jd}|d|j||jtjdS)Nz module os os.access path: intrr;path) parse_functionr?r len parametersassertIsInstance converterrZ int_converterr rpr r r test_param-s   zClinicParserTest.test_paramcCs&|d}|jd}|d|jdS)Nz4module os os.access follow_symlinks: bool = Truefollow_symlinksTrrr?rrr r rtest_param_default5s  z#ClinicParserTest.test_param_defaultcCs&|d}|jd}|d|jdS)NzCmodule os os.access follow_symlinks: \ bool \ =\ TruerTrrr r rtest_param_with_continuations:s  z.ClinicParserTest.test_param_with_continuationscCsN|d}|jd}|tj|j|d|jj|d}||ddS)NzOmodule os os.access follow_symlinks: int(c_default='MAXSIZE') = sys.maxsizerZMAXSIZEz:module os os.access follow_symlinks: int = sys.maxsizez~Error on line 0: When you specify a named constant ('sys.maxsize') as your default value, you MUST specify a valid c_default. ) rrr?r0maxsizerrZ c_defaultparse_function_should_fail)r rrsr r rtest_param_default_expression?s    z.ClinicParserTest.test_param_default_expressioncCs@|d}|jd}|dt|j||jdjtjdS)NzR module os os.access follow_symlinks: bool = True something_else: str = ''rZsomething_else)rrr?rrrr str_converterrr r rtest_param_no_docstringHs  z(ClinicParserTest.test_param_no_docstringcCs|d}||ddS)NzM module os os.access follow_symlinks: bool = True something_else: strzoError on line 0: Can't have a parameter without a default ('something_else') after a parameter with a default! rr?r rr r r*test_param_default_parameters_out_of_orderRs z;ClinicParserTest.test_param_default_parameters_out_of_ordercCs,|d}|jd}|d|jjddS)Nz0module os os.access path: path_t(allow_fd=1)rZallow_fd)rrr?rr rr r r!disabled_test_converter_arguments]s  z2ClinicParserTest.disabled_test_converter_argumentscCs |d}|d|jdS)Nzx module os os.stat as os_stat_fn path: str Path to be examined Perform a stat system call on the given path.zj stat($module, /, path) -- Perform a stat system call on the given path. path Path to be examined rr?strip docstringr rr r rtest_function_docstringbs  z(ClinicParserTest.test_function_docstringcCs |d}|d|jdS)Nz| module foo foo.bar x: int Documentation for x. y: int This is the documentation for foo. Okay, we're done here. zt bar($module, /, x, y) -- This is the documentation for foo. x Documentation for x. Okay, we're done here. rrr r r%test_explicit_parameters_in_docstringus z6ClinicParserTest.test_explicit_parameters_in_docstringcCs|d}|d|jdS)Nz< module os os.stat path: str This/used to break Clinic! z5stat($module, /, path) -- This/used to break Clinic!)rr?rrr r rTtest_parser_regression_special_character_in_parameter_column_of_docstring_first_lines zeClinicParserTest.test_parser_regression_special_character_in_parameter_column_of_docstring_first_linecCs|d}|d|jdS)Nzmodule os os.stat as os_stat_fnZ os_stat_fn)rr?Z c_basenamerr r r test_c_names zClinicParserTest.test_c_namecCs|d}||jtjdS)Nzmodule os os.stat -> int)rrZreturn_converterrZint_return_converterrr r rtest_return_converters z&ClinicParserTest.test_return_convertercCs8|d}|jd}|tjj|j|d|jdS)Nz:module os os.access * follow_symlinks: bool = Truerr)rrr?inspect ParameterZ KEYWORD_ONLYkindgrouprr r r test_stars  zClinicParserTest.test_starcCs&|d}|jd}|d|jdS)Nz/module window window.border [ ls : int ] / Zlsr)rrr?rrr r r test_groups  zClinicParserTest.test_groupcCs\|d}dD]2\}}|j|}||j|||jtjjq||j d dS)Nz module curses curses.addch [ y: int Y-coordinate. x: int X-coordinate. ] ch: char Character to add. [ attr: long Attributes for the character. ] / ))rQ)rPrrRr)rSrz addch([y, x,] ch, [attr]) y Y-coordinate. x X-coordinate. ch Character to add. attr Attributes for the character. rrr?rrrrZPOSITIONAL_ONLYrrr rr rrr r rtest_left_groups    z ClinicParserTest.test_left_groupcCs\|d}dD]2\}}|j|}||j|||jtjjq||j d dS)Na module curses curses.imaginary [ [ y1: int Y-coordinate. y2: int Y-coordinate. ] x1: int X-coordinate. x2: int X-coordinate. ] ch: char Character to add. [ attr1: long Attributes for the character. attr2: long Attributes for the character. attr3: long Attributes for the character. [ attr4: long Attributes for the character. attr5: long Attributes for the character. attr6: long Attributes for the character. ] ] / ) )Zy1)Zy2r)Zx1r)Zx2rr)Zattr1r)Zattr2r)Zattr3r)Zattr4r;)Zattr5r;)Zattr6r;a imaginary([[y1, y2,] x1, x2,] ch, [attr1, attr2, attr3, [attr4, attr5, attr6]]) y1 Y-coordinate. y2 Y-coordinate. x1 X-coordinate. x2 X-coordinate. ch Character to add. attr1 Attributes for the character. attr2 Attributes for the character. attr3 Attributes for the character. attr4 Attributes for the character. attr5 Attributes for the character. attr6 Attributes for the character. rrr r rtest_nested_groupss  #  z#ClinicParserTest.test_nested_groupsc CsdtD}|t||Wdn1s40YWdn1sR0Y|Sr)rcaptured_stdoutre SystemExitrrz)r rstdoutr r rrs  Fz+ClinicParserTest.parse_function_should_failcCs|d}||ddS)Nz| module foo foo.two_top_groups_on_left [ group1 : int ] [ group2 : int ] param: int zpError on line 0: Function two_top_groups_on_left has an unsupported group configuration. (Unexpected state 2.b) rrr r r0test_disallowed_grouping__two_top_groups_on_left#s zAClinicParserTest.test_disallowed_grouping__two_top_groups_on_leftcCs|ddS)Nz} module foo foo.two_top_groups_on_right param: int [ group1 : int ] [ group2 : int ] rrr r r1test_disallowed_grouping__two_top_groups_on_right3szBClinicParserTest.test_disallowed_grouping__two_top_groups_on_rightcCs|ddS)Nz module foo foo.parameter_after_group_on_right param: int [ [ group1 : int ] group2 : int ] rrr r r8test_disallowed_grouping__parameter_after_group_on_right@szIClinicParserTest.test_disallowed_grouping__parameter_after_group_on_rightcCs|ddS)Nz module foo foo.group_after_parameter_on_left [ group2 : int [ group1 : int ] ] param: int rrr r r7test_disallowed_grouping__group_after_parameter_on_leftMszHClinicParserTest.test_disallowed_grouping__group_after_parameter_on_leftcCs|ddS)Nz` module foo foo.empty_group [ [ ] group2 : int ] param: int rrr r r-test_disallowed_grouping__empty_group_on_leftZsz>ClinicParserTest.test_disallowed_grouping__empty_group_on_leftcCs|ddS)Nz` module foo foo.empty_group param: int [ [ ] group2 : int ] rrr r r.test_disallowed_grouping__empty_group_on_rightfsz?ClinicParserTest.test_disallowed_grouping__empty_group_on_rightcCs.|d}|d|j|dt|jdS)Nz module foo foo.bar Docstring zbar($module, /) -- Docstringrrr?rrrrr r rtest_no_parametersrs z#ClinicParserTest.test_no_parameterscCs4|jdddd}|d|j|dt|jdS)NzL module foo class foo.Bar "unused" "notneeded" foo.Bar.__init__ Docstring rr;)signatures_in_blockfunction_indexzBar() -- Docstringrrrr r rtest_init_with_no_parameters}s  z-ClinicParserTest.test_init_with_no_parameterscCs|ddS)Nz! module foo foo.bar => int / rrr r rtest_illegal_module_linesz)ClinicParserTest.test_illegal_module_linecCs|ddS)Nz! module foo foo.bar as 935 / rrr r rtest_illegal_c_basenamesz(ClinicParserTest.test_illegal_c_basenamecCs|ddS)Nz module foo foo.bar * * rrr r rtest_single_starsz!ClinicParserTest.test_single_starcCs|ddS)Nz module foo foo.bar * rrr r rKtest_parameters_required_after_star_without_initial_parameters_or_docstringsz\ClinicParserTest.test_parameters_required_after_star_without_initial_parameters_or_docstringcCs|ddS)Nz* module foo foo.bar * Docstring here. rrr r rMtest_parameters_required_after_star_without_initial_parameters_with_docstringsz^ClinicParserTest.test_parameters_required_after_star_without_initial_parameters_with_docstringcCs|ddS)Nz( module foo foo.bar this: int * rrr r rMtest_parameters_required_after_star_with_initial_parameters_without_docstringsz^ClinicParserTest.test_parameters_required_after_star_with_initial_parameters_without_docstringcCs|ddS)Nz3 module foo foo.bar this: int * Docstring. rrr r rItest_parameters_required_after_star_with_initial_parameters_and_docstringszZClinicParserTest.test_parameters_required_after_star_with_initial_parameters_and_docstringcCs|ddS)Nz module foo foo.bar / / rrr r rtest_single_slashsz"ClinicParserTest.test_single_slashcCs|ddS)Nz< module foo foo.bar x: int y: int * z: int / rrr r rtest_mix_star_and_slashsz(ClinicParserTest.test_mix_star_and_slashcCs|ddS)Nz% module foo foo.bar / x: int rrr r r1test_parameters_not_permitted_after_slash_for_nowszBClinicParserTest.test_parameters_not_permitted_after_slash_for_nowcCs |d}|d|jdS)Nzk module foo foo.bar x: int Nested docstring here, goeth. * y: str Not at column 0! zV bar($module, /, x, *, y) -- Not at column 0! x Nested docstring here, goeth. rrr r rtest_function_not_at_column_0s z.ClinicParserTest.test_function_not_at_column_0csJt}t|d_fddjd<td}||jdS)NFcs tddS)NflagT)setattrr rr rz1ClinicParserTest.test_directive..Zsetflag)r"rrZ directivesrrr<Z assertTrue)r r@r$r rrtest_directives  zClinicParserTest.test_directivecCs.|d}|j\}}||jdjtjdS)Nz module os os.access path: "s"r)r<rrrrrrrr r rtest_legacy_converterss  z'ClinicParserTest.test_legacy_converterscCs&t}t|}t|}|||Sr)r"rrrr<)r textr@rr$r r rr<s   zClinicParserTest.parser;rcCs(||}|j}|t||||Sr)r<rr?r)r rrrr$rr r rrs zClinicParserTest.parse_functionc Cs|ttjd|ttjdtJ}|t tj ddddWdn1s^0YWdn1s|0Y|| ddS)Nz zzThe igloos are melting!z clown.txtE)r!Z line_numberz>Error in file "clown.txt" on line 69: The igloos are melting! ) r?r2r unspecifiedZNULLrrrerZfailrz)r rr r rtest_scaffolding s   Lz!ClinicParserTest.test_scaffoldingN)r;r).rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr<rrr r r rrsV    (L          rc@seZdZdZddZdS)ClinicExternalTestNc Cs"td}t|ddd}|}Wdn1s60Yt}tj|d}t|ddd}||Wdn1s0Yt |j }t |t|ddd}|}Wdn1s0Yt |j }Wdn1s0Y| ||| ||dS)Nz clinic.testrGzutf-8)encodingz clinic.test.cw)rZfindfileopenreadZtemp_dirrrjoinwritestat st_mtime_nsrZ parse_filer?) r sourceryZ orig_contentsZtmp_dirZtestfileZ old_mtime_nsZ new_contentsZ new_mtime_nsr r r test_externals & (  &* z ClinicExternalTest.test_external)rrrZmaxDiffrr r r rrsr__main__)testrrZunittestrr)rZos.pathrr0Zskip_if_missingZimports_under_toolrrrrrr8r@r"r9rCrhrrrvrwrrrmainr r r rs8   */04=~