HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/lib/python3/dist-packages/twisted/test/__pycache__/test_usage.cpython-38.pyc
U

��W[]\�@stdZddlmZmZddlmZddlmZGdd�dej�Z	Gdd�dej
�ZGd	d
�d
ej�ZGdd�dej
�Z
Gd
d�dej�ZGdd�dej�ZGdd�dej
�ZGdd�dej
�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej
�ZGdd�dej
�ZGdd �d ej
�ZGd!d"�d"ej
�ZGd#d$�d$ej
�ZGd%d&�d&ej
�ZGd'd(�d(ej
�Zd)S)*zK
Tests for L{twisted.python.usage}, a command line option parsing library.
�)�division�absolute_import)�unittest)�usagec@sVeZdZddddgdddgdd	d
gdd	dd
ggZdddgddggZdd�Zdd�Zd	S)�WellBehaved�long�w�defaultzand a docstring�another�nzno docstring�longonlyN�noshort�	shortless�exceptzthis one got docstring�aflag�fzO

                 flagallicious docstringness for this here

                 �flout�ocCsd|jd<dS)N�PONY!�myflag��opts��self�r�9/usr/lib/python3/dist-packages/twisted/test/test_usage.py�
opt_myflagszWellBehaved.opt_myflagcCsd|f|jd<dS)Nz%s WITH A PONY!�myparamr�r�valuerrr�opt_myparam"szWellBehaved.opt_myparam)�__name__�
__module__�__qualname__�
optParameters�optFlagsrr rrrrrs
����	rc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�ParseCorrectnessTestszZ
    Test L{usage.Options.parseOptions} for correct values under
    good conditions.
    cCs$d��|_t�|_|j�|j�dS)zL
        Instantiate and parseOptions a well-behaved Options class.
        �A--long Alpha -n Beta --shortless Gamma -f --myflag --myparam TofuN)�split�niceArgVr�nice�parseOptionsrrrr�setUp,s
zParseCorrectnessTests.setUpcCsT|�|jjdd�|�|jjdd�|�|jjdd�|�|jjdd�d	S)
z1
        Parameters have correct values.
        rZAlphar
ZBetarr
rZGammaN��assertEqualr*rrrrr�test_checkParameters9sz*ParseCorrectnessTests.test_checkParameterscCs,|�|jjdd�|�|jjdd�dS)z,
        Flags have correct values.
        r�rrNr-rrrr�test_checkFlagsBsz%ParseCorrectnessTests.test_checkFlagscCs,|�|jjdd�|�|jjdd�dS)zB
        Custom flags and parameters have correct values.
        rrrzTofu WITH A PONY!Nr-rrrr�test_checkCustomsIsz'ParseCorrectnessTests.test_checkCustomsN)r!r"r#�__doc__r,r/r1r2rrrrr&'s

	r&c@sLeZdZddddegddddegdddd	egd
dddeggZdd
�ZeZdS)�TypedOptions�foointN�zFoo int�foofloat��Q���@z	Foo float�eggintzEgg int without default�eggfloatzEgg float without defaultcCs
||_dS)zg
        This option has an underscore in its name to exercise the _ to -
        translation.
        N)�underscoreValuerrrr�opt_under_scoreZszTypedOptions.opt_under_score)r!r"r#�int�floatr$r<Zopt_urrrrr4Rs�r4c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�
TypedTestszK
    Test L{usage.Options.parseOptions} for options with forced types.
    cCst�|_dS�N)r4rrrrrr,hszTypedTests.setUpcCs�g}|j�|�|�|jjdd�|�|jjdt�|�|jjdd�|�|jjdt�|�|jjd�|�|jjd�dS)z,
        Default values are parsed.
        r5r6r7r8r9r:N)rr+r.r�assertIsInstancer=r>�assertIsNone�r�argVrrr�test_defaultValueskszTypedTests.test_defaultValuescCs�d��}|j�|�|�|jjdd�|�|jjdt�|�|jjdd�|�|jjdt�|�|jjdd�|�|jjdt�|�|jjdd	�|�|jjdt�d
