o
    ¯b[  ã                   @   sd  d Z ddlmZ ddlmZ G dd„ dejƒZG dd„ dejƒZG dd	„ d	ejƒZ	G d
d„ dejƒZ
G dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG d d!„ d!ejƒZG d"d#„ d#ejƒZG d$d%„ d%ejƒZG d&d'„ d'ejƒZd(S ))zK
Tests for L{twisted.python.usage}, a command line option parsing library.
é    )Úusage)Úunittestc                   @   sH   e Zd Zg d¢g d¢g d¢g d¢gZg d¢ddggZdd	„ Zd
d„ ZdS )ÚWellBehaved)ÚlongÚwÚdefaultzand a docstring)ÚanotherÚnzno docstring)ÚlongonlyNÚnoshort)Ú	shortlessNÚexceptzthis one got docstring)ÚaflagÚfzO

                 flagallicious docstringness for this here

                 ÚfloutÚoc                 C   s   d| j d< d S )NúPONY!Úmyflag©Úopts©Úself© r   ú9/usr/lib/python3/dist-packages/twisted/test/test_usage.pyÚ
opt_myflag!   s   zWellBehaved.opt_myflagc                 C   s   |› d�| j d< d S )Nz WITH A PONY!Úmyparamr   ©r   Úvaluer   r   r   Úopt_myparam$   s   zWellBehaved.opt_myparamN)Ú__name__Ú
__module__Ú__qualname__ÚoptParametersÚoptFlagsr   r   r   r   r   r   r      s    ü	ör   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚParseCorrectnessTestszZ
    Test L{usage.Options.parseOptions} for correct values under
    good conditions.
    c                 C   s$   d  ¡ | _tƒ | _| j | j¡ dS )zL
        Instantiate and parseOptions a well-behaved Options class.
        úA--long Alpha -n Beta --shortless Gamma -f --myflag --myparam TofuN)ÚsplitÚniceArgVr   ÚniceÚparseOptionsr   r   r   r   ÚsetUp.   s
   þzParseCorrectnessTests.setUpc                 C   sT   |   | jjd d¡ |   | jjd d¡ |   | jjd d¡ |   | jjd d¡ d	S )
z1
        Parameters have correct values.
        r   ÚAlphar   ÚBetar
   r   r   ÚGammaN©ÚassertEqualr(   r   r   r   r   r   Útest_checkParameters;   s   z*ParseCorrectnessTests.test_checkParametersc                 C   ó,   |   | jjd d¡ |   | jjd d¡ dS )z,
        Flags have correct values.
        r   é   r   r   Nr.   r   r   r   r   Útest_checkFlagsD   ó   z%ParseCorrectnessTests.test_checkFlagsc                 C   r1   )zB
        Custom flags and parameters have correct values.
        r   r   r   zTofu WITH A PONY!Nr.   r   r   r   r   Útest_checkCustomsK   r4   z'ParseCorrectnessTests.test_checkCustomsN)r   r    r!   Ú__doc__r*   r0   r3   r5   r   r   r   r   r$   (   s    	r$   c                   @   sL   e Zd Zddddegddddegdddd	egd
dddeggZdd„ ZeZdS )ÚTypedOptionsÚfoointNéˆ  zFoo intÚfoofloatçìQ¸…ë@z	Foo floatÚeggintzEgg int without defaultÚeggfloatzEgg float without defaultc                 C   s
   || _ dS )zg
        This option has an underscore in its name to exercise the _ to -
        translation.
        N)ÚunderscoreValuer   r   r   r   Úopt_under_score[   s   
zTypedOptions.opt_under_score)r   r    r!   ÚintÚfloatr"   r?   Úopt_ur   r   r   r   r7   S   s    ür7   c                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )Ú
TypedTestszK
    Test L{usage.Options.parseOptions} for options with forced types.
    c                 C   s   t ƒ | _d S ©N)r7   r   r   r   r   r   r*   j   s   zTypedTests.setUpc                 C   sˆ   g }| j  |¡ |  | j jd d¡ |  | j jd t¡ |  | j jd d¡ |  | j jd t¡ |  | j jd ¡ |  | j jd ¡ dS )z,
        Default values are parsed.
        r8   r9   r:   r;   r<   r=   N)r   r)   r/   r   ÚassertIsInstancer@   rA   ÚassertIsNone©r   ÚargVr   r   r   Útest_defaultValuesm   s   zTypedTests.test_defaultValuesc                 C   s¸   d  ¡ }| j |¡ |  | jjd d¡ |  | jjd t¡ |  | jjd d¡ |  | jjd t¡ |  | jjd d¡ |  | jjd t¡ |  | jjd d	¡ |  | jjd t¡ d
