Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/test/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/test/__pycache__/test_usage.cpython-37.pyc

B

;��]]\�@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)NzPONY!�myflag)�opts)�self�r�J/opt/alt/python37/lib64/python3.7/site-packages/twisted/test/test_usage.py�
opt_myflagszWellBehaved.opt_myflagcCsd|f|jd<dS)Nz%s WITH A PONY!�myparam)r)r�valuerrr�opt_myparam"szWellBehaved.opt_myparam)�__name__�
__module__�__qualname__�
optParameters�optFlagsrrrrrrrs

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.
        zA--long Alpha -n Beta --shortless Gamma -f --myflag --myparam TofuN)�split�niceArgVr�nice�parseOptions)rrrr�setUp,s
zParseCorrectnessTests.setUpcCsT|�|jjdd�|�|jjdd�|�|jjdd�|�|jjdd�d	S)
z1
        Parameters have correct values.
        r�Alphar
ZBetarr
rZGammaN)�assertEqualr%r)rrrr�test_checkParameters9sz*ParseCorrectnessTests.test_checkParameterscCs,|�|jjdd�|�|jjdd�dS)z,
        Flags have correct values.
        r�rrN)r)r%r)rrrr�test_checkFlagsBsz%ParseCorrectnessTests.test_checkFlagscCs,|�|jjdd�|�|jjdd�dS)zB
        Custom flags and parameters have correct values.
        rzPONY!rzTofu WITH A PONY!N)r)r%r)rrrr�test_checkCustomsIsz'ParseCorrectnessTests.test_checkCustomsN)rrr�__doc__r'r*r,r-rrrrr"'s

	r"c@sLeZdZddddegddddegdddd	egd
dddeggZdd
�ZeZdS)�TypedOptions�foointNi�zFoo int�foofloatg�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)�underscoreValue)rrrrr�opt_under_scoreZszTypedOptions.opt_under_score)rrr�int�floatr r5Zopt_urrrrr/Rsr/c@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)r/r)rrrrr'hszTypedTests.setUpcCs�g}|j�|�|�|jjdd�|�|jjdt�|�|jjdd�|�|jjdt�|�|jjd�|�|jjd�dS)z,
        Default values are parsed.
        r0i�r1g�Q���@r2r3N)rr&r)r�assertIsInstancer6r7�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 21r0i�r1g����̸��r2� r3g5@N)r#rr&r)rr9r6r7)rr;rrr�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)r4)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�barN)rr&r)r4)rrrr�test_underscoreOptionAlias�sz%TypedTests.test_underscoreOptionAliascCs d��}|�tj|jj|�dS)z7
        Passing wrong values raises an error.
        z--fooint eggN)r#�assertRaisesr�
UsageErrorr&)rr;rrr�test_invalidValues�szTypedTests.test_invalidValuesN)
rrrr.r'r<r>r@rBrErrrrr8ds	r8c@seZdZdddddggZdS)�WrongTypedOptions�barwrongNzBar with wrong coerce�he)rrrr rrrrrF�srFc@s8eZdZdd�Zdd�Zddddegdddd	eggZdS)
�WeirdCallableOptionscCstd��dS)NZOuch)�RuntimeError)rrrr�_bar�szWeirdCallableOptions._barcCstd��dS)NZYay)�
ValueError)rrrr�_foo�szWeirdCallableOptions._foorGNzBar with strange callableZfoowrongzFoo with strange callable)rrrrKrMr rrrrrI�srIc@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)rFr#rC�	TypeErrorr&)r�usr;rrr�test_nonCallable�sz WrongTypedTests.test_nonCallablecCst�}g}|�|�dS)zP
        The coerce functions are not called if no values are provided.
        N)rIr&)rrPr;rrr�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)	rIr#rCrrDr&r)�strrJ)rrPr;�errr�test_weirdCallable�sz"WrongTypedTests.test_weirdCallableN)rrrr.rQrRrUrrrrrN�srNc@seZdZdd�ZdS)�OutputTestscCs.t�}|�tj|jdg�}|�t|�d�dS)zF
        Error output case adjustment does not mangle options
        z-Zzoption -Z not recognizedN)rrCrrDr&r)rS)r�optrTrrr�test_uppercasing�szOutputTests.test_uppercasingN)rrrrXrrrrrV�srVc@seZdZdgZdgZdS)�InquisitionOptions)�expectrT)ztorture-device�tzcomfy-chairzset preferred torture deviceN)rrrr!r rrrrrY�srYc@seZdZddgZdS)�HolyQuestOptions)�	horseback�hzuse a horse)z	for-grail�gN)rrrr!rrrrr\�sr\c@s*eZdZdgZddedfddedfgZdS)	�SubCommandOptions)zeuropian-swallowNz$set default swallow type to Europian�inquisition�inquestzPerform an inquisition�	holyquestZquestzEmbark upon a holy questN)rrrr!rYr\�subCommandsrrrrr`�s
r`c@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.
        z--europian-swallowrazeuropian-swallowrZztorture-devicezcomfy-chairN)	r`r&�
assertTruer)�
subCommandr9�
subOptionsrY�assertFalse)rrrrr�test_simpleSubcommandsz%SubCommandTests.test_simpleSubcommandcCsft�}|�dddg�|�|d�|�|jd�|�|jt�|�|jd�|�|jdd�dS)	zA
        Flags and options of a subcommand are assigned.
        raz--expectz--torture-device=featherzeuropian-swallowrZztorture-device�featherN)	r`r&rir)rgr9rhrYrf)rrrrr�"test_subcommandWithFlagsAndOptionssz2SubCommandTests.test_subcommandWithFlagsAndOptionscCsft�}|�dddg�|�|d�|�|jd�|�|jt�|�|jd�|�|jdd�d	S)