S)z2
        int and float values are parsed.
        z8--fooint 912 --foofloat -823.1 --eggint 32 --eggfloat 21r5i�r7g����̸��r9� r:g5@N)r(rr+r.rrAr=r>rCrrr�test_parsingValuesyszTypedTests.test_parsingValuescCs$|j�ddg�|�|jjd�dS)zw
        A dash in an option name is translated to an underscore before being
        dispatched to a handler.
        z
--under-score�fooN�rr+r.r;rrrr�test_underscoreOption�sz TypedTests.test_underscoreOptioncCs$|j�ddg�|�|jjd�dS)zE
        An option name with a dash in it can have an alias.
        z-u�barNrIrrrr�test_underscoreOptionAlias�sz%TypedTests.test_underscoreOptionAliascCs d��}|�tj|jj|�dS)z7
        Passing wrong values raises an error.
        z--fooint eggN)r(�assertRaisesr�
UsageErrorr+rCrrr�test_invalidValues�szTypedTests.test_invalidValuesN)
r!r"r#r3r,rErGrJrLrOrrrrr?ds	r?c@seZdZdddddggZdS)�WrongTypedOptions�barwrongNzBar with wrong coerceZhe)r!r"r#r$rrrrrP�s�rPc@s8eZdZdd�Zdd�Zddddegdddd	eggZdS)
�WeirdCallableOptionscCstd��dS)NZOuch)�RuntimeError�rrrr�_bar�szWeirdCallableOptions._barcCstd��dS)NZYay)�
ValueErrorrTrrr�_foo�szWeirdCallableOptions._foorQNzBar with strange callableZfoowrongzFoo with strange callable)r!r"r#rUrWr$rrrrrR�s
�rRc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�WrongTypedTestszF
    Test L{usage.Options.parseOptions} for wrong coerce options.
    cCs"t�}d��}|�t|j|�dS)z2
        Using a non-callable type fails.
        z--barwrong eggN)rPr(rM�	TypeErrorr+�r�usrDrrr�test_nonCallable�sz WrongTypedTests.test_nonCallablecCst�}g}|�|�dS)zP
        The coerce functions are not called if no values are provided.
        N)rRr+rZrrr�test_notCalledInDefault�sz'WrongTypedTests.test_notCalledInDefaultcCsRt�}d��}|�tj|j|�}|�t|�d�t�}d��}|�t|j|�dS)zI
        Errors raised by coerce functions are handled properly.
        z--foowrong blahz&Parameter type enforcement failed: Yayz--barwrong blahN)	rRr(rMrrNr+r.�strrS)rr[rD�errr�test_weirdCallable�sz"WrongTypedTests.test_weirdCallableN)r!r"r#r3r\r]r`rrrrrX�srXc@seZdZdd�ZdS)�OutputTestscCs.t�}|�tj|jdg�}|�t|�d�dS)zF
        Error output case adjustment does not mangle options
        z-Zzoption -Z not recognizedN)rrMrrNr+r.r^)rZoptr_rrr�test_uppercasing�s�zOutputTests.test_uppercasingN)r!r"r#rbrrrrra�srac@seZdZdgZdgZdS)�InquisitionOptions)�expectr_)�torture-device�t�comfy-chairzset preferred torture deviceN)r!r"r#r%r$rrrrrc�s��rcc@seZdZddgZdS)�HolyQuestOptions)�	horseback�hzuse a horse)�	for-grail�gN)r!r"r#r%rrrrrh�s�rhc@s*eZdZdgZddedfddedfgZdS)	�SubCommandOptions)�europian-swallowNz$set default swallow type to Europian�inquisition�inquestzPerform an inquisition�	holyquestZquestzEmbark upon a holy questN)r!r"r#r%rcrh�subCommandsrrrrrm�s���rmc@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�SubCommandTestszJ
    Test L{usage.Options.parseOptions} for options with subcommands.
    cCsdt�}|�ddg�|�|d�|�|jd�|�|jt�|�|jd�|�|jdd�dS)z-
        A subcommand is recognized.
        �--europian-swallowrornrdrergN)	rmr+�
