B
    u9aúó  ã               @   s  d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	Z	d dl	m
Z
mZmZmZmZmZmZmZmZmZmZ d dl	mZ d dl	mZ G dd„ deƒZG d	d
„ d
eƒZG dd„ dejƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdddddœZ dd„ Z!G dd„ deƒZ"G dd„ deƒZ#G d d!„ d!eƒZ$G d"d#„ d#eƒZ%G d$d%„ d%eƒZ&G d&d'„ d'eƒZ'G d(d)„ d)eƒZ(G d*d+„ d+eƒZ)G d,d-„ d-eƒZ*G d.d/„ d/eƒZ+G d0d1„ d1eƒZ,G d2d3„ d3eƒZ-G d4d5„ d5eƒZ.G d6d7„ d7eƒZ/G d8d9„ d9eƒZ0G d:d;„ d;eƒZ1G d<d=„ d=eƒZ2G d>d?„ d?eƒZ3G d@dA„ dAeƒZ4G dBdC„ dCeƒZ5G dDdE„ dEeƒZ6G dFdG„ dGeƒZ7G dHdI„ dIe7ƒZ8G dJdK„ dKe7ƒZ9G dLdM„ dMeƒZ:dNZ;dOZ<dPZ=dQZ>dRZ?G dSdT„ dTeƒZ@G dUdV„ dVeƒZAG dWdX„ dXeƒZBG dYdZ„ dZejƒZCd[d\„ ZDeEd]kreDƒ  dS )^é    N)ÚStringIO)Úsupport)Úmake_optionÚOptionÚTitledHelpFormatterÚOptionParserÚOptionGroupÚSUPPRESS_USAGEÚOptionErrorÚOptionConflictErrorÚBadOptionErrorÚOptionValueErrorÚValues)Ú_match_abbrev)Ú
_parse_numc               @   s   e Zd Zddd„Zdd„ ZdS )ÚInterceptedErrorNc             C   s   || _ || _|| _d S )N)Úerror_messageÚexit_statusÚexit_message)Úselfr   r   r   © r   ú#/usr/lib/python3.7/test_optparse.pyÚ__init__   s    zInterceptedError.__init__c             C   s   | j p| jpdS )Nzintercepted error)r   r   )r   r   r   r   Ú__str__$   s    zInterceptedError.__str__)NNN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s     
r   c               @   s   e Zd Zddd„Zdd„ ZdS )ÚInterceptingOptionParserr   Nc             C   s   t ||d‚d S )N)r   r   )r   )r   ÚstatusÚmsgr   r   r   Úexit(   s    zInterceptingOptionParser.exitc             C   s   t |d‚d S )N)r   )r   )r   r   r   r   r   Úerror+   s    zInterceptingOptionParser.error)r   N)r   r   r   r    r!   r   r   r   r   r   '   s   
r   c               @   s>   e Zd Zdd„ Zdd„ Zdd„ Zdd	d
„Zdd„ Zdd„ ZdS )ÚBaseTestc             C   sH   | j  |¡\}}t|ƒ}|  ||dtƒ  ¡ |  ||dtƒ  ¡ ||fS )aš  Assert 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_argsÚvarsÚassertEqualÚlocals)r   ÚargsZexpected_optsZexpected_positional_argsÚoptionsZpositional_argsZoptdictr   r   r   ÚassertParseOK0   s    zBaseTest.assertParseOKc          
   C   s¦   |dkrd}|dkri }y|||Ž W nj |k
r } zLt |ƒ}t|tjƒrj|  | |¡d|j|f ¡ n|  ||d||f ¡ |S d}~X Y nX |  dt	ƒ  ¡ dS )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.
        Nr   zLexpected 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Ú
isinstanceÚreÚPatternÚ
assertTrueÚsearchÚpatternr&   Úfailr'   )r   Úfuncr(   ÚkwargsZexpected_exceptionÚexpected_messageÚerrZactual_messager   r   r   ÚassertRaisesN   s"    zBaseTest.assertRaisesc          
   C   sP   y| j  |¡ W n0 tk
r@ } z|  |j|¡ W dd}~X Y nX |  d¡ dS )z‘
        Assert the parser fails with the expected message.  Caller
        must ensure that self.parser is an InterceptingOptionParser.
        Nzexpected parse failure)r#   r$   r   r&   r   ÚassertFalse)r   Úcmdline_argsÚexpected_outputr6   r   r   r   ÚassertParseFail‰   s
     zBaseTest.assertParseFailr   Nc          
   C   sÀ   t j}y0ztƒ t _| j |¡ W dt j ¡ }|t _X W nz tk
r° } z\|  t|t	ƒdt
|ƒ ¡ ||kr„|  d| d | d ¡ |  |j|¡ |  |j|¡ W dd}~X Y nX |  d¡ dS )z7Assert the parser prints the expected output on stdout.Nz0expected output to be an ordinary string, not %rzexpected: 
'''
z'''
but got 
'''
z'''zexpected parser.exit())ÚsysÚstdoutr   r#   r$   Úgetvaluer   r/   r,   r+   Útyper2   r&   r   r   r8   )r   r9   r:   Zexpected_statusZexpected_errorZsave_stdoutÚoutputr6   r   r   r   ÚassertOutput•   s$    
 zBaseTest.assertOutputc             G   s   |   ||dt|¡ dS )z4Assert that TypeError is raised when executing func.N)r7   Ú	TypeError)r   r3   r5   r(   r   r   r   ÚassertTypeError²   s    zBaseTest.assertTypeErrorc             C   s.   |  ¡ }||kr*|  d| d | d ¡‚d S )Nzhelp text failure; expected:
"z	"; got:
"z"
)Úformat_helpZfailureException)r   r#   Úexpected_helpZactual_helpr   r   r   Ú
assertHelp¶   s    zBaseTest.assertHelp)r   N)	r   r   r   r*   r7   r;   rA   rC   rF   r   r   r   r   r"   /   s   ; 
r"   c               @   sÊ   e Zd Zdd„ Zg i f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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-d.„ Zd/S )0ÚTestOptionChecksc             C   s   t td| _d S )N)Úusage)r   r	   r#   )r   r   r   r   ÚsetUpÅ   s    zTestOptionChecks.setUpc             C   s   |   t||t|¡ d S )N)r7   r   r
   )r   r5   r(   r4   r   r   r   ÚassertOptionErrorÈ   s    
z"TestOptionChecks.assertOptionErrorc             C   s   |   td¡ d S )Nz+at least one option string must be supplied)rC   r   )r   r   r   r   Útest_opt_string_emptyÌ   s    z&TestOptionChecks.test_opt_string_emptyc             C   s   |   ddg¡ d S )Nz?invalid option string 'b': must be at least two characters longÚb)rJ   )r   r   r   r   Útest_opt_string_too_shortÐ   s    z*TestOptionChecks.test_opt_string_too_shortc             C   s   |   ddg¡ d S )NzOinvalid short option string '--': must be of the form -x, (x any non-dash char)z--)rJ   )r   r   r   r   Útest_opt_string_short_invalidÕ   s    z.TestOptionChecks.test_opt_string_short_invalidc             C   s   |   ddg¡ d S )NzJinvalid long option string '---': must start with --, followed by non-dashz---)rJ   )r   r   r   r   Útest_opt_string_long_invalidÛ   s    z-TestOptionChecks.test_opt_string_long_invalidc             C   s   |   ddgd d dœ¡ d S )Nz.option -b: invalid keyword arguments: bar, fooz-b)ÚfooÚbar)rJ   )r   r   r   r   Útest_attr_invalidá   s    z"TestOptionChecks.test_attr_invalidc             C   s   |   ddgddi¡ d S )Nz option -b: invalid action: 'foo'z-bÚactionrP   )rJ   )r   r   r   r   Útest_action_invalidæ   s    z$TestOptionChecks.test_action_invalidc             C   s,   |   ddgddi¡ |   ddgdti¡ d S )Nz%option -b: invalid option type: 'foo'z-br?   rP   z'option -b: invalid option type: 'tuple')rJ   Útuple)r   r   r   r   Útest_type_invalidë   s    z"TestOptionChecks.test_type_invalidc             C   s   |   ddgdddœ¡ d S )Nz4option -b: must not supply a type for action 'count'z-bÚcountÚint)rS   r?   )rJ   )r   r   r   r   Útest_no_type_for_actionó   s    z(TestOptionChecks.test_no_type_for_actionc             C   s   |   dddgddi¡ d S )Nz@option -b/--bad: must supply a list of choices for type 'choice'z-bz--badr?   Úchoice)rJ   )r   r   r   r   Útest_no_choices_listø   s    z%TestOptionChecks.test_no_choices_listc             C   s*   t dƒj}|  d| ddgdddœ¡ d S )NÚ zBoption -b/--bad: choices must be a list of strings ('%s' supplied)z-bz--badrZ   zbad choices)r?   Úchoices)r?   r   rJ   )r   Útypenamer   r   r   Útest_bad_choices_listþ   s    
z&TestOptionChecks.test_bad_choices_listc             C   s   |   ddgdddœ¡ d S )Nz1option -b: must not supply choices for type 'int'z-brX   Zbad)r?   r]   )rJ   )r   r   r   r   Útest_no_choices_for_type  s    z)TestOptionChecks.test_no_choices_for_typec             C   s   |   ddgdddœ¡ d S )Nz:option -b: 'const' must not be supplied for action 'store'z-bÚstoreé   )rS   Úconst)rJ   )r   r   r   r   Útest_no_const_for_action  s    z)TestOptionChecks.test_no_const_for_actionc             C   s   |   ddgdddœ¡ d S )Nz:option -b: 'nargs' must not be supplied for action 'count'z-brW   é   )rS   Únargs)rJ   )r   r   r   r   Útest_no_nargs_for_action  s    z)TestOptionChecks.test_no_nargs_for_actionc             C   s   |   ddgdddœ¡ d S )Nz'option -b: callback not callable: 'foo'z-bÚcallbackrP   )rS   rh   )rJ   )r   r   r   r   Útest_callback_not_callable  s    z+TestOptionChecks.test_callback_not_callablec             C   s   d S )Nr   )r   r   r   r   Údummy  s    zTestOptionChecks.dummyc             C   s   |   ddgd| jddœ¡ d S )NzAoption -b: callback_args, if supplied, must be a tuple: not 'foo'z-brh   rP   )rS   rh   Úcallback_args)rJ   rj   )r   r   r   r   Útest_callback_args_no_tuple  s
    z,TestOptionChecks.test_callback_args_no_tuplec             C   s   |   ddgd| jddœ¡ d S )NzBoption -b: callback_kwargs, if supplied, must be a dict: not 'foo'z-brh   rP   )rS   rh   Úcallback_kwargs)rJ   rj   )r   r   r   r   Útest_callback_kwargs_no_dict&  s
    z-TestOptionChecks.test_callback_kwargs_no_dictc             C   s   |   ddgdddœ¡ d S )Nz<option -b: callback supplied ('foo') for non-callback optionz-bra   rP   )rS   rh   )rJ   )r   r   r   r   Útest_no_callback_for_action.  s    z,TestOptionChecks.test_no_callback_for_actionc             C   s   |   ddgdddœ¡ d S )Nz9option -b: callback_args supplied for non-callback optionz-bra   rP   )rS   rk   )rJ   )r   r   r   r   Ú test_no_callback_args_for_action4  s    z1TestOptionChecks.test_no_callback_args_for_actionc             C   s   |   ddgdddœ¡ d S )Nz;option -b: callback_kwargs supplied for non-callback optionz-bra   rP   )rS   rm   )rJ   )r   r   r   r   Ú"test_no_callback_kwargs_for_action:  s    z3TestOptionChecks.test_no_callback_kwargs_for_actionc             C   s2   |   ddg¡ |   dddg¡ |   dddg¡ d S )NzMinvalid long option string '-debug': must start with --, followed by non-dashz-debugzXoption -d: invalid long option string '-debug': must start with --, followed by non-dashz-dz--debug)rJ   )r   r   r   r   Útest_no_single_dash@  s    
