a ze@sddlZddlZddlZddlZddlZddlmZddlmZddl Z ddl m Z m Z m Z m Z mZmZmZmZmZmZmZddl mZddl mZGdddeZGd d d e ZGd d d ejZGd ddeZGdddeZGdddeZGdddeZdddddZ ddZ!Gddde Z"GdddeZ#Gd d!d!eZ$Gd"d#d#eZ%Gd$d%d%eZ&Gd&d'd'eZ'Gd(d)d)eZ(Gd*d+d+eZ)Gd,d-d-eZ*Gd.d/d/eZ+Gd0d1d1eZ,Gd2d3d3eZ-Gd4d5d5eZ.Gd6d7d7eZ/Gd8d9d9eZ0Gd:d;d;eZ1Gdd?d?eZ3Gd@dAdAeZ4GdBdCdCeZ5GdDdEdEeZ6GdFdGdGeZ7GdHdIdIe7Z8GdJdKdKe7Z9GdLdMdMeZ:dNZ;dOZdRZ?GdSdTdTeZ@GdUdVdVeZAGdWdXdXeZBGdYdZdZejZCeDd[kreEdS)\N)StringIO)support) make_optionOptionTitledHelpFormatter OptionParser OptionGroupSUPPRESS_USAGE OptionErrorOptionConflictErrorBadOptionErrorOptionValueErrorValues) _match_abbrev) _parse_numc@seZdZdddZddZdS)InterceptedErrorNcCs||_||_||_dSN) error_message exit_status exit_message)selfrrrrF/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_optparse.py__init__szInterceptedError.__init__cCs|jp|jpdS)Nzintercepted error)rrrrrr__str__$szInterceptedError.__str__)NNN)__name__ __module__ __qualname__rrrrrrrs  rc@seZdZdddZddZdS)InterceptingOptionParserrNcCst||ddS)N)rrr)rstatusmsgrrrexit(szInterceptingOptionParser.exitcCst|ddS)N)rr )rr"rrrerror+szInterceptingOptionParser.error)rN)rrrr#r$rrrrr's rc@s>eZdZddZddZddZdd d Zd d Zd dZdS)BaseTestcCsH|j|\}}t|}|||dt|||dt||fS)aAssert the options are what we expected when parsing arguments. Otherwise, fail with a nicely formatted message. Keyword arguments: args -- A list of arguments to parse with OptionParser. expected_opts -- The options expected. expected_positional_args -- The positional arguments expected. Returns the options and positional args for further testing. zJ Options are %(optdict)s. Should be %(expected_opts)s. Args were %(args)s.zj Positional arguments are %(positional_args)s. Should be %(expected_positional_args)s. Args were %(args)s.)parser parse_argsvars assertEquallocals)rargsZ expected_optsZexpected_positional_argsoptionsZpositional_argsZoptdictrrr assertParseOK0s zBaseTest.assertParseOKc Cs|dur d}|duri}z||i|Wnp|y}zXt|}t|tjrl|||d|j|fn|||d||f|WYd}~Sd}~00|dt dS)a- Assert that the expected exception is raised when calling a function, and that the right error message is included with that exception. Arguments: func -- the function to call args -- positional arguments to `func` kwargs -- keyword arguments to `func` expected_exception -- exception that should be raised expected_message -- expected exception message (or pattern if a compiled regex object) Returns the exception raised for further testing. NrzLexpected exception message pattern: /%s/ actual exception message: '''%s''' zHexpected exception message: '''%s''' actual exception message: '''%s''' znexpected exception %(expected_exception)s not raised called %(func)r with args %(args)r and kwargs %(kwargs)r ) str isinstancerePattern assertTruesearchpatternr)failr*)rfuncr+kwargsZexpected_exceptionexpected_messageerrZactual_messagerrr assertRaisesNs0   zBaseTest.assertRaisesc CsRz|j|Wn2tyB}z||j|WYd}~nd}~00|ddS)z Assert the parser fails with the expected message. Caller must ensure that self.parser is an InterceptingOptionParser. Nzexpected parse failure)r&r'rr)r assertFalse)r cmdline_argsexpected_outputr9rrrassertParseFails $zBaseTest.assertParseFailrNc Cstj}z@z(tt_|j|Wtj}|t_ntj}|t_0Wn|ty}zd|t|t dt |||kr| d|d|d| |j || |j|WYd}~nd}~00|ddS)z7Assert the parser prints the expected output on stdout.z0expected output to be an ordinary string, not %rzexpected: ''' z''' but got ''' z'''Nzexpected parser.exit())sysstdoutrr&r'getvaluerr2r/r.typer5r)rrr;)rr<r=Zexpected_statusZexpected_errorZ save_stdoutoutputr9rrr assertOutputs6    $zBaseTest.assertOutputcGs|||dt|dS)z4Assert that TypeError is raised when executing func.N)r: TypeError)rr6r8r+rrrassertTypeErrorszBaseTest.assertTypeErrorcCs.|}||kr*|d|d|ddS)Nzhelp text failure; expected: "z "; got: "z" ) format_helpZfailureException)rr& expected_helpZ actual_helprrr assertHelpszBaseTest.assertHelp)rN) rrrr-r:r>rDrFrIrrrrr%/s; r%c@seZdZddZgifddZddZddZd 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/S)0TestOptionCheckscCsttd|_dSNusagerr r&rrrrsetUpszTestOptionChecks.setUpcCs|t||t|dSr)r:rr )rr8r+r7rrrassertOptionErrors z"TestOptionChecks.assertOptionErrorcCs|tddS)Nz+at least one option string must be supplied)rFrrrrrtest_opt_string_emptysz&TestOptionChecks.test_opt_string_emptycCs|ddgdS)Nz?invalid option string 'b': must be at least two characters longbrPrrrrtest_opt_string_too_shortsz*TestOptionChecks.test_opt_string_too_shortcCs|ddgdS)NzOinvalid short option string '--': must be of the form -x, (x any non-dash char)--rSrrrrtest_opt_string_short_invalidsz.TestOptionChecks.test_opt_string_short_invalidcCs|ddgdS)NzJinvalid long option string '---': must start with --, followed by non-dashz---rSrrrrtest_opt_string_long_invalidsz-TestOptionChecks.test_opt_string_long_invalidcCs|ddgddddS)Nz.option -b: invalid keyword arguments: bar, foo-bfoobarrSrrrrtest_attr_invalids z"TestOptionChecks.test_attr_invalidcCs|ddgddidS)Nz option -b: invalid action: 'foo'rXactionrZrSrrrrtest_action_invalids z$TestOptionChecks.test_action_invalidcCs,|ddgddi|ddgdtidS)Nz%option -b: invalid option type: 'foo'rXrBrZz'option -b: invalid option type: 'tuple')rPtuplerrrrtest_type_invalids  z"TestOptionChecks.test_type_invalidcCs|ddgddddS)Nz4option -b: must not supply a type for action 'count'rXcountint)r]rBrSrrrrtest_no_type_for_actions z(TestOptionChecks.test_no_type_for_actioncCs|dddgddidS)Nz@option -b/--bad: must supply a list of choices for type 'choice'rX--badrBchoicerSrrrrtest_no_choices_lists z%TestOptionChecks.test_no_choices_listcCs*tdj}|d|ddgddddS)NzBoption -b/--bad: choices must be a list of strings ('%s' supplied)rXrdrez bad choicesrBchoices)rBrrP)rtypenamerrrtest_bad_choices_lists z&TestOptionChecks.test_bad_choices_listcCs|ddgddddS)Nz1option -b: must not supply choices for type 'int'rXrbZbadrhrSrrrrtest_no_choices_for_types z)TestOptionChecks.test_no_choices_for_typecCs|ddgddddS)Nz:option -b: 'const' must not be supplied for action 'store'rXstore)r]constrSrrrrtest_no_const_for_action s z)TestOptionChecks.test_no_const_for_actioncCs|ddgddddS)Nz:option -b: 'nargs' must not be supplied for action 'count'rXra)r]nargsrSrrrrtest_no_nargs_for_actions z)TestOptionChecks.test_no_nargs_for_actioncCs|ddgddddS)Nz'option -b: callback not callable: 'foo'rXcallbackrZr]rtrSrrrrtest_callback_not_callables z+TestOptionChecks.test_callback_not_callablecCsdSrrrrrrdummyszTestOptionChecks.dummycCs|ddgd|jdddS)NzAoption -b: callback_args, if supplied, must be a tuple: not 'foo'rXrtrZ)r]rt callback_argsrPrwrrrrtest_callback_args_no_tuplesz,TestOptionChecks.test_callback_args_no_tuplecCs|ddgd|jdddS)NzBoption -b: callback_kwargs, if supplied, must be a dict: not 'foo'rXrtrZ)r]rtcallback_kwargsryrrrrtest_callback_kwargs_no_dict&sz-TestOptionChecks.test_callback_kwargs_no_dictcCs|ddgddddS)Nz