assertTruer.�
subCommandrA�
subOptionsrc�assertFalse�rrrrr�test_simpleSubcommandsz%SubCommandTests.test_simpleSubcommandcCsft�}|�dddg�|�|d�|�|jd�|�|jt�|�|jd�|�|jdd�dS)	zA
        Flags and options of a subcommand are assigned.
        ro�--expect�--torture-device=featherrnrdre�featherN�	rmr+rxr.rvrArwrcruryrrr�"test_subcommandWithFlagsAndOptionssz2SubCommandTests.test_subcommandWithFlagsAndOptionscCsft�}|�dddg�|�|d�|�|jd�|�|jt�|�|jd�|�|jdd�d	S)
zG
        Flags and options of a subcommand alias are assigned.
        rpr{r|rnrordrer}Nr~ryrrr�'test_subcommandAliasWithFlagsAndOptionssz7SubCommandTests.test_subcommandAliasWithFlagsAndOptionscCsbt�}|�ddg�|�|d�|�|jd�|�|jt�|�|jd�|�|jd�dS)zG
        Flags and options of another subcommand are assigned.
        rqz--for-grailrnrirkN)	rmr+rxr.rvrArwrhruryrrr�)test_anotherSubcommandWithFlagsAndOptions*sz9SubCommandTests.test_anotherSubcommandWithFlagsAndOptionscCs@t�}|�dg�|�|d�|�|j�|�t|d��dS)z�
        If no subcommand is specified and no default subcommand is assigned,
        a subcommand will not be implied.
        rtrnrwN)rmr+rurBrvrx�hasattrryrrr�test_noSubcommand6s
z!SubCommandTests.test_noSubcommandcCsht�}d|_|�dg�|�|d�|�|jd�|�|jt�|�	|jd�|�|jdd�dS)	zK
        Flags and options in the default subcommand are assigned.
        rprtrnrordrergN)
rmZdefaultSubCommandr+rur.rvrArwrcrxryrrr�test_defaultSubcommandAsz&SubCommandTests.test_defaultSubcommandcs`Gdd�dtj��G�fdd�dtj�}|�}|�dg�|�t|jd��|�|jj|�dS)zw
        The parseOptions method from the Options object specified for the
        given subcommand is called.
        c@seZdZdd�ZdS)zDSubCommandTests.test_subCommandParseOptionsHasParent.<locals>.SubOptc_s |j|_tjj|f|�|�dSr@)�parent�	sawParentr�Optionsr+)r�a�kwrrrr+TszQSubCommandTests.test_subCommandParseOptionsHasParent.<locals>.SubOpt.parseOptionsN)r!r"r#r+rrrr�SubOptSsr�cseZdZdd�dfgZdS)zASubCommandTests.test_subCommandParseOptionsHasParent.<locals>.OptrHrrKN�r!r"r#rrr�r�rr�OptWs
�r�rHr�N)rr�r+rur�rwr.r�)rr�rrr�r�$test_subCommandParseOptionsHasParentNsz4SubCommandTests.test_subCommandParseOptionsHasParentcs�Gdd�dtj��G�fdd�dtj�}G�fdd�dtj�}|�}|�dg�|�}|�dg�|�t|jd	��|�t|jd	��|�|jj|�|�|jj|�d
S)zh
        The .parent pointer is correct even when the same Options class is
        used twice.
        c@seZdZdS)z:SubCommandTests.test_subCommandInTwoPlaces.<locals>.SubOptN)r!r"r#rrrrr�esr�cseZdZdd�dfgZdS)z:SubCommandTests.test_subCommandInTwoPlaces.<locals>.OptFoorHr�quuxNr�rr�rr�OptFoogs
�r�cseZdZdd�dfgZdS)z:SubCommandTests.test_subCommandInTwoPlaces.<locals>.OptBarrK�br�Nr�rr�rr�OptBarks
�r�rHrKr�N)rr�r+rur�rwZfailUnlessIdenticalr�)rr�r�ZoFooZoBarrr�r�test_subCommandInTwoPlaces`sz*SubCommandTests.test_subCommandInTwoPlacesN)r!r"r#r3rzrr�r�r�r�r�r�rrrrrss
rsc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�HelpStringTestsz&
    Test generated help strings.
    cCsd��|_t�|_dS)z;
        Instantiate a well-behaved Options class.
        r'N)r(r)rr*rrrrr,}s