z$TestOptionChecks.test_no_single_dashN)r   r   r   rI   rJ   rK   rM   rN   rO   rR   rT   rV   rY   r[   r_   r`   rd   rg   ri   rj   rl   rn   ro   rp   rq   rr   r   r   r   r   rG   Ä   s.   rG   c               @   sr   e 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ejddddd„ ƒZdS )ÚTestOptionParserc             C   s:   t ƒ | _| jjddddddd | jjdd	d
ddd d S )Nz-vz	--verbosez-nz--noisyÚ
store_trueÚverbose)rS   Údestz-qz--quietz--silentÚstore_false)r   r#   Ú
add_option)r   r   r   r   rI   Q  s
    
zTestOptionParser.setUpc             C   s   |   | jjdd ¡ d S )Nznot an Option instance: None)rC   r#   rx   )r   r   r   r   Útest_add_option_no_OptionX  s    
z*TestOptionParser.test_add_option_no_Optionc             C   s   |   | jjdd d ¡ d S )Nzinvalid arguments)rC   r#   rx   )r   r   r   r   Ú!test_add_option_invalid_arguments\  s    
z2TestOptionParser.test_add_option_invalid_argumentsc             C   s\   | j  d¡}|  |t¡ |  |jddg¡ |  |jddg¡ |  |jd¡ |  |jd¡ d S )Nz-vz-nz	--verbosez--noisyrt   ru   )	r#   Ú
get_optionZassertIsInstancer   r&   Ú_short_optsÚ
_long_optsrS   rv   )r   Úopt1r   r   r   Útest_get_option`  s    z TestOptionParser.test_get_optionc             C   s\   | j  d¡}| j  d¡}| j  d¡}| j  d¡}|  ||  koP|  koP|kn  ¡ d S )Nz-vz	--verbosez-nz--noisy)r#   r{   r/   )r   r~   Zopt2Zopt3Zopt4r   r   r   Útest_get_option_equalsh  s
    z'TestOptionParser.test_get_option_equalsc             C   s(   |   | j d¡¡ |   | j d¡¡ d S )Nz-vz	--verbose)r/   r#   Ú
has_option)r   r   r   r   Útest_has_optiono  s    z TestOptionParser.test_has_optionc             C   sÈ   |   | j d¡d k¡ |   | j d¡d k¡ |   | j d¡d k¡ |   | j d¡d k¡ |  | j d¡¡ |  | j d¡¡ |  | j d¡¡ |  | j d¡¡ |   | j d¡¡ |   | j d¡¡ d S )Nz-vz	--verbosez-nz--noisyz-qz--silent)r/   r#   r{   r8   r   )r   r   r   r   ÚassertTrueremoveds  s    z"TestOptionParser.assertTrueremovedc             C   s   | j  d¡ |  ¡  d S )Nz-n)r#   Úremove_optionrƒ   )r   r   r   r   Útest_remove_short_opt  s    z&TestOptionParser.test_remove_short_optc             C   s   | j  d¡ |  ¡  d S )Nz	--verbose)r#   r„   rƒ   )r   r   r   r   Útest_remove_long_opt…  s    z%TestOptionParser.test_remove_long_optc             C   s   |   | jjdd td¡ d S )N)rP   zno such option 'foo')r7   r#   r„   Ú
ValueError)r   r   r   r   Útest_remove_nonexistent‰  s    z(TestOptionParser.test_remove_nonexistentzRelies on sys.getrefcountT)Zcpythonc             C   sH   dg}t  |¡}tƒ }| dd¡ ||_| ¡  ~|  |t  |¡¡ d S )Né*   z-az	--aaarggh)r<   Úgetrefcountr   rx   Ú	big_thingZdestroyr&   )r   r‹   Zrefcountr#   r   r   r   Útest_refleak  s    
zTestOptionParser.test_refleakN)r   r   r   rI   ry   rz   r   r€   r‚   rƒ   r…   r†   rˆ   r   Zimpl_detailrŒ   r   r   r   r   rs   P  s   rs   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚTestOptionValuesc             C   s   d S )Nr   )r   r   r   r   rI      s    zTestOptionValues.setUpc             C   s¦   t ƒ }|  t|ƒi ¡ |  |i ¡ |  |ddi¡ |  |d¡ dddœ}t |d}|  t|ƒ|¡ |  ||¡ |  |ddi¡ |  |i ¡ |  |d¡ |  |g ¡ d S )NrP   rQ   r\   r‰   )rP   Úbaz)Údefaults)r   r&   r%   ZassertNotEqual)r   ÚvaluesÚdictr   r   r   Útest_basics£  s    

