U
    ¹êW[]\  ã                   @   st  d Z ddlmZm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.
é    )ÚdivisionÚabsolute_import)Úunittest)Úusagec                   @   sV   e Zd Zddddgdddgdd	d
gdd	ddggZdddg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Ú	shortlessÚ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|f | j d< d S )Nz%s WITH A PONY!Úmyparamr   ©r   Úvaluer   r   r   Úopt_myparam"   s    zWellBehaved.opt_myparam)Ú__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   ZAlphar
   ZBetar   r   r   ZGammaN©ÚassertEqualr*   r   r   r   r   r   Útest_checkParameters9   s    z*ParseCorrectnessTests.test_checkParametersc                 C   s,   |   | jjd d¡ |   | jjd d¡ dS )z,
        Flags have correct values.
        r   é   r   r   Nr-   r   r   r   r   Útest_checkFlagsB   s    z%ParseCorrectnessTests.test_checkFlagsc                 C   s,   |   | jjd d¡ |   | jjd d¡ dS )zB
        Custom flags and parameters have correct values.
        r   r   r   zTofu WITH A PONY!Nr-   r   r   r   r   Útest_checkCustomsI   s    z'ParseCorrectnessTests.test_checkCustomsN)r!   r"   r#   Ú__doc__r,   r/   r1   r2   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_scoreZ   s    zTypedOptions.opt_under_score)r!   r"   r#   ÚintÚfloatr$   r<   Zopt_ur   r   r   r   r4   R   s   ür4   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)r4   r   r   r   r   r   r,   h   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.
        r5   r6   r7   r8   r9   r:   N)r   r+   r.   r   ÚassertIsInstancer=   r>   ÚassertIsNone©r   ÚargVr   r   r   Útest_defaultValuesk   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 21r5   i  r7   gÍÌÌÌÌ¸‰Àr9   é    r:   g      5@N)r(   r   r+   r.   r   rA   r=   r>   rC   r   r   r   Útest_parsingValuesy   s    zTypedTests.test_parsingValuesc                 C   s$   | 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   s$   | j  ddg¡ |  | j jd¡ dS )zE
        An option name with a dash in it can have an alias.
        z-uÚbarNrI   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+   rC   r   r   r   Útest_invalidValues›   s    zTypedTests.test_invalidValuesN)
r!   r"   r#   r3   r,   rE   rG   rJ   rL   rO   r   r   r   r   r?   d   s   	r?   c                   @   s   e Zd ZdddddggZdS )ÚWrongTypedOptionsÚbarwrongNzBar with wrong coerceZhe)r!   r"   r#   r$   r   r   r   r   rP   ¤   s   ÿrP   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   s   t dƒ‚d S )NZOuch)ÚRuntimeError©r   r   r   r   Ú_bar«   s    zWeirdCallableOptions._barc                 C   s   t dƒ‚d S )NZYay)Ú
ValueErrorrT   r   r   r   Ú_foo­   s    zWeirdCallableOptions._foorQ   NzBar with strange callableZfoowrongzFoo with strange callable)r!   r"   r#   rU   rW   r$   r   r   r   r   rR   ª   s
   þrR   c                   @   s(   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)rP   r(   rM   Ú	TypeErrorr+   ©r   ÚusrD   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)rR   r+   rZ   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)	rR   r(   rM   r   rN   r+   r.   ÚstrrS   )r   r[   rD   Úer   r   r   Útest_weirdCallableÉ   s    z"WrongTypedTests.test_weirdCallableN)r!   r"   r#   r3   r\   r]   r`   r   r   r   r   rX   µ   s   rX   c                   @   s   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   rM   r   rN   r+   r.   r^   )r   Zoptr_   r   r   r   Útest_uppercasingÚ   s     ÿzOutputTests.test_uppercasingN)r!   r"   r#   rb   r   r   r   r   ra   Ù   s   ra   c                   @   s   e Zd ZdgZdgZdS )ÚInquisitionOptions)Úexpectr_   )útorture-deviceÚtúcomfy-chairzset preferred torture deviceN)r!   r"   r#   r%   r$   r   r   r   r   rc   ä   s   ÿÿrc   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   rh   ï   s   þrh   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Ú	holyquestZquestzEmbark upon a holy questN)r!   r"   r#   r%   rc   rh   ÚsubCommandsr   r   r   r   rm   ö   s   ÿÿýrm   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-swallowro   rn   rd   re   rg   N)	rm   r+   Ú
assertTruer.   Ú
subCommandrA   Ú
subOptionsrc   ÚassertFalse©r   r   r   r   r   Útest_simpleSubcommand  s    z%SubCommandTests.test_simpleSubcommandc                 C   sf   t ƒ }| dddg¡ |  |d ¡ |  |jd¡ |  |jt¡ |  |jd ¡ |  |jd d¡ dS )	zA
        Flags and options of a subcommand are assigned.
        ro   ú--expectú--torture-device=featherrn   rd   re   ÚfeatherN©	rm   r+   rx   r.   rv   rA   rw   rc   ru   ry   r   r   r   Ú"test_subcommandWithFlagsAndOptions  s    z2SubCommandTests.test_subcommandWithFlagsAndOptionsc                 C   sf   t ƒ }| dddg¡ |  |d ¡ |  |jd¡ |  |jt¡ |  |jd ¡ |  |jd d¡ d	S )