zG
        Flags and options of a subcommand alias are assigned.
        rbz--expectz--torture-device=featherzeuropian-swallowrarZztorture-devicerkN)	r`r&rir)rgr9rhrYrf)rrrrr�'test_subcommandAliasWithFlagsAndOptionssz7SubCommandTests.test_subcommandAliasWithFlagsAndOptionscCsbt�}|�ddg�|�|d�|�|jd�|�|jt�|�|jd�|�|jd�dS)zG
        Flags and options of another subcommand are assigned.
        rcz--for-grailzeuropian-swallowr]z	for-grailN)	r`r&rir)rgr9rhr\rf)rrrrr�)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.
        z--europian-swallowzeuropian-swallowrhN)r`r&rfr:rgri�hasattr)rrrrr�test_noSubcommand6s
z!SubCommandTests.test_noSubcommandcCsht�}d|_|�dg�|�|d�|�|jd�|�|jt�|�	|jd�|�|jdd�dS)	zK
        Flags and options in the default subcommand are assigned.
        rbz--europian-swallowzeuropian-swallowrarZztorture-devicezcomfy-chairN)
r`ZdefaultSubCommandr&rfr)rgr9rhrYri)rrrrr�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|�|�dS)N)�parent�	sawParentr�Optionsr&)r�a�kwrrrr&TszQSubCommandTests.test_subCommandParseOptionsHasParent.<locals>.SubOpt.parseOptionsN)rrrr&rrrr�SubOptSsrwcseZdZdd�dfgZdS)zASubCommandTests.test_subCommandParseOptionsHasParent.<locals>.Optr?rrAN)rrrrdr)rwrr�OptWsrxr?rsN)rrtr&rfrorhr)rs)rrxrr)rwr�$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)rrrrrrrrwesrwcseZdZdd�dfgZdS)z:SubCommandTests.test_subCommandInTwoPlaces.<locals>.OptFoor?r�quuxN)rrrrdr)rwrr�OptFoogsr{cseZdZdd�dfgZdS)z:SubCommandTests.test_subCommandInTwoPlaces.<locals>.OptBarrA�brzN)rrrrdr)rwrr�OptBarksr}r?rArrN)rrtr&rfrorhZfailUnlessIdenticalrr)rr{r}ZoFooZoBarr)rwr�test_subCommandInTwoPlaces`sz*SubCommandTests.test_subCommandInTwoPlacesN)rrrr.rjrlrmrnrprqryr~rrrrres
rec@s(eZdZdZdd�Zdd�Zdd�ZdS)	�HelpStringTestsz&
    Test generated help strings.
    cCsd��|_t�|_dS)z;
        Instantiate a well-behaved Options class.
        zA--long Alpha -n Beta --shortless Gamma -f --myflag --myparam TofuN)r#r$rr%)rrrrr'}s
zHelpStringTests.setUpc
Cs@y|j��Wn,tk
r:}z|�|�Wdd}~XYnXdS)z,
        __str__ shouldn't go boom.
        N)r%�__str__�	ExceptionZfail)rrTrrr�
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)rSr%�
splitlinesrf�lenr�)r�linesrrr�&test_whitespaceStripFlagsAndParameters�sz6HelpStringTests.test_whitespaceStripFlagsAndParametersN)rrrr.r'r�r�rrrrrys	rc@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�
portCoerce)rrrr�test_validCoerce�sz PortCoerceTests.test_validCoercecCsD|�ttjd�|�ttjd�|�ttjd�|�ttjd�dS)z"
        Test error path.
        �z-21Z212189r?N)rCrLrr�)rrrr�test_errorCoerce�sz PortCoerceTests.test_errorCoerceN)rrrr.r�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.
        zsome-optionz
:some-option:zsome actionT)�descr�repeatz*: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.
        zsome-optionz:some-option (*):_files -g "*"z*.pyz$:some-option (*.py):_files -g "*.py"zsome actionT)r�r�z%*:some action (*.py):_files -g "*.py"N)r�
CompleteFilesr�r�r))rr�r�rrr�
test_files�s
zZshCompleterTests.test_filescCsNt��}|�dtj�}|�|d�tjddd�}|�dtj�}|�|d�dS)zV
        CompleteDirs produces zsh shell-code that completes directory names.
        zsome-optionz:some-option:_directorieszsome actionT)r�r�z*:some action:_directoriesN)r�CompleteDirsr�r�r))rr�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.
        �ABCzsome-optionz:some-option:(A B C)�1�2�3z:some-option:(1 2 3)zsome actionT)r�r�z*:some action:(1 2 3)N)r�CompleteListr�r�r))rr�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�zsome-optionz-:some-option:_values -s , 'some-option' A B Cr�r�r�z-:some-option:_values -s , 'some-option' 1 2 3zsome actionT)r�r�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.
        zsome-optionz:some-option:_userszsome actionT)r�r�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.
        zsome-optionz:group:_groupszsome actionT)r�r�z*:some action:_groupsN)r�CompleteGroupsr�r�r))rr�r�rrr�test_groupsszZshCompleterTests.test_groupscCsNt��}|�dtj�}|�|d�tjddd�}|�dtj�}|�|d�dS)zU
        CompleteHostnames produces zsh shell-code that completes hostnames.
        zsome-optionz:some-option:_hostszsome actionT)r�r�z*:some action:_hostsN)r�CompleteHostnamesr�r�r))rr�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>.
        zsome-optionz:host | user@host:zsome actionT)r�r�z*:some action:N)r�CompleteUserAtHostr�r�rf�
startswith)rr�r�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.
        zsome-optionz:some-option:_net_interfaceszsome actionT)r�r�z*:some action:_net_interfacesN)r�CompleteNetInterfacesr�r�r))rr�r�rrr�test_netInterfacesBsz$ZshCompleterTests.test_netInterfacesN)rrrr.r�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
Csptjtjtjtjtjtjtjtjtj	tj
g
}x>|D]6}y
|�}Wn|d�}YnX|�t|j
dd�q2WdS)zM
        Using an unknown shellType should raise NotImplementedError
        NZbad_shell_type)rr�r�r�r�r�r�r�r�r�r�rC�NotImplementedErrorr�)r�classes�cls�actionrrr�test_unknownShellVs


z.CompleterNotImplementedTests.test_unknownShellN)rrrr.r�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)rrurrr�oneArgssz"FlagFunctionTests.SomeClass.oneArgcCsdS)zU
            A no argument method to be tested by L{usage.flagFunction}.
            Nr)rrrr�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)rrur|r�rrr�manyArgssz$FlagFunctionTests.SomeClass.manyArgsN)rrrr.r�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)rCrrDr�r�r�r)rS)r�excrrr�test_tooManyArguments�sz'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 flubudufN)rCrrDr�r�r�r)rS)rr�rrr�,test_tooManyArgumentsAndSpecificErrorMessage�sz>FlagFunctionTests.test_tooManyArgumentsAndSpecificErrorMessageN)
rrrr.�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.
                Nr)rrrr�opt_very_very_long�szNOptionsInternalTests.test_optionsAliasesOrder.<locals>.Opts.opt_very_very_longN)rrrr�Z	opt_shortZopt_srrrr�Opts�sr�r��shortzvery-very-long)r�r�zvery-very-longN)rrtr)�dict�fromkeysZsynonyms)rr�rrrr�test_optionsAliasesOrder�s
z-OptionsInternalTests.test_optionsAliasesOrderN)rrrr.r�rrrrr��sr�N)r.�
__future__rrZ
twisted.trialrZtwisted.pythonrrtrZTestCaser"r/r8rFrIrNrVrYr\r`rerr�r�r�r�r�rrrr�<module>s,+@$w#E