zTestOptionValues.test_basicsN)r   r   r   rI   r’   r   r   r   r   r   Ÿ  s   r   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestTypeAliasesc             C   s   t ƒ | _d S )N)r   r#   )r   r   r   r   rI   µ  s    zTestTypeAliases.setUpc             C   s*   | j jddd |  | j  d¡jd¡ d S )Nz-sr+   )r?   Ústring)r#   rx   r&   r{   r?   )r   r   r   r   Útest_str_aliases_string¸  s    z'TestTypeAliases.test_str_aliases_stringc             C   sP   | j jdtd |  | j  d¡jd¡ | j jdtd |  | j  d¡jd¡ d S )Nz-s)r?   r”   z-xrX   )r#   rx   r+   r&   r{   r?   rX   )r   r   r   r   Útest_type_object¼  s    z TestTypeAliases.test_type_objectN)r   r   r   rI   r•   r–   r   r   r   r   r“   ´  s   r“   rb   é<   i  i€Q )ÚsÚmÚhÚdc          	   C   sb   y4|d   ¡ rt|ƒS t|d d… ƒt|d   S W n( ttfk
r\   td||f ƒ‚Y nX d S )Néÿÿÿÿzoption %s: invalid duration: %r)ÚisdigitrX   Ú_time_unitsr‡   Ú
IndexErrorr   )ÚoptionÚoptÚvaluer   r   r   Ú_check_durationÆ  s     r£   c               @   s*   e Zd Zejd Ze ej¡Zeed< dS )ÚDurationOption)Údurationr¥   N)r   r   r   r   ÚTYPESÚcopyÚTYPE_CHECKERr£   r   r   r   r   r¤   Ð  s   
r¤   c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestDefaultValuesc             C   s’   t ƒ | _| jjdddd | jjdddd | jjd	d
dd | jjdd
d | jjddd | j d¡ | jjdd d ddd dd d dœ| _d S )Nz-vz	--verboseT)Údefaultz-qz--quietru   )rv   z-nrX   é%   )r?   rª   z-m)r?   z-srP   z-tz-u)ru   Únr™   r˜   ÚtÚu)r   r#   rx   Úexpected)r   r   r   r   rI   Ö  s    zTestDefaultValues.setUpc             C   s   |   | j ¡ | j¡ d S )N)r&   r#   Úget_default_valuesr¯   )r   r   r   r   Útest_basic_defaultsæ  s    z%TestDefaultValues.test_basic_defaultsc             C   s:   | j jddd | j dddœ¡ |  | j  ¡ | j¡ d S )Nr‰   iœÿÿÿ)r¬   r™   )r#   Úset_defaultsr¯   Úupdater&   r°   )r   r   r   r   Útest_mixed_defaults_posté  s    z*TestDefaultValues.test_mixed_defaults_postc             C   s–   | j jddd | j jddd | j  d¡ | j dddœ¡ |  | j  ¡ | j¡ | j  d¡ | j jdd d | j dd i¡ |  | j  ¡ | j¡ d S )	NZbarfÚblah)ÚxÚyz-xZfrob)rª   z-yr·   )r#   r²   rx   r¯   r³   r&   r°   r„   )r   r   r   r   Útest_mixed_defaults_preî  s    z)TestDefaultValues.test_mixed_defaults_prec             C   sš   t | j_| jjdddd | jjdddd | jjdd | j dd	d
dœ¡ |  | j ¡ | j¡ | j 	d¡ | j ddddœ¡ |  | j ¡ | j¡ d S )Nz-dr¥   i,  )r?   rª   z-eZ6mÚ42)r¬   ih  r‰   )r›   Úer¬   F)
r¤   r#   Úoption_classrx   r²   r¯   r³   r&   r°   Zset_process_default_values)r   r   r   r   Útest_process_defaultû  s    z&TestDefaultValues.test_process_defaultN)r   r   r   rI   r±   r´   r¸   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 )ÚTestProgNamez]
    Test that %prog expands to the right thing in usage, version,
    and help strings.
    c             C   s   |   | ¡ |¡ d S )N)r&   Z	get_usage)r   r#   Úexpected_usager   r   r   ÚassertUsage  s    zTestProgName.assertUsagec             C   s   |   | ¡ |¡ d S )N)r&   Zget_version)r   r#   Zexpected_versionr   r   r   ÚassertVersion  s    zTestProgName.assertVersionc          
   C   sz   t jd d … }zVtj ddd¡t jd< tddd}d}|  ||¡ |  |d	¡ |  ||d
 d ¡ W d |t jd d …< X d S )NrP   rQ   zbaz.pyr   z	%prog ...z	%prog 1.2)ÚversionzUsage: baz.py ...
z
baz.py 1.2Ú
zlOptions:
  --version   show program's version number and exit
  -h, --help  show this help message and exit
)	r<   ÚargvÚosÚpathÚjoinr   r¿   rÀ   rF   )r   Ú	save_argvr#   r¾   r   r   r   Útest_default_progname  s    z"TestProgName.test_default_prognamec             C   sR   t dddd}| d¡ | d¡ d}|  ||¡ |  |d¡ |  ||d	 ¡ d S )
NZthingyz	%prog 0.1z%prog arg arg)ÚprogrÁ   rH   z-hz	--versionzUsage: thingy arg arg
z
thingy 0.1rÂ   )r   r„   r¿   rÀ   rF   )r   r#   r¾   r   r   r   Útest_custom_progname&  s    

z!TestProgName.test_custom_prognameN)r   r   r   Ú__doc__r¿   rÀ   rÈ   rÊ   r   r   r   r   r½     s
   r½   c               @   s\   e 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 )ÚTestExpandDefaultsc             C   s4   t dd| _d| _d| _| jd | _| jd | _d S )NÚtest)rÉ   zXUsage: test [options]

Options:
  -h, --help            show this help message and exit
z"read from FILE [default: %default]z:  -f FILE, --file=FILE  read from FILE [default: foo.txt]
z7  -f FILE, --file=FILE  read from FILE [default: none]
)r   r#   Úhelp_prefixÚ	file_helpÚexpected_help_fileÚexpected_help_none)r   r   r   r   rI   3  s    zTestExpandDefaults.setUpc             C   s*   | j jddd| jd |  | j | j¡ d S )Nz-fz--filezfoo.txt)rª   Úhelp)r#   rx   rÏ   rF   rÐ   )r   r   r   r   Útest_option_defaultA  s    

z&TestExpandDefaults.test_option_defaultc             C   s6   | j jdd| jd | j  dd¡ |  | j | j¡ d S )Nz-fz--file)rÒ   Úfilezfoo.txt)r#   rx   rÏ   Úset_defaultrF   rÐ   )r   r   r   r   Útest_parser_default_1G  s    

z(TestExpandDefaults.test_parser_default_1c             C   s6   | j jdd| jd | j jdd |  | j | j¡ d S )Nz-fz--file)rÒ   zfoo.txt)rÔ   )r#   rx   rÏ   r²   rF   rÐ   )r   r   r   r   Útest_parser_default_2M  s    

z(TestExpandDefaults.test_parser_default_2c             C   s(   | j jdd| jd |  | j | j¡ d S )Nz-fz--file)rÒ   )r#   rx   rÏ   rF   rÑ   )r   r   r   r   Útest_no_defaultS  s    

z"TestExpandDefaults.test_no_defaultc             C   s*   | j jddd | jd |  | j | j¡ d S )Nz-fz--file)rª   rÒ   )r#   rx   rÏ   rF   rÑ   )r   r   r   r   Útest_default_none_1X  s    

z&TestExpandDefaults.test_default_none_1c             C   s6   | j jdd| jd | j jd d |  | j | j¡ d S )Nz-fz--file)rÒ   )rÔ   )r#   rx   rÏ   r²   rF   rÑ   )r   r   r   r   Útest_default_none_2^  s    

z&TestExpandDefaults.test_default_none_2c             C   s<   | j jdddd | j jdd | jd }|  | j |¡ d S )Nz-pz--probz1blow up with probability PROB [default: %default])rÒ   g…ëQ¸…Û?)ZprobzF  -p PROB, --prob=PROB  blow up with probability PROB [default: 0.43]
)r#   rx   r²   rÎ   rF   )r   rE   r   r   r   Útest_float_defaultd  s    z%TestExpandDefaults.test_float_defaultc             C   s2   | j jddddd d| j j_|  | j | j¡ d S )Nz-fz--filezfoo.txtz#read from FILE [default: *DEFAULT*])rª   rÒ   z	*DEFAULT*)r#   rx   Ú	formatterÚdefault_tagrF   rÐ   )r   r   r   r   Útest_alt_expandm  s
    

z"TestExpandDefaults.test_alt_expandc             C   s:   | j jddddd d | j j_| jd }|  | j |¡ d S )Nz-fz--filezfoo.txtzread from %default file)rª   rÒ   z0  -f FILE, --file=FILE  read from %default file
)r#   rx   rÜ   rÝ   rÎ   rF   )r   rE   r   r   r   Útest_no_expandt  s    

z!TestExpandDefaults.test_no_expandN)r   r   r   rI   rÓ   rÖ   r×   rØ   rÙ   rÚ   rÛ   rÞ   rß   r   r   r   r   rÌ   2  s   	rÌ   c               @   sä   e 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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+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7S )8ÚTestStandardc             C   s8   t dddt dddddt d	d
dg}tt|d| _d S )Nz-ar”   )r?   z-bz--boorX   Úboo)r?   rv   z--fooÚappend)rS   )rH   Úoption_list)r   r   r	   r#   )r   r)   r   r   r   rI     s
    
zTestStandard.setUpc             C   s   |   dgd¡ d S )Nz-az-a option requires 1 argument)r;   )r   r   r   r   Útest_required_value‰  s    z TestStandard.test_required_valuec             C   s   |   ddgd¡ d S )Nz-bZ5xz&option -b: invalid integer value: '5x')r;   )r   r   r   r   Útest_invalid_integerŒ  s    
z!TestStandard.test_invalid_integerc             C   s   |   dgd¡ d S )Nz--boo13zno such option: --boo13)r;   )r   r   r   r   Útest_no_such_option  s    z TestStandard.test_no_such_optionc             C   s   |   dgd¡ d S )Nz--boo=x5z)option --boo: invalid integer value: 'x5')r;   )r   r   r   r   Útest_long_invalid_integer“  s    z&TestStandard.test_long_invalid_integerc             C   s   |   g d d d dœg ¡ d S )N)Úará   rP   )r*   )r   r   r   r   Ú
test_empty—  s    zTestStandard.test_emptyc             C   s&   |   ddddgdd ddgdœg ¡ d S )Nz-ar\   z
--foo=blahz--foo=rµ   )rè   rá   rP   )r*   )r   r   r   r   Ú"test_shortopt_empty_longopt_appendš  s    z/TestStandard.test_shortopt_empty_longopt_appendc             C   s*   |   dddddgd d dddgdœg ¡ d S )Nz--foorQ   r\   z--foo=xr¶   )rè   rá   rP   )r*   )r   r   r   r   Útest_long_option_appendŸ  s
    z$TestStandard.test_long_option_appendc             C   s   |   dgdd d dœg ¡ d S )Nz-abcZbc)rè   rá   rP   )r*   )r   r   r   r   Útest_option_argument_joined¦  s    