zHelpStringTests.setUpc
Cs@z|j��Wn,tk
r:}z|�|�W5d}~XYnXdS)z,
        __str__ shouldn't go boom.
        N)r*�__str__�	ExceptionZfail)rr_rrr�
test_noGoBoom�szHelpStringTests.test_noGoBoomcCsFdd�t|j���D�}|�t|�dk�|�|d�d�dk�dS)zK
        Extra whitespace in flag and parameters docs is stripped.
        cSsg|]}|�d�dkr|�qS)rr)�find)�.0�srrr�
<listcomp>�szJHelpStringTests.test_whitespaceStripFlagsAndParameters.<locals>.<listcomp>rZ
flagalliciousN)r^r*�
splitlinesru�lenr�)r�linesrrr�&test_whitespaceStripFlagsAndParameters�sz6HelpStringTests.test_whitespaceStripFlagsAndParametersN)r!r"r#r3r,r�r�rrrrr�ys	r�c@s eZdZdZdd�Zdd�ZdS)�PortCoerceTestsz3
    Test the behavior of L{usage.portCoerce}.
    cCs:|�dt�d��|�dt�d��|�dt�d��dS)z4
        Test the answers with valid input.
        r�0i�Z3210i��Z65535N)r.r�
portCoercerrrr�test_validCoerce�sz PortCoerceTests.test_validCoercecCsD|�ttjd�|�ttjd�|�ttjd�|�ttjd�dS)z"
        Test error path.
        �z-21Z212189rHN)rMrVrr�rrrr�test_errorCoerce�sz PortCoerceTests.test_errorCoerceN)r!r"r#r3r�r�rrrrr��sr�c@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�ZshCompleterTestsz�
    Test the behavior of the various L{twisted.usage.Completer} classes
    for producing output usable by zsh tab-completion system.
    cCsNt��}|�dtj�}|�|d�tjddd�}|�dtj�}|�|d�dS)zX
        Completer produces zsh shell-code that produces no completion matches.
        �some-optionz
:some-option:�some actionT�Zdescr�repeat�*:some action:N)r�	Completer�
_shellCode�_ZSHr.�r�c�gotrrr�test_completer�sz ZshCompleterTests.test_completercCstt��}|�dtj�}|�|d�t�d�}|�dtj�}|�|d�tjdddd�}|�dtj�}|�|d�d	S)
zn
        CompleteFiles produces zsh shell-code that completes file names
        according to a glob.
        r�z:some-option (*):_files -g "*"z*.pyz$:some-option (*.py):_files -g "*.py"r�Tr�z%*:some action (*.py):_files -g "*.py"N)r�
CompleteFilesr�r�r.r�rrr�
test_files�s
zZshCompleterTests.test_filescCsNt��}|�dtj�}|�|d�tjddd�}|�dtj�}|�|d�dS)zV
        CompleteDirs produces zsh shell-code that completes directory names.
        r�z:some-option:_directoriesr�Tr�z*:some action:_directoriesN)r�CompleteDirsr�r�r.r�rrr�	test_dirs�szZshCompleterTests.test_dirscCs�t�d�}|�dtj�}|�|d�t�dddg�}|�dtj�}|�|d�tjdddgdd	d