S )z2
        int and float values are parsed.
        z8--fooint 912 --foofloat -823.1 --eggint 32 --eggfloat 21r8   i�  r:   gÍÌÌÌÌ¸‰Àr<   é    r=   g      5@N)r&   r   r)   r/   r   rE   r@   rA   rG   r   r   r   Útest_parsingValuesz   s   zTypedTests.test_parsingValuesc                 C   ó$   | j  ddg¡ |  | j jd¡ dS )zw
        A dash in an option name is translated to an underscore before being
        dispatched to a handler.
        z--under-scoreÚfooN©r   r)   r/   r>   r   r   r   r   Útest_underscoreOption‰   s   z TypedTests.test_underscoreOptionc                 C   rL   )zE
        An option name with a dash in it can have an alias.
        z-uÚbarNrN   r   r   r   r   Útest_underscoreOptionAlias‘   s   z%TypedTests.test_underscoreOptionAliasc                 C   s    d  ¡ }|  tj| jj|¡ dS )z7
        Passing wrong values raises an error.
        z--fooint eggN)r&   ÚassertRaisesr   Ú
UsageErrorr)   rG   r   r   r   Útest_invalidValues˜   s   zTypedTests.test_invalidValuesN)
r   r    r!   r6   r*   rI   rK   rO   rQ   rT   r   r   r   r   rC   e   s    rC   c                   @   s   e Zd Zg d¢gZdS )ÚWrongTypedOptions)ÚbarwrongNNzBar with wrong coerceÚheN)r   r    r!   r"   r   r   r   r   rU       s    rU   c                   @   s8   e Zd Zdd„ Zdd„ Zddddegdddd	eggZdS )
ÚWeirdCallableOptionsc                 C   ó   t dƒ‚)NÚOuch)ÚRuntimeError©r   r   r   r   Ú_bar¥   ó   zWeirdCallableOptions._barc                 C   rY   )NÚYay)Ú
ValueErrorr\   r   r   r   Ú_foo¨   r^   zWeirdCallableOptions._foorV   NzBar with strange callableÚfoowrongzFoo with strange callable)r   r    r!   r]   ra   r"   r   r   r   r   rX   ¤   s    þrX   c                   @   ó(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚWrongTypedTestszF
    Test L{usage.Options.parseOptions} for wrong coerce options.
    c                 C   s"   t ƒ }d ¡ }|  t|j|¡ dS )z2
        Using a non-callable type fails.
        z--barwrong eggN)rU   r&   rR   Ú	TypeErrorr)   ©r   ÚusrH   r   r   r   Útest_nonCallable¶   s   z WrongTypedTests.test_nonCallablec                 C   s   t ƒ }g }| |¡ dS )zP
        The coerce functions are not called if no values are provided.
        N)rX   r)   rf   r   r   r   Útest_notCalledInDefault¾   s   z'WrongTypedTests.test_notCalledInDefaultc                 C   sR   t ƒ }d ¡ }|  tj|j|¡}|  t|ƒd¡ t ƒ }d ¡ }|  t|j|¡ dS )zI
        Errors raised by coerce functions are handled properly.
        z--foowrong blahz&Parameter type enforcement failed: Yayz--barwrong blahN)	rX   r&   rR   r   rS   r)   r/   Ústrr[   )r   rg   rH   Úer   r   r   Útest_weirdCallableÆ   s   z"WrongTypedTests.test_weirdCallableN)r   r    r!   r6   rh   ri   rl   r   r   r   r   rd   ±   s
    rd   c                   @   ó   e Zd Zdd„ ZdS )ÚOutputTestsc                 C   s.   t ƒ }|  tj|jdg¡}|  t|ƒd¡ dS )zF
        Error output case adjustment does not mangle options
        z-Zzoption -Z not recognizedN)r   rR   r   rS   r)   r/   rj   )r   Úoptrk   r   r   r   Útest_uppercasing×   s   zOutputTests.test_uppercasingN)r   r    r!   rp   r   r   r   r   rn   Ö   ó    rn   c                   @   s   e Zd ZdgZdgZdS )ÚInquisitionOptions)Úexpectrk   )útorture-deviceÚtúcomfy-chairzset preferred torture deviceN)r   r    r!   r#   r"   r   r   r   r   rr   à   s
    ÿÿrr   c                   @   s   e Zd ZddgZdS )ÚHolyQuestOptions)Ú	horsebackÚhzuse a horse)ú	for-grailÚgN)r   r    r!   r#   r   r   r   r   rw   é   s    þrw   c                   @   s*   e Zd ZdgZddedfddedfgZdS )	ÚSubCommandOptions)úeuropian-swallowNz$set default swallow type to EuropianÚinquisitionÚinquestzPerform an inquisitionÚ	holyquestÚquestzEmbark upon a holy questN)r   r    r!   r#   rr   rw   ÚsubCommandsr   r   r   r   r|   ð   s    ÿ