z(TestStandard.test_option_argument_joinedc             C   s   |   ddgdd d dœg ¡ d S )Nz-aZ34)rè   rá   rP   )r*   )r   r   r   r   Útest_option_argument_split«  s    

z'TestStandard.test_option_argument_splitc             C   s   |   dgd dd dœg ¡ d S )Nz-b34é"   )rè   rá   rP   )r*   )r   r   r   r   Ú#test_option_argument_joined_integer°  s    
z0TestStandard.test_option_argument_joined_integerc             C   s   |   ddgd dd dœg ¡ d S )Nz-bz-5éûÿÿÿ)rè   rá   rP   )r*   )r   r   r   r   Ú+test_option_argument_split_negative_integerµ  s    

z8TestStandard.test_option_argument_split_negative_integerc             C   s   |   dgd dd dœg ¡ d S )Nz--boo=13é   )rè   rá   rP   )r*   )r   r   r   r   Ú test_long_option_argument_joinedº  s    
z-TestStandard.test_long_option_argument_joinedc             C   s   |   ddgd dd dœg ¡ d S )Nz--booZ111éo   )rè   rá   rP   )r*   )r   r   r   r   Útest_long_option_argument_split¿  s    

z,TestStandard.test_long_option_argument_splitc             C   s    |   ddgdd dgdœg ¡ d S )Nz	--foo=barz-axyzÚxyzrQ   )rè   rá   rP   )r*   )r   r   r   r   Útest_long_option_short_optionÄ  s    
z*TestStandard.test_long_option_short_optionc             C   s    |   ddgdd dgdœg ¡ d S )Nz--f=barz-axyzrö   rQ   )rè   rá   rP   )r*   )r   r   r   r   Útest_abbrev_long_optionÉ  s    
z$TestStandard.test_abbrev_long_optionc             C   s2   | j  g ¡\}}| j  ¡ }|  t|ƒt|ƒ¡ d S )N)r#   r$   r°   r&   r%   )r   r)   r(   r   r   r   r   Útest_defaultsÎ  s    
zTestStandard.test_defaultsc             C   s&   | j jddddd |  dgd¡ d S )Nz--fozra   r”   rP   )rS   r?   rv   z--f=barz%ambiguous option: --f (--foo, --foz?))r#   rx   r;   )r   r   r   r   Útest_ambiguous_optionÓ  s    

z"TestStandard.test_ambiguous_optionc             C   s$   |   ddddgdd dgdœg ¡ d S )Nz-arö   z--foorQ   )rè   rá   rP   )r*   )r   r   r   r   Ú test_short_and_long_option_splitÚ  s    z-TestStandard.test_short_and_long_option_splitc             C   s(   |   dddddgd dddgdœg ¡ d S )	Nz	--foo=barz-bZ123z--foorŽ   é{   rQ   )rè   rá   rP   )r*   )r   r   r   r   Ú*test_short_option_split_long_option_appendß  s    z7TestStandard.test_short_option_split_long_option_appendc             C   s"   |   dddgdd d dœdg¡ d S )Nz-arP   rQ   )rè   rá   rP   )r*   )r   r   r   r   Ú*test_short_option_split_one_positional_argä  s    
z7TestStandard.test_short_option_split_one_positional_argc             C   sF   |   ddddgdd d dœddg¡ |   ddddgdd dgdœg ¡ d S )Nz-az--rP   rQ   )rè   rá   rP   z--foo)r*   )r   r   r   r   Ú$test_short_option_consumes_separatoré  s    

z1TestStandard.test_short_option_consumes_separatorc             C   s(   |   ddddgdd d dœddg¡f d S )Nz-abz--z--foorQ   rL   )rè   rá   rP   )r*   )r   r   r   r   Ú&test_short_option_joined_and_separatorñ  s    
z3TestStandard.test_short_option_joined_and_separatorc             C   s&   |   ddddgdd dgdœdg¡ d S )Nz-abú-z--foorQ   rL   )rè   rá   rP   )r*   )r   r   r   r   Ú"test_hyphen_becomes_positional_argö  s    z/TestStandard.test_hyphen_becomes_positional_argc             C   s*   |   ddddddgd dddgd	œg ¡ d S )
Nz-b3z-bÚ5z	--foo=barz--foorŽ   é   rQ   )rè   rá   rP   )r*   )r   r   r   r   Útest_no_append_versus_appendû  s    z)TestStandard.test_no_append_versus_appendc             C   s   |   ddgdd d dœg ¡ d S )Nz-az-b3)rè   rá   rP   )r*   )r   r   r   r   Ú&test_option_consumes_optionlike_string   s    

z3TestStandard.test_option_consumes_optionlike_stringc             C   s"   | j jddd |  dgd¡ d S )Nz-trt   )rS   z-testzno such option: -e)r#   rx   r;   )r   r   r   r   Ú#test_combined_single_invalid_option  s    z0TestStandard.test_combined_single_invalid_optionN)r   r   r   rI   rä   rå   ræ   rç   ré   rê   rë   rì   rí   rï   rñ   ró   rõ   r÷   rø   rù   rú   rû   rý   rþ   rÿ   r   r  r  r  r  r   r   r   r   rà   €  s6   rà   c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestBoolc             C   s2   t ddddddt ddd	dd
g}t|d| _d S )Nz-vz	--verbosert   ru   r\   )rS   rv   rª   z-qz--quietrw   )rS   rv   )rã   )r   r   r#   )r   r)   r   r   r   rI     s    
zTestBool.setUpc             C   s   |   g ddig ¡ d S )Nru   r\   )r*   )r   r   r   r   Útest_bool_default  s    zTestBool.test_bool_defaultc             C   s,   |   dgddig ¡\}}|  |jdk¡ d S )Nz-qru   r   F)r*   r/   ru   )r   r)   r(   r   r   r   Útest_bool_false  s    
zTestBool.test_bool_falsec             C   s,   |   dgddig ¡\}}|  |jdk¡ d S )Nz-vru   rb   T)r*   r/   ru   )r   r)   r(   r   r   r   Útest_bool_true"  s    
zTestBool.test_bool_truec             C   s   |   dddgddig ¡ d S )Nz-qvqz-qz-vru   rb   )r*   )r   r   r   r   Útest_bool_flicker_on_and_off(  s    z%TestBool.test_bool_flicker_on_and_offN)r   r   r   rI   r	  r
  r  r  r   r   r   r   r  
  s
   r  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
Ú
TestChoicec             C   s,   t td| _| jjdddddddgd d S )	N)rH   z-cra   rZ   ÚoneZtwoZthree)rS   r?   rv   r]   )r   r	   r#   rx   )r   r   r   r   rI   .  s    zTestChoice.setUpc             C   s   |   dddgddidg¡ d S )Nz-cr  rö   rZ   )r*   )r   r   r   r   Útest_valid_choice3  s    zTestChoice.test_valid_choicec             C   s   |   dddgd¡ d S )Nz-cÚfourÚabczEoption -c: invalid choice: 'four' (choose from 'one', 'two', 'three'))r;   )r   r   r   r   Útest_invalid_choice8  s    zTestChoice.test_invalid_choicec             C   sD   | j jdddddgd | j  d¡}|  |jd¡ |  |jd¡ d S )	Nz-dz	--defaultr  ZfiveZsix)r]   rZ   ra   )r#   rx   r{   r&   r?   rS   )r   r¡   r   r   r   Útest_add_choice_option=  s
    