�}|�dtj�}|�|d�dS)
zw
        CompleteList produces zsh shell-code that completes words from a fixed
        list of possibilities.
        �ABCr�z:some-option:(A B C)�1�2�3z:some-option:(1 2 3)r�Tr�z*:some action:(1 2 3)N)r�CompleteListr�r�r.r�rrr�	test_list�s
�zZshCompleterTests.test_listcCs�t�d�}|�dtj�}|�|d�t�dddg�}|�dtj�}|�|d�tjdddgdd	d
�}|�dtj�}d}|�||�dS)
z�
        CompleteMultiList produces zsh shell-code that completes multiple
        comma-separated words from a fixed list of possibilities.
        r�r�z-:some-option:_values -s , 'some-option' A B Cr�r�r�z-:some-option:_values -s , 'some-option' 1 2 3r�Tr�z.*:some action:_values -s , 'some action' 1 2 3N)r�CompleteMultiListr�r�r.)rr�r�Zexpectedrrr�test_multiList�s
�z ZshCompleterTests.test_multiListcCsNt��}|�dtj�}|�|d�tjddd�}|�dtj�}|�|d�dS)zd
        CompleteUsernames produces zsh shell-code that completes system
        usernames.
        r�z:some-option:_usersr�Tr�z*:some action:_usersN)r�CompleteUsernamesr�r�r.�rr��outrrr�test_usernamessz ZshCompleterTests.test_usernamescCsNt��}|�dtj�}|�|d�tjddd�}|�dtj�}|�|d�dS)zc
        CompleteGroups produces zsh shell-code that completes system group
        names.
        r�z:group:_groupsr�Tr�z*:some action:_groupsN)r�CompleteGroupsr�r�r.r�rrr�test_groupsszZshCompleterTests.test_groupscCsNt��}|�dtj�}|�|d�tjddd�}|�dtj�}|�|d�dS)zU
        CompleteHostnames produces zsh shell-code that completes hostnames.
        r�z:some-option:_hostsr�Tr�z*:some action:_hostsN)r�CompleteHostnamesr�r�r.r�rrr�test_hostnames'sz ZshCompleterTests.test_hostnamescCsVt��}|�dtj�}|�|�d��tjddd�}|�dtj�}|�|�d��dS)z�
        CompleteUserAtHost produces zsh shell-code that completes hostnames or
        a word of the form <username>@<hostname>.
        r�z:host | user@host:r�Tr�r�N)r�CompleteUserAtHostr�r�ru�
startswithr�rrr�test_userAtHost4sz!ZshCompleterTests.test_userAtHostcCsNt��}|�dtj�}|�|d�tjddd�}|�dtj�}|�|d�dS)zv
        CompleteNetInterfaces produces zsh shell-code that completes system
        network interface names.
        r�z:some-option:_net_interfacesr�Tr�z*:some action:_net_interfacesN)r�CompleteNetInterfacesr�r�r.r�rrr�test_netInterfacesBsz$ZshCompleterTests.test_netInterfacesN)r!r"r#r3r�r�r�r�r�r�r�r�r�r�rrrrr��s


r�c@seZdZdZdd�ZdS)�CompleterNotImplementedTestszs
    Using an unknown shell constant with the various Completer() classes
    should raise NotImplementedError
    c
Csltjtjtjtjtjtjtjtjtj	tj
g
}|D]6}z
|�}Wn|d�}YnX|�t|j
dd�q0dS)zM
        Using an unknown shellType should raise NotImplementedError
        NZbad_shell_type)rr�r�r�r�r�r�r�r�r�r�rM�NotImplementedErrorr�)r�classes�cls�actionrrr�test_unknownShellVs&�

�z.CompleterNotImplementedTests.test_unknownShellN)r!r"r#r3r�rrrrr�Qsr�c@s@eZdZdZGdd�de�Zdd�Zdd�Zdd	�Zd
d�Z	dS)
�FlagFunctionTestsz*
    Tests for L{usage.flagFunction}.
    c@s(eZdZdZdd�Zdd�Zdd�ZdS)	zFlagFunctionTests.SomeClassz>
        Dummy class for L{usage.flagFunction} tests.
        cCsdS)z�
            A one argument method to be tested by L{usage.flagFunction}.

            @param a: a useless argument to satisfy the function's signature.
            Nr)rr�rrr�oneArgssz"FlagFunctionTests.SomeClass.oneArgcCsdS)zU
            A no argument method to be tested by L{usage.flagFunction}.
            Nrrrrr�noArgzsz!FlagFunctionTests.SomeClass.noArgcCsdS)aG
            A multiple arguments method to be tested by L{usage.flagFunction}.

            @param a: a useless argument to satisfy the function's signature.
            @param b: a useless argument to satisfy the function's signature.
            @param c: a useless argument to satisfy the function's signature.
            Nr)rr�r�r�rrr�manyArgssz$FlagFunctionTests.SomeClass.manyArgsN)r!r"r#r3r�r�r�rrrr�	SomeClassosr�cCs|�dt�|��j��dS)zs
        L{usage.flagFunction} returns C{False} if the method checked allows
        exactly one argument.
        FN)�assertIsr�flagFunctionr�r�rrrr�test_hasArg�szFlagFunctionTests.test_hasArgcCs|�dt�|��j��dS)zq
        L{usage.flagFunction} returns C{True} if the method checked allows
        exactly no argument.
        TN)r�rr�r�r�rrrr�
test_noArg�szFlagFunctionTests.test_noArgcCs,|�tjtj|��j�}|�dt|��dS)z
        L{usage.flagFunction} raises L{usage.UsageError} if the method checked
        allows more than one argument.
        z$Invalid Option function for manyArgsN�rMrrNr�r�r�r.r^�r�excrrr�test_tooManyArguments�s�z'FlagFunctionTests.test_tooManyArgumentscCs.|�tjtj|��jd�}|�dt|��dS)z�
        L{usage.flagFunction} uses the given method name in the error message
        raised when the method allows too many arguments.
        Zflubudufz$Invalid Option function for flubudufNr�r�rrr�,test_tooManyArgumentsAndSpecificErrorMessage�s�z>FlagFunctionTests.test_tooManyArgumentsAndSpecificErrorMessageN)
r!r"r#r3�objectr�r�r�r�r�rrrrr�js
r�c@seZdZdZdd�ZdS)�OptionsInternalTestsz6
    Tests internal behavior of C{usage.Options}.
    cCsPGdd�dtj�}|�}|�t�dddgd�|jd|jd|jdd��dS)zs
        Options which are synonyms to another option are aliases towards the
        longest option name.
        c@seZdZdd�ZeZeZdS)z;OptionsInternalTests.test_optionsAliasesOrder.<locals>.OptscSsdS)z~
                This is an option method with a very long name, that is going to
                be aliased.
                Nrrrrr�opt_very_very_long�szNOptionsInternalTests.test_optionsAliasesOrder.<locals>.Opts.opt_very_very_longN)r!r"r#r�Z	opt_shortZopt_srrrr�Opts�sr�r��short�very-very-long)r�r�r�N)rr�r.�dict�fromkeysZsynonyms)rr�rrrr�test_optionsAliasesOrder�s
���z-OptionsInternalTests.test_optionsAliasesOrderN)r!r"r#r3r�rrrrr��sr�N)r3Z
__future__rrZ
twisted.trialrZtwisted.pythonrr�rZTestCaser&r4r?rPrRrXrarcrhrmrsr�r�r�r�r�r�rrrr�<module>s,+@$w#E