þr|   c                   @   sP   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚSubCommandTestszJ
    Test L{usage.Options.parseOptions} for options with subcommands.
    c                 C   sd   t ƒ }| ddg¡ |  |d ¡ |  |jd¡ |  |jt¡ |  |jd ¡ |  |jd d¡ dS )z-
        A subcommand is recognized.
        ú--europian-swallowr~   r}   rs   rt   rv   N)	r|   r)   Ú
assertTruer/   Ú
subCommandrE   Ú
subOptionsrr   ÚassertFalse©r   r   r   r   r   Útest_simpleSubcommandÿ   ó   z%SubCommandTests.test_simpleSubcommandc                 C   ód   t ƒ }| g d¢¡ |  |d ¡ |  |jd¡ |  |jt¡ |  |jd ¡ |  |jd d¡ dS )zA
        Flags and options of a subcommand are assigned.
        )r~   ú--expectú--torture-device=featherr}   r~   rs   rt   ÚfeatherN©	r|   r)   rˆ   r/   r†   rE   r‡   rr   r…   r‰   r   r   r   Ú"test_subcommandWithFlagsAndOptions  r‹   z2SubCommandTests.test_subcommandWithFlagsAndOptionsc                 C   rŒ   )zG
        Flags and options of a subcommand alias are assigned.
        )r   r�   rŽ   r}   r~   rs   rt   r�   Nr�   r‰   r   r   r   Ú'test_subcommandAliasWithFlagsAndOptions  r‹   z7SubCommandTests.test_subcommandAliasWithFlagsAndOptionsc                 C   sb   t ƒ }| ddg¡ |  |d ¡ |  |jd¡ |  |jt¡ |  |jd ¡ |  |jd ¡ dS )zG
        Flags and options of another subcommand are assigned.
        r€   z--for-grailr}   rx   rz   N)	r|   r)   rˆ   r/   r†   rE   r‡   rw   r…   r‰   r   r   r   Ú)test_anotherSubcommandWithFlagsAndOptions#  s   z9SubCommandTests.test_anotherSubcommandWithFlagsAndOptionsc                 C   s@   t ƒ }| dg¡ |  |d ¡ |  |j¡ |  t|dƒ¡ dS )z€
        If no subcommand is specified and no default subcommand is assigned,
        a subcommand will not be implied.
        r„   r}   r‡   N)r|   r)   r…   rF   r†   rˆ   Úhasattrr‰   r   r   r   Útest_noSubcommand/  s
   z!SubCommandTests.test_noSubcommandc                 C   sh   t ƒ }d|_| dg¡ |  |d ¡ |  |jd¡ |  |jt¡ |  	|jd ¡ |  |jd d¡ dS )	zK
        Flags and options in the default subcommand are assigned.
        r   r„   r}   r~   rs   rt   rv   N)