z!TestChoice.test_add_choice_optionN)r   r   r   rI   r  r  r  r   r   r   r   r  -  s   r  c               @   s|   e 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d„ Zdd„ Zdd„ Zdd„ ZdS )Ú	TestCountc             C   sV   t td| _tdddd| _| j | j¡ | jjdddd | jjd	d
dddd d S )N)rH   z-vrW   ru   )rS   rv   z	--verboserX   )r?   rv   z-qz--quietÚstore_constr   )rS   rv   rc   )r   r	   r#   r   Úv_optrx   )r   r   r   r   rI   E  s    
zTestCount.setUpc             C   s   |   g dd ig ¡ d S )Nru   )r*   )r   r   r   r   ré   M  s    zTestCount.test_emptyc             C   s   |   dgddig ¡ d S )Nz-vru   rb   )r*   )r   r   r   r   Útest_count_oneP  s    zTestCount.test_count_onec             C   s   |   dgddig ¡ d S )Nz-vvvru   é   )r*   )r   r   r   r   Útest_count_threeS  s    zTestCount.test_count_threec             C   s   |   dddgddig ¡ d S )Nz-vru   r  )r*   )r   r   r   r   Útest_count_three_apartV  s    z TestCount.test_count_three_apartc             C   s   |   ddgddig ¡ d S )Nz-vvvz--verbose=2ru   re   )r*   )r   r   r   r   Útest_count_override_amountY  s    z$TestCount.test_count_override_amountc             C   s   |   dddgddig ¡ d S )Nz-vvvz--verbose=2z-qru   r   )r*   )r   r   r   r   Útest_count_override_quiet\  s    z#TestCount.test_count_override_quietc             C   s   |   ddddgddig ¡ d S )Nz-vvvz--verbose=2z-qz-vru   rb   )r*   )r   r   r   r   Útest_count_overriding_  s    zTestCount.test_count_overridingc             C   s   |   dddgddidg¡ d S )Nz--quietÚ3z-vru   rb   )r*   )r   r   r   r   Útest_count_interspersed_argsc  s    z&TestCount.test_count_interspersed_argsc             C   s*   | j  ¡  |  dddgddiddg¡ d S )Nz--quietr  z-vru   r   )r#   Zdisable_interspersed_argsr*   )r   r   r   r   Útest_count_no_interspersed_argsh  s    
z)TestCount.test_count_no_interspersed_argsc             C   s   |   ddgd¡ d S )Nz-q3z-vzno such option: -3)r;   )r   r   r   r   Útest_count_no_such_optionn  s    z#TestCount.test_count_no_such_optionc             C   s   |   ddgd¡ d S )Nz	--quiet=3z-vz$--quiet option does not take a value)r;   )r   r   r   r   Útest_count_option_no_valueq  s    
z$TestCount.test_count_option_no_valuec             C   s$   | j  dd¡ |  g ddig ¡ d S )Nru   r   )r#   rÕ   r*   )r   r   r   r   Útest_count_with_defaultu  s    z!TestCount.test_count_with_defaultc             C   s,   | j  dd¡ |  ddddgddig ¡ d S )Nru   r   z-vvvz--verbose=2z-qz-vrb   )r#   rÕ   r*   )r   r   r   r   Útest_count_overriding_defaulty  s    z'TestCount.test_count_overriding_defaultN)r   r   r   rI   ré   r  r  r  r  r  r  r  r   r!  r"  r#  r$  r   r   r   r   r  D  s   r  c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestMultipleArgsc             C   s(   t td| _| jjddddddd d S )	N)rH   z-pz--pointra   r  ÚfloatÚpoint)rS   rf   r?   rv   )r   r	   r#   rx   )r   r   r   r   rI     s    
zTestMultipleArgs.setUpc             C   s&   |   ddddddgddiddg¡ d S )	NrP   z-pÚ1z2.5z-4.3rö   r'  )g      ð?g      @g333333À)r*   )r   r   r   r   Útest_nargs_with_positional_args„  s    z0TestMultipleArgs.test_nargs_with_positional_argsc             C   s"   |   dddddgddidg¡ d S )Nz--pointz-1z2.5z-0rö   r'  )g      ð¿g      @g       €)r*   )r   r   r   r   Útest_nargs_long_opt‰  s    z$TestMultipleArgs.test_nargs_long_optc             C   s   |   ddddgd¡ d S )Nz-pz1.0Z2xz3.5z-option -p: invalid floating-point value: '2x')r;   )r   r   r   r   Útest_nargs_invalid_float_valueŽ  s    z/TestMultipleArgs.test_nargs_invalid_float_valuec             C   s   |   dddgd¡ d S )Nz--pointz1.0z3.5z#--point option requires 3 arguments)r;   )r   r   r   r   Útest_nargs_required_values“  s    z+TestMultipleArgs.test_nargs_required_valuesN)r   r   r   rI   r)  r*  r+  r,  r   r   r   r   r%  ~  s
   r%  c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestMultipleArgsAppendc             C   sV   t td| _| jjddddddd | jjd	d
ddddd | jjdddddd d S )N)rH   z-pz--pointra   r  r&  r'  )rS   rf   r?   rv   z-fz--foorâ   re   rX   rP   z-zz--zeroÚappend_const)r   r   )rS   rv   rc   )r   r	   r#   rx   )r   r   r   r   rI   ˜  s    

zTestMultipleArgsAppend.setUpc          	   C   s,   |   dddddddgd dd	gd
œdg¡ d S )Nz-fÚ4z-3rµ   z--foor(  Z666)é   éýÿÿÿ)rb   iš  )r'  rP   )r*   )r   r   r   r   Útest_nargs_append¡  s    z(TestMultipleArgsAppend.test_nargs_appendc             C   s   |   dgd¡ d S )Nz-f4,3z-f option requires 2 arguments)r;   )r   r   r   r   Ú!test_nargs_append_required_values¦  s    z8TestMultipleArgsAppend.test_nargs_append_required_valuesc             C   s   |   ddgd dgdœg ¡ d S )Nz--foo=3r/  )r  r0  )r'  rP   )r*   )r   r   r   r   Útest_nargs_append_simpleª  s    

z/TestMultipleArgsAppend.test_nargs_append_simplec             C   s(   |   dddddgd dddgdœg ¡ d S )	Nz--zeroz--foor  r/  z-z)r   r   )r  r0  )r'  rP   )r*   )r   r   r   r   Útest_nargs_append_const¯  s    z.TestMultipleArgsAppend.test_nargs_append_constN)r   r   r   rI   r2  r3  r4  r5  r   r   r   r   r-  —  s
   	r-  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚTestVersionc          
   C   s\   t tdd| _tjd d … }z*tj tjdd¡tjd< |  	dgd¡ W d |tjd d …< X d S )Nz	%prog 0.1)rH   rÁ   rP   rQ   r   z	--versionzbar 0.1
)
r   r	   r#   r<   rÃ   rÄ   rÅ   rÆ   ÚcurdirrA   )r   rÇ   r   r   r   Útest_versionµ  s    
zTestVersion.test_versionc             C   s   t td| _|  dgd¡ d S )N)rH   z	--versionzno such option: --version)r   r	   r#   r;   )r   r   r   r   Útest_no_version¿  s    zTestVersion.test_no_versionN)r   r   r   r8  r9  r   r   r   r   r6  ´  s   
r6  c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚTestConflictingDefaultsz4Conflicting default values: the last one should win.c             C   s   t tdddddgd| _d S )Nz-vrt   ru   rb   )rS   rv   rª   )rã   )r   r   r#   )r   r   r   r   rI   È  s    zTestConflictingDefaults.setUpc             C   s*   | j jddddd |  g ddig ¡ d S )Nz-qrw   ru   r   )rS   rv   rª   )r#   rx   r*   )r   r   r   r   Útest_conflict_defaultÌ  s    z-TestConflictingDefaults.test_conflict_defaultc             C   s*   | j jdddd d |  g dd ig ¡ d S )Nz-qrw   ru   )rS   rv   rª   )r#   rx   r*   )r   r   r   r   Útest_conflict_default_noneÑ  s    z2TestConflictingDefaults.test_conflict_default_noneN)r   r   r   rË   rI   r;  r<  r   r   r   r   r:  Æ  s   r:  c               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTestOptionGroupc             C   s   t td| _d S )N)rH   )r   r	   r#   )r   r   r   r   rI   ×  s    zTestOptionGroup.setUpc             C   s@   t | jdƒ}| j |¡ |jdddd |  dgddig ¡ d S )NÚSpamz--spamrt   zspam spam spam spam)rS   rÒ   Zspamrb   )r   r#   Úadd_option_grouprx   r*   )r   Úgroupr   r   r   Ú!test_option_group_create_instanceÚ  s
    z1TestOptionGroup.test_option_group_create_instancec             C   s   |   | jjdd ¡ d S )Nz!not an OptionGroup instance: None)rC   r#   r?  )r   r   r   r   Útest_add_group_no_groupá  s    
z'TestOptionGroup.test_add_group_no_groupc             C   s   |   | jjdd d ¡ d S )Nzinvalid arguments)rC   r#   r?  )r   r   r   r   Ú test_add_group_invalid_argumentså  s    
z0TestOptionGroup.test_add_group_invalid_argumentsc             C   s0   t | jdƒ}tƒ |_|  | jj|fd td¡ d S )Nr>  z"invalid OptionGroup (wrong parser))r   r#   r   r7   r?  r‡   )r   r@  r   r   r   Útest_add_group_wrong_parseré  s    z+TestOptionGroup.test_add_group_wrong_parserc             C   s@   | j jddd}| d¡ |jddd |  | j  d¡|¡ d S )NzGroup 2zSome more options)ÚdescriptionZBaconz--baconrX   )r?   )r#   r?  Z	set_titlerx   r/   Zget_option_group)r   r@  r   r   r   Útest_group_manipulateï  s
    