zG
        Flags and options of a subcommand alias are assigned.
        rp   r{   r|   rn   ro   rd   re   r}   Nr~   ry   r   r   r   Ú'test_subcommandAliasWithFlagsAndOptions  s    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.
        rq   z--for-grailrn   ri   rk   N)	rm   r+   rx   r.   rv   rA   rw   rh   ru   ry   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.
        rt   rn   rw   N)rm   r+   ru   rB   rv   rx   Úhasattrry   r   r   r   Útest_noSubcommand6  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.
        rp   rt   rn   ro   rd   re   rg   N)
rm   ZdefaultSubCommandr+   ru   r.   rv   rA   rw   rc   rx   ry   r   r   r   Útest_defaultSubcommandA  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                   @   s   e Zd Zdd„ ZdS )zDSubCommandTests.test_subCommandParseOptionsHasParent.<locals>.SubOptc                 _   s    | j | _tjj| f|ž|Ž d S r@   )ÚparentÚ	sawParentr   ÚOptionsr+   )r   ÚaÚkwr   r   r   r+   T  s    zQSubCommandTests.test_subCommandParseOptionsHasParent.<locals>.SubOpt.parseOptionsN)r!   r"   r#   r+   r   r   r   r   ÚSubOptS  s   rŠ   c                       s   e Zd Zdd” dfgZdS )zASubCommandTests.test_subCommandParseOptionsHasParent.<locals>.OptrH   r   rK   N©r!   r"   r#   rr   r   ©rŠ   r   r   ÚOptW  s   
ÿr   rH   r†   N)r   r‡   r+   ru   r‚   rw   r.   r†   )r   r   r   r   rŒ   r   Ú$test_subCommandParseOptionsHasParentN  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Š   e  s   rŠ   c                       s   e Zd Zdd” dfgZdS )z:SubCommandTests.test_subCommandInTwoPlaces.<locals>.OptFoorH   r   ÚquuxNr‹   r   rŒ   r   r   ÚOptFoog  s   
ÿr   c                       s   e Zd Zdd” dfgZdS )z:SubCommandTests.test_subCommandInTwoPlaces.<locals>.OptBarrK   Úbr   Nr‹   r   rŒ   r   r   ÚOptBark  s   
ÿr’   rH   rK   r…   N)r   r‡   r+   ru   r‚   rw   ZfailUnlessIdenticalr…   )r   r   r’   ZoFooZoBarr   rŒ   r   Útest_subCommandInTwoPlaces`  s    z*SubCommandTests.test_subCommandInTwoPlacesN)r!   r"   r#   r3   rz   r   r€   r   rƒ   r„   rŽ   r“   r   r   r   r   rs     s   rs   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú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   s@   z| j  ¡  W n, tk
r: } z|  |¡ W 5 d}~X Y nX dS )z,
        __str__ shouldn't go boom.
        N)r*   Ú__str__Ú	ExceptionZfail)r   r_   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   ZflagalliciousN)r^   r*   Ú
splitlinesru   Úlenr˜   )r   Úlinesr   r   r   Ú&test_whitespaceStripFlagsAndParameters‘  s    z6HelpStringTests.test_whitespaceStripFlagsAndParametersN)r!   r"   r#   r3   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Š  Z3210iÿÿ  Z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-21Z212189rH   N)rM   rV   r   r¢   r   r   r   r   Útest_errorCoerce¨  s    z PortCoerceTests.test_errorCoerceN)r!   r"   r#   r3   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   sN   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©ZdescrÚrepeatú*:some action:N)r   Ú	CompleterÚ
_shellCodeÚ_ZSHr.   ©r   ÚcÚgotr   r   r   Útest_completer¸  s    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   sN   t  ¡ }| dt j¡}|  |d¡ t jddd}| dt j¡}|  |d¡ dS )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×  s    zZshCompleterTests.test_dirsc                 C   s‚   t  d¡}| dt j¡}|  |d¡ t  dddg¡}| dt j¡}|  |d¡ t jdddg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  dddg¡}| dt j¡}|  |d¡ t jdddg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¸   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.   )r   r°   r±   Zexpectedr   r   r   Útest_multiList÷  s    
ÿz ZshCompleterTests.test_multiListc                 C   sN   t  ¡ }| dt j¡}|  |d¡ t jddd}| dt j¡}|  |d¡ dS )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  s    z ZshCompleterTests.test_usernamesc                 C   sN   t  ¡ }| dt j¡}|  |d¡ t jddd}| dt j¡}|  |d¡ dS )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  s    zZshCompleterTests.test_groupsc                 C   sN   t  ¡ }| dt j¡}|  |d¡ t jddd}| dt j¡}|  |d¡ dS )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'  s    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®   ru   Ú
startswithrÀ   r   r   r   Útest_userAtHost4  s    z!ZshCompleterTests.test_userAtHostc                 C   sN   t  ¡ }| dt j¡}|  |d¡ t jddd}| dt j¡}|  |d¡ dS )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_netInterfacesB  s    z$ZshCompleterTests.test_netInterfacesN)r!   r"   r#   r3   r²   r´   r¶   r¼   r¾   rÂ   rÄ   rÆ   rÉ   rË   r   r   r   r   r¦   ³  s   r¦   c                   @   s   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   sl   t jt jt jt jt jt jt jt jt j	t j
g
}|D ]6}z
|ƒ }W n   |dƒ}Y nX |  t|jdd¡ q0dS )zM
        Using an unknown shellType should raise NotImplementedError
        NZbad_shell_type)r   r¬   r³   rµ   r»   r½   r¿   rÃ   rÅ   rÇ   rÊ   rM   ÚNotImplementedErrorr­   )r   ÚclassesÚclsÚactionr   r   r   Útest_unknownShellV  s&        ü

 ÿz.CompleterNotImplementedTests.test_unknownShellN)r!   r"   r#   r3   rÑ   r   r   r   r   rÌ   Q  s   rÌ   c                   @   s@   e Zd ZdZG dd„ deƒZdd„ Zdd„ Zdd	„ Zd
d„ Z	dS )ÚFlagFunctionTestsz*
    Tests for L{usage.flagFunction}.
    c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	zFlagFunctionTests.SomeClassz>
        Dummy class for L{usage.flagFunction} tests.
        c                 C   s   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   ÚoneArgs  s    z"FlagFunctionTests.SomeClass.oneArgc                 C   s   dS )zU
            A no argument method to be tested by L{usage.flagFunction}.
            Nr   r   r   r   r   ÚnoArgz  s    z!FlagFunctionTests.SomeClass.noArgc                 C   s   dS )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  s    z$FlagFunctionTests.SomeClass.manyArgsN)r!   r"   r#   r3   rÓ   rÔ   rÕ   r   r   r   r   Ú	SomeClasso  s   rÖ   c                 C   s   |   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‰  s    zFlagFunctionTests.test_hasArgc                 C   s   |   dt |  ¡ j¡¡ dS )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‘  s    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©rM   r   rN   rØ   rÖ   rÕ   r.   r^   ©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.
        Zflubudufz$Invalid Option function for flubudufNrÛ   rÜ   r   r   r   Ú,test_tooManyArgumentsAndSpecificErrorMessage£  s      þz>FlagFunctionTests.test_tooManyArgumentsAndSpecificErrorMessageN)
r!   r"   r#   r3   ÚobjectrÖ   rÙ   rÚ   rÞ   rß   r   r   r   r   rÒ   j  s   
rÒ   c                   @   s   e Zd ZdZdd„ ZdS )ÚOptionsInternalTestsz6
    Tests internal behavior of C{usage.Options}.
    c                 C   sP   G dd„ dt jƒ}|ƒ }|  t dddg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   s   dS )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º  s    zNOptionsInternalTests.test_optionsAliasesOrder.<locals>.Opts.opt_very_very_longN)r!   r"   r#   râ   Z	opt_shortZopt_sr   r   r   r   ÚOpts¹  s   rã   rš   Úshortúvery-very-long)rš   rä   rå   N)r   r‡   r.   ÚdictÚfromkeysZsynonyms)r   rã   r   r   r   r   Útest_optionsAliasesOrder´  s    
 ÿýþz-OptionsInternalTests.test_optionsAliasesOrderN)r!   r"   r#   r3   rè   r   r   r   r   rá   ¯  s   rá   N)r3   Z
__future__r   r   Ztwisted.trialr   Ztwisted.pythonr   r‡   r   ZTestCaser&   r4   r?   rP   rR   rX   ra   rc   rh   rm   rs   r”   r    r¦   rÌ   rÒ   rá   r   r   r   r   Ú<module>   s,   +@$w# E