r|   ÚdefaultSubCommandr)   r…   r/   r†   rE   r‡   rr   rˆ   r‰   r   r   r   Útest_defaultSubcommand:  s   z&SubCommandTests.test_defaultSubcommandc                    s`   G dd„ dt jƒ‰ G ‡ fdd„dt jƒ}|ƒ }| dg¡ |  t|jdƒ¡ |  |jj|¡ dS )zw
        The parseOptions method from the Options object specified for the
        given subcommand is called.
        c                   @   rm   )zDSubCommandTests.test_subCommandParseOptionsHasParent.<locals>.SubOptc                 _   s&   | j | _tjj| g|¢R i |¤Ž d S rD   )ÚparentÚ	sawParentr   ÚOptionsr)   )r   ÚaÚkwr   r   r   r)   N  s   zQSubCommandTests.test_subCommandParseOptionsHasParent.<locals>.SubOpt.parseOptionsN)r   r    r!   r)   r   r   r   r   ÚSubOptM  rq   r�   c                       ó   e Zd Zdd” dfgZdS )zASubCommandTests.test_subCommandParseOptionsHasParent.<locals>.OptrM   r   rP   N©r   r    r!   r‚   r   ©r�   r   r   ÚOptR  ó    
ÿr¡   rM   r™   N)r   rš   r)   r…   r”   r‡   r/   r™   )r   r¡   r   r   r    r   Ú$test_subCommandParseOptionsHasParentG  s   z4SubCommandTests.test_subCommandParseOptionsHasParentc                    sª   G dd„ dt jƒ‰ G ‡ fdd„dt jƒ}G ‡ fdd„dt jƒ}|ƒ }| dg¡ |ƒ }| dg¡ |  t|jd	ƒ¡ |  t|jd	ƒ¡ |  |jj|¡ |  |jj|¡ d
S )zh
        The .parent pointer is correct even when the same Options class is
        used twice.
        c                   @   s   e Zd ZdS )z:SubCommandTests.test_subCommandInTwoPlaces.<locals>.SubOptN)r   r    r!   r   r   r   r   r�   b  s    r�   c                       rž   )z:SubCommandTests.test_subCommandInTwoPlaces.<locals>.OptFoorM   r   ÚquuxNrŸ   r   r    r   r   ÚOptFooe  r¢   r¥   c                       rž   )z:SubCommandTests.test_subCommandInTwoPlaces.<locals>.OptBarrP   Úbr¤   NrŸ   r   r    r   r   ÚOptBarj  r¢   r§   rM   rP   r˜   N)r   rš   r)   r…   r”   r‡   ÚfailUnlessIdenticalr˜   )r   r¥   r§   ÚoFooÚoBarr   r    r   Útest_subCommandInTwoPlaces\  s   z*SubCommandTests.test_subCommandInTwoPlacesN)r   r    r!   r6   rŠ   r‘   r’   r“   r•   r—   r£   r«   r   r   r   r   rƒ   ú   s    rƒ   c                   @   rc   )	ÚHelpStringTestsz&
    Test generated help strings.
    c                 C   s   d  ¡ | _tƒ | _dS )z;
        Instantiate a well-behaved Options class.
        r%   N)r&   r'   r   r(   r   r   r   r   r*   ~  s   þzHelpStringTests.setUpc              
   C   sB   z| j  ¡  W dS  ty  } z|  |¡ W Y d}~dS d}~ww )z,
        __str__ shouldn't go boom.
        N)r(   Ú__str__Ú	ExceptionÚfail)r   rk   r   r   r   Útest_noGoBoom‰  s   €ÿzHelpStringTests.test_noGoBoomc                 C   sF   dd„ t | jƒ ¡ D ƒ}|  t|ƒdk¡ |  |d  d¡dk¡ dS )zK
        Extra whitespace in flag and parameters docs is stripped.
        c                 S   s   g | ]}|  d ¡dkr|‘qS )r   r   )Úfind)Ú.0Úsr   r   r   Ú
<listcomp>˜  s    zJHelpStringTests.test_whitespaceStripFlagsAndParameters.<locals>.<listcomp>r   ÚflagalliciousN)rj   r(   Ú
splitlinesr…   Úlenr±   )r   Úlinesr   r   r   Ú&test_whitespaceStripFlagsAndParameters’  s   z6HelpStringTests.test_whitespaceStripFlagsAndParametersN)r   r    r!   r6   r*   r°   r¹   r   r   r   r   r¬   y  s
    	r¬   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚPortCoerceTestsz3
    Test the behavior of L{usage.portCoerce}.
    c                 C   s:   |   dt d¡¡ |   dt d¡¡ |   dt d¡¡ dS )z4
        Test the answers with valid input.
        r   Ú0iŠ  Ú3210iÿÿ  Ú65535N)r/   r   Ú
portCoercer   r   r   r   Útest_validCoerce¢  s   z PortCoerceTests.test_validCoercec                 C   sD   |   ttjd¡ |   ttjd¡ |   ttjd¡ |   ttjd¡ dS )z"
        Test error path.
        Ú z-21Ú212189rM   N)rR   r`   r   r¾   r   r   r   r   Útest_errorCoerceª  s   z PortCoerceTests.test_errorCoerceN)r   r    r!   r6   r¿   rÂ   r   r   r   r   rº   �  s    rº   c                   @   s`   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚZshCompleterTestsz‹
    Test the behavior of the various L{twisted.usage.Completer} classes
    for producing output usable by zsh tab-completion system.
    c                 C   óN   t  ¡ }| dt j¡}|  |d¡ t jddd�}| dt j¡}|  |d¡ dS )zX
        Completer produces zsh shell-code that produces no completion matches.
        úsome-optionz:some-option:úsome actionT©ÚdescrÚrepeatú*:some action:N)r   Ú	CompleterÚ
_shellCodeÚ_ZSHr/   ©r   ÚcÚgotr   r   r   Útest_completerº  ó   z ZshCompleterTests.test_completerc                 C   st   t  ¡ }| dt j¡}|  |d¡ t  d¡}| dt j¡}|  |d¡ t jdddd�}| dt j¡}|  |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Î   r   r   r   Ú
test_filesÆ  s   
zZshCompleterTests.test_filesc                 C   rÄ   )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Î   r   r   r   Ú	test_dirs×  rÒ   zZshCompleterTests.test_dirsc                 C   s~   t  d¡}| dt j¡}|  |d¡ t  g d¢¡}| dt j¡}|  |d¡ t jg d¢ddd�}| dt j¡}|  |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Î   r   r   r   Ú	test_listã  s   
zZshCompleterTests.test_listc                 C   s‚   t  d¡}| dt j¡}|  |d¡ t  g d¢¡}| dt j¡}|  |d¡ t jg d¢ddd�}| dt j¡}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Ø   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/   )r   rÏ   rÐ   Úexpectedr   r   r   Útest_multiListô  s   
z ZshCompleterTests.test_multiListc                 C   rÄ   )zd
        CompleteUsernames produces zsh shell-code that completes system
        usernames.
        rÅ   z:some-option:_usersrÆ   TrÇ   z*:some action:_usersN)r   ÚCompleteUsernamesrÌ   rÍ   r/   ©r   rÏ   Úoutr   r   r   Útest_usernames  ó   z ZshCompleterTests.test_usernamesc                 C   rÄ   )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â   r   r   r   Útest_groups  rå   zZshCompleterTests.test_groupsc                 C   rÄ   )zU
        CompleteHostnames produces zsh shell-code that completes hostnames.
        rÅ   z:some-option:_hostsrÆ   TrÇ   z*:some action:_hostsN)r   ÚCompleteHostnamesrÌ   rÍ   r/   râ   r   r   r   Útest_hostnames   rÒ   z ZshCompleterTests.test_hostnamesc                 C   sV   t  ¡ }| dt j¡}|  | d¡¡ t jddd�}| dt j¡}|  | d¡¡ dS )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Í   r…   Ú
startswithrâ   r   r   r   Útest_userAtHost,  s   z!ZshCompleterTests.test_userAtHostc                 C   rÄ   )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â   r   r   r   Útest_netInterfaces9  rå   z$ZshCompleterTests.test_netInterfacesN)r   r    r!   r6   rÑ   rÔ   rÖ   rÝ   rà   rä   rç   ré   rì   rî   r   r   r   r   rÃ   ´  s    rÃ   c                   @   ó   e Zd ZdZdd„ ZdS )ÚCompleterNotImplementedTestszs
    Using an unknown shell constant with the various Completer() classes
    should raise NotImplementedError
    c              
   C   sr   t jt jt jt jt jt jt jt jt j	t j
g
}|D ]}z|ƒ }W n ty,   |dƒ}Y nw |  t|jdd¡ qdS )zM
        Using an unknown shellType should raise NotImplementedError
        NÚbad_shell_type)r   rË   rÓ   rÕ   rÜ   rÞ   rá   ræ   rè   rê   rí   ÚBaseExceptionrR   ÚNotImplementedErrorrÌ   )r   ÚclassesÚclsÚactionr   r   r   Útest_unknownShellM  s*   ö
ÿ
ÿûz.CompleterNotImplementedTests.test_unknownShellN)r   r    r!   r6   r÷   r   r   r   r   rð   G  s    rð   c                   @   s>   e Zd ZdZG dd„ dƒZdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚFlagFunctionTestsz*
    Tests for L{usage.flagFunction}.
    c                   @   rc   )	zFlagFunctionTests.SomeClassz>
        Dummy class for L{usage.flagFunction} tests.
        c                 C   ó   dS )z¥
            A one argument method to be tested by L{usage.flagFunction}.

            @param a: a useless argument to satisfy the function's signature.
            Nr   )r   r›   r   r   r   ÚoneArgr  ó    z"FlagFunctionTests.SomeClass.oneArgc                 C   rù   )zU
            A no argument method to be tested by L{usage.flagFunction}.
            Nr   r   r   r   r   ÚnoArgy  rû   z!FlagFunctionTests.SomeClass.noArgc                 C   rù   )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   )r   r›   r¦   rÏ   r   r   r   ÚmanyArgs~  rû   z$FlagFunctionTests.SomeClass.manyArgsN)r   r    r!   r6   rú   rü   rý   r   r   r   r   Ú	SomeClassm  s
    rþ   c                 C   ó   |   dt |  ¡ j¡¡ dS )zs
        L{usage.flagFunction} returns C{False} if the method checked allows
        exactly one argument.
        FN)ÚassertIsr   ÚflagFunctionrþ   rú   r   r   r   r   Útest_hasArg‡  ó   zFlagFunctionTests.test_hasArgc                 C   rÿ   )zq
        L{usage.flagFunction} returns C{True} if the method checked allows
        exactly no argument.
        TN)r   r   r  rþ   rü   r   r   r   r   Ú
test_noArgŽ  r  zFlagFunctionTests.test_noArgc                 C   s,   |   tjtj|  ¡ j¡}|  dt|ƒ¡ dS )z
        L{usage.flagFunction} raises L{usage.UsageError} if the method checked
        allows more than one argument.
        z$Invalid Option function for manyArgsN©rR   r   rS   r  rþ   rý   r/   rj   ©r   Úexcr   r   r   Útest_tooManyArguments•  s   ÿz'FlagFunctionTests.test_tooManyArgumentsc                 C   s.   |   tjtj|  ¡ jd¡}|  dt|ƒ¡ dS )z‘
        L{usage.flagFunction} uses the given method name in the error message
        raised when the method allows too many arguments.
        Úflubudufz$Invalid Option function for flubudufNr  r  r   r   r   Ú,test_tooManyArgumentsAndSpecificErrorMessageŸ  s   ÿz>FlagFunctionTests.test_tooManyArgumentsAndSpecificErrorMessageN)	r   r    r!   r6   rþ   r  r  r  r
  r   r   r   r   rø   h  s    
rø   c                   @   rï   )ÚOptionsInternalTestsz6
    Tests internal behavior of C{usage.Options}.
    c                 C   sN   G dd„ dt jƒ}|ƒ }|  t g d¢d¡|jd |jd |jd dœ¡ dS )zs
        Options which are synonyms to another option are aliases towards the
        longest option name.
        c                   @   s   e Zd Zdd„ ZeZeZdS )z;OptionsInternalTests.test_optionsAliasesOrder.<locals>.Optsc                 S   rù   )z~
                This is an option method with a very long name, that is going to
                be aliased.
                Nr   r   r   r   r   Úopt_very_very_long¶  rû   zNOptionsInternalTests.test_optionsAliasesOrder.<locals>.Opts.opt_very_very_longN)r   r    r!   r  Ú	opt_shortÚopt_sr   r   r   r   ÚOptsµ  s    r  )r³   Úshortúvery-very-longr  r³   r  N)r   rš   r/   ÚdictÚfromkeysÚsynonyms)r   r  r   r   r   r   Útest_optionsAliasesOrder¯  s   
ýþz-OptionsInternalTests.test_optionsAliasesOrderN)r   r    r!   r6   r  r   r   r   r   r  ª  s    r  N)r6   Útwisted.pythonr   Útwisted.trialr   rš   r   ÚTestCaser$   r7   rC   rU   rX   rd   rn   rr   rw   r|   rƒ   r¬   rº   rÃ   rð   rø   r  r   r   r   r   Ú<module>   s,   +;%
	
$ !B