z%TestOptionGroup.test_group_manipulateN)	r   r   r   rI   rA  rB  rC  rD  rF  r   r   r   r   r=  Ö  s   r=  c               @   sD   e Zd Zdd„ Zdd„ ZG dd„ deƒZdd„ Zd	d
„ Zdd„ Z	dS )ÚTestExtendAddTypesc             C   s<   t t| jd| _| jjdd ddd | jjddddd d S )	N)rH   r»   z-ar”   rè   )r?   rv   z-fz--filerÔ   )r   r	   ÚMyOptionr#   rx   )r   r   r   r   rI   ù  s    zTestExtendAddTypes.setUpc             C   s:   t j tj¡rt  tj¡ nt j tj¡r6t  tj¡ d S )N)rÄ   rÅ   Úisdirr   ÚTESTFNÚrmdirÚisfileÚunlink)r   r   r   r   ÚtearDownÿ  s    zTestExtendAddTypes.tearDownc               @   s2   e Zd Zdd„ Zejd Ze ej¡Zeed< dS )zTestExtendAddTypes.MyOptionc             C   s6   t j |¡std| ƒ‚nt j |¡s2td| ƒ‚|S )Nz%s: file does not existz%s: not a regular file)rÄ   rÅ   Úexistsr   rL  )r    r¡   r¢   r   r   r   Ú
check_file  s
    z&TestExtendAddTypes.MyOption.check_file)rÔ   rÔ   N)r   r   r   rP  r   r¦   r§   r¨   r   r   r   r   rH    s   
rH  c             C   s.   t  t j¡ |  dt jdgt jddœg ¡ d S )Nz--filez-afoorP   )rÔ   rè   )r   Zcreate_empty_filerJ  r*   )r   r   r   r   Útest_filetype_ok  s    
z#TestExtendAddTypes.test_filetype_okc             C   s   |   dtjdgdtj ¡ d S )Nz--filez-afooz%s: file does not exist)r;   r   rJ  )r   r   r   r   Útest_filetype_noexist  s    z(TestExtendAddTypes.test_filetype_noexistc             C   s*   t  tj¡ |  dtjdgdtj ¡ d S )Nz--filez-afooz%s: not a regular file)rÄ   Úmkdirr   rJ  r;   )r   r   r   r   Útest_filetype_notfile  s    z(TestExtendAddTypes.test_filetype_notfileN)
r   r   r   rI   rN  r   rH  rQ  rR  rT  r   r   r   r   rG  ø  s   rG  c               @   s4   e Zd Zdd„ ZG dd„ deƒZdd„ Zdd„ Zd	S )
ÚTestExtendAddActionsc             C   s&   | j ddddddg}t|d| _d S )Nz-az--appleÚextendr”   Úapple)rS   r?   rv   )rã   )rH  r   r#   )r   r)   r   r   r   rI   $  s    
zTestExtendAddActions.setUpc               @   s2   e Zd Zejd Zejd Zejd Zdd„ ZdS )zTestExtendAddActions.MyOption)rV  c          	   C   s@   |dkr&|  d¡}| |g ¡ |¡ nt | ||||||¡ d S )NrV  ú,)ÚsplitÚensure_valuerV  r   Útake_action)r   rS   rv   r¡   r¢   r   r#   Zlvaluer   r   r   r[  .  s
    
z)TestExtendAddActions.MyOption.take_actionN)r   r   r   r   ZACTIONSZSTORE_ACTIONSZTYPED_ACTIONSr[  r   r   r   r   rH  )  s   


rH  c             C   s    |   ddgddddgig ¡ d S )Nz	-afoo,barz--apple=blahrW  rP   rQ   rµ   )r*   )r   r   r   r   Útest_extend_add_action6  s    
z+TestExtendAddActions.test_extend_add_actionc             C   s&   |   ddddgdddddgig ¡ d S )	Nz-arP   z-abarz--apple=x,yrW  rQ   r¶   r·   )r*   )r   r   r   r   Útest_extend_add_action_normal;  s    z2TestExtendAddActions.test_extend_add_action_normalN)r   r   r   rI   r   rH  r\  r]  r   r   r   r   rU  #  s   rU  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestCallbackc          	   C   s8   t dd d| jdt ddd| jdddg}t|d	| _d S )
Nz-xrh   )rS   rh   z-fz--filer”   Úfilename)rS   rh   r?   rv   )rã   )r   Úprocess_optr   r#   )r   r)   r   r   r   rI   C  s    
zTestCallback.setUpc             C   sä   |dkrd|   |jdg¡ |   |jg ¡ |  || jk¡ |  |d k¡ |   t|jƒdd i¡ d|j_n||dkrÒ|   |jdg¡ |   |jdg¡ |  || jk¡ |   |d¡ |   t|jƒd ddœ¡ t|j|j	|ƒ n|  
d| ¡ d S )	Nz-xr_  r‰   z--filez-frP   )r_  r¶   z!Unknown option %r in process_opt.)r&   r|   r}   r/   r#   r%   r   r¶   Úsetattrrv   r2   )r   r    r¡   r¢   Úparser_r   r   r   r`  P  s    
zTestCallback.process_optc             C   s   |   ddgdddœg ¡ d S )Nz-xz
--file=foorP   r‰   )r_  r¶   )r*   )r   r   r   r   Útest_callbackd  s    
zTestCallback.test_callbackc             C   sB   t td}| d¡ |jddddd„ dd	d
 d}|  ||¡ d S )N)rH   z-hz-tz--testrh   c               S   s   d S )Nr   r   r   r   r   Ú<lambda>p  ó    z1TestCallback.test_callback_help.<locals>.<lambda>r”   rP   )rS   rh   r?   rÒ   z%Options:
  -t TEST, --test=TEST  foo
)r   r	   r„   rx   rF   )r   r#   rE   r   r   r   Útest_callback_helpi  s    


zTestCallback.test_callback_helpN)r   r   r   rI   r`  rc  rf  r   r   r   r   r^  B  s   r^  c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestCallbackExtraArgsc          
   C   s0   t ddd| jdtfddg dg}t|d| _d S )	Nz-pz--pointrh   r  r”   Úpoints)rS   rh   rk   r?   rv   rª   )rã   )r   Úprocess_tuplerX   r   r#   )r   r)   r   r   r   rI   y  s
    zTestCallbackExtraArgs.setUpc             C   sp   |   |d¡ |  |tk¡ |dkr0|   |d¡ n|dkrD|   |d¡ tt|| d¡ƒƒ}t|j|jƒ 	|¡ d S )Nr  z-pz1,2,3z--pointz4,5,6rX  )
r&   r/   rX   rU   ÚmaprY  Úgetattrr   rv   râ   )r   r    r¡   r¢   rb  Úlenr?   r   r   r   ri  €  s    z#TestCallbackExtraArgs.process_tuplec             C   s    |   dddgdddgig ¡ d S )Nz-p1,2,3z--pointz4,5,6rh  )rb   re   r  )r0  r  é   )r*   )r   r   r   r   Útest_callback_extra_argsŒ  s    
z.TestCallbackExtraArgs.test_callback_extra_argsN)r   r   r   rI   ri  rn  r   r   r   r   rg  x  s   rg  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestCallbackMeddleArgsc                s*   ‡ fdd„t dddƒD ƒ}t|dˆ _d S )Nc                s"   g | ]}t t|ƒd ˆ jdd‘qS )rh   Úthings)rS   rh   rv   )r   r+   Ú	process_n)Ú.0r¶   )r   r   r   ú
<listcomp>“  s   z0TestCallbackMeddleArgs.setUp.<locals>.<listcomp>rœ   iúÿÿÿ)rã   )Úranger   r#   )r   r)   r   )r   r   rI   ’  s    
zTestCallbackMeddleArgs.setUpc             C   st   t |dd … ƒ}|j}t|ƒ|k r4|  d||f ¡ |j |jg ¡}| t|d|… ƒ¡ |j	 |¡ |d|…= d S )Nrb   z$Expected %d arguments for %s option.r   )
rX   Úrargsrl  r2   r   rZ  rv   râ   rU   Zlargs)r   r    r¡   r¢   rb  rf   ru  rv   r   r   r   rq  ™  s    z TestCallbackMeddleArgs.process_nc             C   s*   |   ddddddgddd	gid
dg¡ d S )Nz-1rP   z-3rQ   rŽ   Úquxrp  )rP   )rQ   rŽ   rv  rb   r  )r*   )r   r   r   r   Útest_callback_meddle_args¤  s    
z0TestCallbackMeddleArgs.test_callback_meddle_argsc             C   s    |   dddgddgidg¡ d S )Nz-2rP   z--rp  )rP   z--re   )r*   )r   r   r   r   Ú#test_callback_meddle_args_separator©  s    z:TestCallbackMeddleArgs.test_callback_meddle_args_separatorN)r   r   r   rI   rq  rw  rx  r   r   r   r   ro  ‘  s   ro  c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestCallbackManyArgsc          	   C   s<   t dddd| jddt dddd	| jd
dg}t|d| _d S )Nz-az--applerh   re   r”   )rS   rf   rh   r?   z-bz--bobr  rX   )rã   )r   Úprocess_manyr   r#   )r   r)   r   r   r   rI   ¯  s
    


zTestCallbackManyArgs.setUpc             C   sZ   |dkr|   |d¡ n@|dkr,|   |d¡ n*|dkrB|   |d¡ n|dkrV|   |d¡ d S )	Nz-a)rP   rQ   z--apple)ÚdingÚdongz-b)rb   re   r  z--bob)ifýÿÿr‰   r   )r&   )r   r    r¡   r¢   rb  r   r   r   rz  ¶  s    z!TestCallbackManyArgs.process_manyc             C   s4   |   ddddddddd	d
ddddgd d dœg ¡ d S )Nz-arP   rQ   z--appler{  r|  z-br(  Ú2r  z--bobz-666r¹   Ú0)rW  Zbob)r*   )r   r   r   r   Útest_many_argsÀ  s
    z#TestCallbackManyArgs.test_many_argsN)r   r   r   rI   rz  r  r   r   r   r   ry  ®  s   
ry  c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestCallbackCheckAbbrevc             C   s    t ƒ | _| jjdd| jd d S )Nz	--foo-barrh   )rS   rh   )r   r#   rx   Úcheck_abbrev)r   r   r   r   rI   È  s    
zTestCallbackCheckAbbrev.setUpc             C   s   |   |d¡ d S )Nz	--foo-bar)r&   )r   r    r¡   r¢   r#   r   r   r   r  Í  s    z$TestCallbackCheckAbbrev.check_abbrevc             C   s   |   dgi g ¡ d S )Nz--foo)r*   )r   r   r   r   Útest_abbrev_callback_expansionÐ  s    z6TestCallbackCheckAbbrev.test_abbrev_callback_expansionN)r   r   r   rI   r  r‚  r   r   r   r   r€  Ç  s   r€  c               @   sD   e 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S )ÚTestCallbackVarArgsc          	   C   sB   t dddddt dddd	t d
dd| jddg}tt|d| _d S )Nz-arX   re   rè   )r?   rf   rv   z-brt   rL   )rS   rv   z-cz
--callbackrh   Úc)rS   rh   rv   )rH   rã   )r   Úvariable_argsr   r	   r#   )r   r)   r   r   r   rI   Ô  s    zTestCallbackVarArgs.setUpc             C   s–   |   |d k¡ g }|j}xh|r€|d }|d d… dkrBt|ƒdksj|d d… dkrnt|ƒdkrn|d dkrnP q| |¡ |d= qW t|j|j|ƒ d S )Nr   re   z--rb   r  )r/   ru  rl  râ   ra  r   rv   )r   r    r¡   r¢   r#   ru  Úargr   r   r   r…  Ü  s    (

z!TestCallbackVarArgs.variable_argsc             C   s(   |   dddddgdd ddgdœg ¡ d S )Nz-a3z-5z
--callbackrP   rQ   )r  rð   )rè   rL   r„  )r*   )r   r   r   r   Útest_variable_argsê  s    z&TestCallbackVarArgs.test_variable_argsc             C   s.   |   ddddddgd ddddgdœdg¡ d S )	Nz-cZ37z--Zxxxz-bÚhelloT)rè   rL   r„  )r*   )r   r   r   r   Ú%test_consume_separator_stop_at_optionï  s
    z9TestCallbackVarArgs.test_consume_separator_stop_at_optionc             C   s,   |   dddddgd d dddgdœdg¡ d S )Nrˆ  z-crP   r  rQ   )rè   rL   r„  )r*   )r   r   r   r   Ú%test_positional_arg_and_variable_argsö  s
    z9TestCallbackVarArgs.test_positional_arg_and_variable_argsc             C   s"   |   dddgd ddgdœg ¡ d S )Nz-crP   z-bT)rè   rL   r„  )r*   )r   r   r   r   Útest_stop_at_optioný  s    z'TestCallbackVarArgs.test_stop_at_optionc             C   s   |   ddddgd¡ d S )Nz-cr  z-5z-azno such option: -5)r;   )r   r   r   r   Útest_stop_at_invalid_option  s    z/TestCallbackVarArgs.test_stop_at_invalid_optionN)
r   r   r   rI   r…  r‡  r‰  rŠ  r‹  rŒ  r   r   r   r   rƒ  Ó  s   rƒ  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚConflictBasec             C   s&   t ddddddg}tt|d| _d S )Nz-vz	--verboserW   ru   zincrement verbosity)rS   rv   rÒ   )rH   rã   )r   r   r	   r#   )r   r)   r   r   r   rI   	  s    zConflictBase.setUpc             C   s   d|j _d S )Nrb   )r   Úshow_version)r   r    r¡   r¢   r#   r   r   r   rŽ    s    zConflictBase.show_versionN)r   r   r   rI   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 )ÚTestConflictz9Use the default conflict resolution for Optik 1.2: error.c             C   s<   |   |dd| jddœtd¡}|  |jd¡ |  |jd¡ d S )N)z-vz	--versionrh   zshow version)rS   rh   rÒ   z5option -v/--version: conflicting option string(s): -vz conflicting option string(s): -vz-v/--version)r7   rŽ  r   r&   r   Z	option_id)r   r3   r6   r   r   r   ÚassertTrueconflict_error  s    z%TestConflict.assertTrueconflict_errorc             C   s   |   | jj¡ d S )N)r  r#   rx   )r   r   r   r   Útest_conflict_error  s    z TestConflict.test_conflict_errorc             C   s   t | jdƒ}|  |j¡ d S )NzGroup 1)r   r#   r  rx   )r   r@  r   r   r   Útest_conflict_error_group"  s    z&TestConflict.test_conflict_error_groupc             C   s   |   | jjdd td¡ d S )N)rP   z'invalid conflict_resolution value 'foo')r7   r#   Úset_conflict_handlerr‡   )r   r   r   r   Útest_no_such_conflict_handler&  s    
z*TestConflict.test_no_such_conflict_handlerN)r   r   r   rË   r  r‘  r’  r”  r   r   r   r   r    s
   r  c               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTestConflictResolvec             C   s2   t  | ¡ | j d¡ | jjddd| jdd d S )NÚresolvez-vz	--versionrh   zshow version)rS   rh   rÒ   )r  rI   r#   r“  rx   rŽ  )r   r   r   r   rI   -  s    
zTestConflictResolve.setUpc             C   s’   | j  d¡}| j  d¡}| j  d¡}|  ||k¡ |  ||k	¡ |  |jdg¡ |  |jdg¡ |  |jdg¡ |  |jg ¡ |  |jdg¡ d S )Nz-vz	--verbosez	--version)r#   r{   r/   r&   r}   r|   )r   r  Zverbose_optZversion_optr   r   r   Útest_conflict_resolve3  s    z)TestConflictResolve.test_conflict_resolvec             C   s   |   dgd¡ d S )Nz-hz}Options:
  --verbose      increment verbosity
  -h, --help     show this help message and exit
  -v, --version  show version
)rA   )r   r   r   r   Útest_conflict_resolve_help@  s    z.TestConflictResolve.test_conflict_resolve_helpc             C   s   |   dgd ddœg ¡ d S )Nz-vrb   )ru   rŽ  )r*   )r   r   r   r   Útest_conflict_resolve_short_optH  s    z3TestConflictResolve.test_conflict_resolve_short_optc             C   s   |   dgddig ¡ d S )Nz	--verboseru   rb   )r*   )r   r   r   r   Útest_conflict_resolve_long_optM  s    z2TestConflictResolve.test_conflict_resolve_long_optc             C   s   |   ddgdddœg ¡ d S )Nz	--verbosez	--versionrb   )ru   rŽ  )r*   )r   r   r   r   Útest_conflict_resolve_long_optsR  s    
z3TestConflictResolve.test_conflict_resolve_long_optsN)	r   r   r   rI   r—  r˜  r™  rš  r›  r   r   r   r   r•  ,  s   r•  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestConflictOverridec             C   sJ   t td| _| j d¡ | jjdddddd | jjddd	d
ddd d S )N)rH   r–  z-nz	--dry-runrt   Údry_runzdon't do anything)rS   rv   rÒ   r  r‰   zdry run mode)rS   rc   rv   rÒ   )r   r	   r#   r“  rx   )r   r   r   r   rI   X  s    

zTestConflictOverride.setUpc             C   s0   | j  d¡}|  |jdg¡ |  |jdg¡ d S )Nz	--dry-runz-n)r#   r{   r&   r|   r}   )r   r¡   r   r   r   Útest_conflict_override_optsb  s    z0TestConflictOverride.test_conflict_override_optsc             C   s   |   dgd¡ d S )Nz-hzXOptions:
  -h, --help     show this help message and exit
  -n, --dry-run  dry run mode
)rA   )r   r   r   r   Útest_conflict_override_helpg  s    z0TestConflictOverride.test_conflict_override_helpc             C   s   |   dgddig ¡ d S )Nz-nr  r‰   )r*   )r   r   r   r   Útest_conflict_override_argsn  s    z0TestConflictOverride.test_conflict_override_argsN)r   r   r   rI   rž  rŸ  r   r   r   r   r   rœ  W  s   
rœ  aS  Usage: bar.py [options]

Options:
  -a APPLE           throw APPLEs at basket
  -b NUM, --boo=NUM  shout "boo!" NUM times (in order to frighten away all the
                     evil spirits that cause trouble and mayhem)
  --foo=FOO          store FOO in the foo list for later fooing
  -h, --help         show this help message and exit
aS  Usage: bar.py [options]

Options:
  -a APPLE           throw APPLEs at basket
  --boo=NUM, -b NUM  shout "boo!" NUM times (in order to frighten away all the
                     evil spirits that cause trouble and mayhem)
  --foo=FOO          store FOO in the foo list for later fooing
  --help, -h         show this help message and exit
aW  Usage
=====
  bar.py [options]

Options
=======
-a APPLE           throw APPLEs at basket
--boo=NUM, -b NUM  shout "boo!" NUM times (in order to frighten away all the
                   evil spirits that cause trouble and mayhem)
--foo=FOO          store FOO in the foo list for later fooing
--help, -h         show this help message and exit
a}  Usage: bar.py [options]

Options:
  -a APPLE           throw APPLEs at basket
  -b NUM, --boo=NUM  shout "boo!" NUM times (in order to
                     frighten away all the evil spirits
                     that cause trouble and mayhem)
  --foo=FOO          store FOO in the foo list for later
                     fooing
  -h, --help         show this help message and exit
a~  Usage: bar.py [options]

Options:
  -a APPLE
    throw
    APPLEs at
    basket
  -b NUM, --boo=NUM
    shout
    "boo!" NUM
    times (in
    order to
    frighten
    away all
    the evil
    spirits
    that cause
    trouble and
    mayhem)
  --foo=FOO
    store FOO
    in the foo
    list for
    later
    fooing
  -h, --help
    show this
    help
    message and
    exit
c               @   sd   e 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d„ ZdS )ÚTestHelpc             C   s   |   d¡| _d S )NéP   )Úmake_parserr#   )r   r   r   r   rI   È  s    zTestHelp.setUpc          	   C   s`   t ddddddt ddd	d
dddt ddddddg}t ¡ }t|ƒ|d< t|dS Q R X d S )Nz-ar”   rè   ZAPPLEzthrow APPLEs at basket)r?   rv   ÚmetavarrÒ   z-bz--boorX   rá   ZNUMzeshout "boo!" NUM times (in order to frighten away all the evil spirits that cause trouble and mayhem)z--foorâ   rP   z*store FOO in the foo list for later fooing)rS   r?   rv   rÒ   ÚCOLUMNS)rã   )r   r   ÚEnvironmentVarGuardr+   r   )r   Úcolumnsr)   Úenvr   r   r   r£  Ë  s    



zTestHelp.make_parserc          
   C   sJ   t jd d … }z&tj dd¡t jd< |  dg|¡ W d |t jd d …< X d S )NrP   zbar.pyr   z-h)r<   rÃ   rÄ   rÅ   rÆ   rA   )r   r:   rÇ   r   r   r   ÚassertHelpEqualsà  s
    zTestHelp.assertHelpEqualsc             C   s   |   t¡ d S )N)r©  Ú_expected_help_basic)r   r   r   r   Ú	test_helpé  s    zTestHelp.test_helpc             C   s   | j  d¡ |  t¡ d S )NzUsage: %prog [options])r#   Z	set_usager©  rª  )r   r   r   r   Útest_help_old_usageì  s    zTestHelp.test_help_old_usagec             C   s   d| j j_|  t¡ d S )Nr   )r#   rÜ   Zshort_firstr©  Ú_expected_help_long_opts_first)r   r   r   r   Útest_help_long_opts_firstð  s    
z"TestHelp.test_help_long_opts_firstc          	   C   s4   t  ¡ "}d|d< tƒ | j_|  t¡ W d Q R X d S )NZ80r¥  )r   r¦  r   r#   rÜ   r©  Ú_expected_help_title_formatter)r   r¨  r   r   r   Útest_help_title_formatterô  s    

z"TestHelp.test_help_title_formatterc             C   s0   |   d¡| _|  t¡ |   d¡| _|  t¡ d S )Nr—   r   )r£  r#   r©  Ú_expected_help_short_linesÚ_expected_very_help_short_lines)r   r   r   r   Útest_wrap_columnsú  s    
zTestHelp.test_wrap_columnsc             C   s0   t td| _| jjdddd d}|  |¡ d S )N)rH   z-art   u   olÃ©!)rS   rÒ   uK   Options:
  -h, --help  show this help message and exit
  -a          olÃ©!
)r   r	   r#   rx   r©  )r   Úexpectr   r   r   Útest_help_unicode  s    zTestHelp.test_help_unicodec             C   s    t tdd| _d}|  |¡ d S )Nu   olÃ©!)rH   rE  u>   olÃ©!

Options:
  -h, --help  show this help message and exit
)r   r	   r#   r©  )r   r´  r   r   r   Útest_help_unicode_description  s    
z&TestHelp.test_help_unicode_descriptionc             C   s^   | j  d¡ t| j ddƒ}|jdddd | j  |¡ d}|  |¡ d	| j _|  |d
 ¡ d S )Nz`This is the program description for %prog.  %prog has an option group as well as single options.zDangerous OptionszZCaution: use of these options is at your own risk.  It is believed that some of them bite.z-grt   zGroup option.)rS   rÒ   aT  Usage: bar.py [options]

This is the program description for bar.py.  bar.py has an option group as
well as single options.

Options:
  -a APPLE           throw APPLEs at basket
  -b NUM, --boo=NUM  shout "boo!" NUM times (in order to frighten away all the
                     evil spirits that cause trouble and mayhem)
  --foo=FOO          store FOO in the foo list for later fooing
  -h, --help         show this help message and exit

  Dangerous Options:
    Caution: use of these options is at your own risk.  It is believed
    that some of them bite.

    -g               Group option.
z Please report bugs to /dev/null.z"
Please report bugs to /dev/null.
)r#   Zset_descriptionr   rx   r?  r©  Úepilog)r   r@  r´  r   r   r   Útest_help_description_groups  s    
z%TestHelp.test_help_description_groupsN)r   r   r   rI   r£  r©  r«  r¬  r®  r°  r³  rµ  r¶  r¸  r   r   r   r   r¡  Ç  s   		
r¡  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚTestMatchAbbrevc          	   C   s    |   tdd d d d dœƒd¡ d S )Nz--f)z--fozz--fooz--fiez--f)r&   r   )r   r   r   r   Útest_match_abbrev?  s    z!TestMatchAbbrev.test_match_abbrevc             C   s*   d}d d d dœ}|   t||fd td¡ d S )Nz--f)z--fozz--fooz--fiez,ambiguous option: --f (--fie, --foo, --foz?))r7   r   r   )r   r˜   Zwordmapr   r   r   Útest_match_abbrev_errorG  s
    
z'TestMatchAbbrev.test_match_abbrev_errorN)r   r   r   rº  r»  r   r   r   r   r¹  >  s   r¹  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestParseNumberc             C   s,   t ƒ | _| jjdtd | jjdtd d S )Nz-n)r?   z-l)r   r#   rx   rX   )r   r   r   r   rI   P  s    zTestParseNumber.setUpc          	   C   s<   |   tdtfi tt d¡¡ |   tdtfi tt d¡¡ d S )Nr\   z!invalid literal for int().*: '?'?Z0xOoopsz*invalid literal for int().*: s?'?0xOoops'?)r7   r   rX   r‡   r-   Úcompile)r   r   r   r   Útest_parse_num_failU  s    

z#TestParseNumber.test_parse_num_failc             C   sp   |   tdtƒd¡ |   tdtƒd¡ |   tdtƒd¡ |   tdtƒd¡ |   td	tƒd
¡ |   tdtƒd¡ d S )Nr~  r   Z0x10é   Z0XAé
   Z010é   Z0b11r  Z0b)r&   r   rX   )r   r   r   r   Útest_parse_num_ok_  s    z!TestParseNumber.test_parse_num_okc             C   sf   |   ddddgdddœg ¡ |   ddd	gd
ddœg ¡ |  dgd¡ |  dgd¡ |  ddgd¡ d S )Nz-nr¹   z-lZ0x20r‰   é    )r¬   ÚlZ0b0101z-l010r  rÁ  z-n008z'option -n: invalid integer value: '008'z-l0b0123z*option -l: invalid integer value: '0b0123'Z0x12xz)option -l: invalid integer value: '0x12x')r*   r;   )r   r   r   r   Útest_numeric_optionsg  s    
z$TestParseNumber.test_numeric_optionsN)r   r   r   rI   r¾  rÂ  rÅ  r   r   r   r   r¼  O  s   
r¼  c               @   s   e Zd Zdd„ ZdS )ÚMiscTestCasec             C   s   dddh}t j| t|d d S )NZcheck_builtinZAmbiguousOptionErrorZ
NO_DEFAULT)Ú	blacklist)r   Zcheck__all__Úoptparse)r   rÇ  r   r   r   Útest__all__u  s    
zMiscTestCase.test__all__N)r   r   r   rÉ  r   r   r   r   rÆ  t  s   rÆ  c               C   s   t  t¡ d S )N)r   Zrun_unittestr   r   r   r   r   Ú	test_mainz  s    rÊ  Ú__main__)Fr<   rÄ   r-   r§   ZunittestÚior   rÍ   r   rÈ  r   r   r   r   r   r	   r
   r   r   r   r   r   r   Ú	Exceptionr   r   ZTestCaser"   rG   rs   r   r“   rž   r£   r¤   r©   r½   rÌ   rà   r  r  r  r%  r-  r6  r:  r=  rG  rU  r^  rg  ro  ry  r€  rƒ  r  r  r•  rœ  rª  r­  r¯  r±  r²  r¡  r¹  r¼  rÆ  rÊ  r   r   r   r   r   Ú<module>	   sv   4  O
3*N #:"+65
+'!w%
