a
    ze                     @   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ZCeDd[kreE  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.9/test/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u rd}|du ri }z||i | W np |y } zXt |}t|tjrl| ||d|j|f  n| ||d||f  |W  Y d}~S d}~0 0 | 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   s0    	zBaseTest.assertRaisesc              
   C   sR   z| j | W n2 tyB } z| |j| W Y d}~nd}~0 0 | 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_outputr9   r   r   r   assertParseFail   s
    $zBaseTest.assertParseFailr   Nc              
   C   s   t j}z@z(t t _| j| W t j }|t _nt j }|t _0 W n| ty } zd| t|t	dt
|  ||kr| d| d | d  | |j| | |j| W Y d}~nd}~0 0 | d dS )z7Assert the parser prints the expected output on stdout.z0expected output to be an ordinary string, not %rzexpected: 
'''
z'''
but got 
'''
z'''Nzexpected parser.exit())sysstdoutr   r&   r'   getvaluer   r2   r/   r.   typer5   r)   r   r   r;   )r   r<   r=   Zexpected_statusZexpected_errorZsave_stdoutoutputr9   r   r   r   assertOutput   s6    


$zBaseTest.assertOutputc                 G   s   |  ||dt| dS )z4Assert that TypeError is raised when executing func.N)r:   	TypeError)r   r6   r8   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-   r:   r>   rD   rF   rI   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 r   )r:   r   r
   )r   r8   r+   r7   r   r   r   assertOptionError   s    
z"TestOptionChecks.assertOptionErrorc                 C   s   |  td d S )Nz+at least one option string must be supplied)rF   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rP   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)--rS   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---rS   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, foo-bfoobarrS   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'rX   actionrZ   rS   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'rX   rB   rZ   z'option -b: invalid option type: 'tuple')rP   tupler   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'rX   countint)r]   rB   rS   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'rX   --badrB   choicerS   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)rX   rd   re   zbad choicesrB   choices)rB   r   rP   )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'rX   rb   Zbadrh   rS   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'rX   store   )r]   constrS   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'rX   ra      )r]   nargsrS   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'rX   callbackrZ   r]   rt   rS   r   r   r   r   test_callback_not_callable  s    z+TestOptionChecks.test_callback_not_callablec                 C   s   d S r   r   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'rX   rt   rZ   )r]   rt   callback_argsrP   rw   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'rX   rt   rZ   )r]   rt   callback_kwargsry   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 optionrX   rm   rZ   ru   rS   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 optionrX   rm   rZ   )r]   rx   rS   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 optionrX   rm   rZ   )r]   r{   rS   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-dash-dz--debugrS   r   r   r   r   test_no_single_dash@  s    z$TestOptionChecks.test_no_single_dashN)r   r   r   rO   rP   rQ   rT   rV   rW   r\   r^   r`   rc   rf   rk   rl   rp   rs   rv   rw   rz   r|   r}   r~   r   r   r   r   r   r   rJ      s.   rJ   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 )N-v	--verbose-n--noisy
store_trueverboser]   dest-q--quiet--silentstore_false)r   r&   
add_optionr   r   r   r   rO   Q  s    zTestOptionParser.setUpc                 C   s   |  | jjdd  d S )Nznot an Option instance: NonerF   r&   r   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 argumentsr   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 )Nr   r   r   r   r   r   )	r&   
get_optionZassertIsInstancer   r)   _short_opts
_long_optsr]   r   )r   opt1r   r   r   test_get_option`  s    z TestOptionParser.test_get_optionc                 C   s\   | j d}| j d}| j d}| j d}| ||  u oP|  u oP|u n   d S )Nr   r   r   r   )r&   r   r2   )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 )Nr   r   )r2   r&   
has_optionr   r   r   r   test_has_optiono  s    z TestOptionParser.test_has_optionc                 C   s   |  | jdd u  |  | jdd u  |  | jdd u  |  | jdd u  | | jd | | jd | | jd | | jd |  | jd |  | jd d S )Nr   r   r   r   r   r   )r2   r&   r   r;   r   r   r   r   r   assertTrueremoveds  s    z"TestOptionParser.assertTrueremovedc                 C   s   | j d |   d S )Nr   r&   remove_optionr   r   r   r   r   test_remove_short_opt  s    z&TestOptionParser.test_remove_short_optc                 C   s   | j d |   d S )Nr   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rZ   zno such option 'foo')r:   r&   r   
ValueErrorr   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*   -az	--aaarggh)r?   getrefcountr   r   	big_thingZdestroyr)   )r   r   Zrefcountr&   r   r   r   test_refleak  s    
zTestOptionParser.test_refleakN)r   r   r   rO   r   r   r   r   r   r   r   r   r   r   Zimpl_detailr   r   r   r   r   r   P  s   r   c                   @   s   e Zd Zdd Zdd ZdS )TestOptionValuesc                 C   s   d S r   r   r   r   r   r   rO     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 )NrZ   r[   rg   r   )rZ   baz)defaults)r   r)   r(   ZassertNotEqual)r   valuesdictr   r   r   test_basics  s    

zTestOptionValues.test_basicsN)r   r   r   rO   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 r   )r   r&   r   r   r   r   rO     s    zTestTypeAliases.setUpc                 C   s*   | j jddd | | j djd d S )N-sr.   rB   string)r&   r   r)   r   rB   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 )Nr   r   r   -xrb   )r&   r   r.   r)   r   rB   rb   r   r   r   r   test_type_object  s    z TestTypeAliases.test_type_objectN)r   r   r   rO   r   r   r   r   r   r   r     s   r   rn   <   i  iQ )smhdc              	   C   sd   z8|d   rt|W S t|d d t|d   W S W n& ttfy^   td||f Y n0 d S )Nzoption %s: invalid duration: %r)isdigitrb   _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 )Nr   r   Tdefaultr   r   r   )r   r   rb   %   rB   r   z-mr   r   rZ   -tz-u)r   nr   r   tu)r   r&   r   expectedr   r   r   r   rO     s    zTestDefaultValues.setUpc                 C   s   |  | j | j d S r   )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yr   Zfrobr   z-yr   )r&   r   r   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 )Nr   r   i,  r   z-eZ6m42)r   ih  r   )r   er   F)
r   r&   option_classr   r   r   r   r)   r   Zset_process_default_valuesr   r   r   r   test_process_default  s    z&TestDefaultValues.test_process_defaultN)r   r   r   rO   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 r   )r)   Z	get_usager   r&   expected_usager   r   r   assertUsage  s    zTestProgName.assertUsagec                 C   s   |  | | d S r   )r)   Zget_version)r   r&   Zexpected_versionr   r   r   assertVersion  s    zTestProgName.assertVersionc              
   C   s   t jd d  }zdtjdddt jd< tddd}d}| || | |d	 | ||d
 d  W |t jd d < n|t jd d < 0 d S )NrZ   r[   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   rI   )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thingy	%prog 0.1z%prog arg arg)progr   rM   -h	--versionzUsage: thingy arg arg
z
thingy 0.1r   )r   r   r   r   rI   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_noner   r   r   r   rO   3  s    zTestExpandDefaults.setUpc                 C   s*   | j jddd| jd | | j | j d S )N-f--filefoo.txtr   help)r&   r   r   rI   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 )Nr   r   r   filer   )r&   r   r   set_defaultrI   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 )Nr   r   r   r   r   )r&   r   r   r   rI   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 )Nr   r   r   r&   r   r   rI   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 )Nr   r   r   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 )Nr   r   r   r  )r&   r   r   r   rI   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 )N-pz--probz1blow up with probability PROB [default: %default]r   gQ?)ZprobzF  -p PROB, --prob=PROB  blow up with probability PROB [default: 0.43]
)r&   r   r   r   rI   r   rH   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 )Nr   r   r   z#read from FILE [default: *DEFAULT*]r   z	*DEFAULT*)r&   r   	formatterdefault_tagrI   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 )Nr   r   r   zread from %default filer   z0  -f FILE, --file=FILE  read from %default file
)r&   r   r  r  r   rI   r
  r   r   r   test_no_expandt  s    

z!TestExpandDefaults.test_no_expandN)r   r   r   rO   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 )Nr   r   r   rX   --boorb   boorB   r   --fooappendr]   rM   option_listr   r   r	   r&   r   r,   r   r   r   rO     s    

zTestStandard.setUpc                 C   s   |  dgd d S )Nr   z-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 )NrX   Z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: --boo13r  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  rZ   r-   r   r   r   r   
test_empty  s    zTestStandard.test_emptyc                 C   s"   |  g ddd ddgdg  d S )N)r   rg   z
--foo=blahz--foo=rg   r   r   r"  r   r   r   r   "test_shortopt_empty_longopt_append  s    
z/TestStandard.test_shortopt_empty_longopt_appendc                 C   s"   |  g dd d g ddg  d S )N)r  r[   r  rg   z--foo=x)r[   rg   r   r   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bcr   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 )Nr   Z34r   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"  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 )NrX   -5r   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"  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 )Nr  Z111o   r   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 )N	--foo=bar-axyzxyzr[   r   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 )N--f=barr2  r3  r[   r   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 r   )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 )N--fozrm   r   rZ   r]   rB   r   r5  z%ambiguous option: --f (--foo, --foz?)r&   r   r>   r   r   r   r   test_ambiguous_option  s    
z"TestStandard.test_ambiguous_optionc                 C   s    |  g ddd dgdg  d S )N)r   r3  r  r[   r3  r[   r   r"  r   r   r   r    test_short_and_long_option_split  s    
z-TestStandard.test_short_and_long_option_splitc                 C   s"   |  g dd dddgdg  d S )N)r1  rX   Z123r  r   {   r[   r   r   r"  r   r   r   r   *test_short_option_split_long_option_append  s    
z7TestStandard.test_short_option_split_long_option_appendc                 C   s    |  g ddd d ddg d S )N)r   rZ   r[   rZ   r   r[   r"  r   r   r   r   *test_short_option_split_one_positional_arg  s    

z7TestStandard.test_short_option_split_one_positional_argc                 C   s>   |  g ddd d dddg |  g ddd dgdg  d S )N)r   rU   rZ   r[   rU   r   rZ   r[   )r   rU   r  r[   r"  r   r   r   r   $test_short_option_consumes_separator  s    


z1TestStandard.test_short_option_consumes_separatorc                 C   s$   |  g ddd d dddgf d S )N)-abrU   r  r[   rR   r   r  r[   r"  r   r   r   r   &test_short_option_joined_and_separator  s    

z3TestStandard.test_short_option_joined_and_separatorc                 C   s"   |  g ddd dgddg d S )N)rA  -r  r[   rR   r[   r   rC  r"  r   r   r   r   "test_hyphen_becomes_positional_arg  s    
z/TestStandard.test_hyphen_becomes_positional_argc                 C   s"   |  g dd dddgdg  d S )N)-b3rX   5r1  r  r      r[   r   r   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 )Nr   rE  r   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 )Nr   r   r  z-testzno such option: -er:  r   r   r   r   #test_combined_single_invalid_option  s    z0TestStandard.test_combined_single_invalid_optionN)r   r   r   rO   r  r  r  r  r#  r$  r%  r&  r'  r)  r,  r.  r0  r4  r6  r7  r;  r<  r>  r?  r@  rB  rD  rH  rI  rJ  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 )Nr   r   r   r   rg   r]   r   r   r   r   r   r   r  )r   r   r&   r  r   r   r   rO     s    	zTestBool.setUpc                 C   s   |  g ddig  d S )Nr   rg   r"  r   r   r   r   test_bool_default  s    zTestBool.test_bool_defaultc                 C   s,   |  dgddig \}}| |jdu  d S )Nr   r   r   Fr-   r2   r   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u  d S )Nr   r   rn   TrO  rP  r   r   r   test_bool_true"  s
    zTestBool.test_bool_truec                 C   s   |  g dddig  d S )N)z-qvqr   r   r   rn   r"  r   r   r   r   test_bool_flicker_on_and_off(  s    
z%TestBool.test_bool_flicker_on_and_offN)r   r   r   rO   rN  rQ  rR  rS  r   r   r   r   rK  
  s
   rK  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g dd d S )NrL   -crm   re   )oneZtwoZthree)r]   rB   r   ri   r   r	   r&   r   r   r   r   r   rO   .  s    zTestChoice.setUpc                 C   s   |  g dddidg d S )N)rU  rV  r3  re   rV  r3  r"  r   r   r   r   test_valid_choice3  s    
zTestChoice.test_valid_choicec                 C   s   |  g dd d S )N)rU  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   sB   | j jddg dd | j d}| |jd | |jd d S )Nr   z	--default)rY  ZfiveZsix)ri   re   rm   )r&   r   r   r)   rB   r]   r   r   r   r   r   test_add_choice_option=  s    
z!TestChoice.test_add_choice_optionN)r   r   r   rO   rX  r[  r]  r   r   r   r   rT  -  s   rT  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 )NrL   r   ra   r   r   r   rb   r  r   r   store_constr   r]   r   ro   )r   r	   r&   r   v_optr   r   r   r   r   rO   E  s    
zTestCount.setUpc                 C   s   |  g dd ig  d S )Nr   r"  r   r   r   r   r#  M  s    zTestCount.test_emptyc                 C   s   |  dgddig  d S )Nr   r   rn   r"  r   r   r   r   test_count_oneP  s    zTestCount.test_count_onec                 C   s   |  dgddig  d S )N-vvvr      r"  r   r   r   r   test_count_threeS  s    zTestCount.test_count_threec                 C   s   |  g dddig  d S )N)r   r   r   r   rd  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 )Nrc  --verbose=2r   rq   r"  r   r   r   r   test_count_override_amountY  s    z$TestCount.test_count_override_amountc                 C   s   |  g dddig  d S )N)rc  rg  r   r   r   r"  r   r   r   r   test_count_override_quiet\  s    z#TestCount.test_count_override_quietc                 C   s   |  g dddig  d S )Nrc  rg  r   r   r   rn   r"  r   r   r   r   test_count_overriding_  s    
zTestCount.test_count_overridingc                 C   s   |  g dddidg d S )Nr   3r   r   rn   rm  r"  r   r   r   r   test_count_interspersed_argsc  s    
z&TestCount.test_count_interspersed_argsc                 C   s(   | j   | g dddiddg d S )Nrl  r   r   rm  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-q3r   zno such option: -3r  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=3r   z$--quiet option does not take a valuer  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 )Nr   r   r&   r  r-   r   r   r   r   test_count_with_defaultu  s    z!TestCount.test_count_with_defaultc                 C   s(   | j dd | g dddig  d S )Nr   r   rj  rn   rr  r   r   r   r   test_count_overriding_defaulty  s    
z'TestCount.test_count_overriding_defaultN)r   r   r   rO   r#  rb  re  rf  rh  ri  rk  rn  ro  rp  rq  rs  rt  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 )	NrL   r	  --pointrm   rd  floatpointr]   rr   rB   r   rW  r   r   r   r   rO     s    
zTestMultipleArgs.setUpc                 C   s   |  g dddiddg d S )N)rZ   r	  12.5z-4.3r3  rx  )g      ?      @g333333rZ   r3  r"  r   r   r   r   test_nargs_with_positional_args  s    
z0TestMultipleArgs.test_nargs_with_positional_argsc                 C   s   |  g dddidg d S )N)rv  -1r{  z-0r3  rx  )g      r|  g       r3  r"  r   r   r   r   test_nargs_long_opt  s    
z$TestMultipleArgs.test_nargs_long_optc                 C   s   |  g dd d S )N)r	  1.0Z2x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   |  g dd d S )N)rv  r  r  z#--point option requires 3 argumentsr  r   r   r   r   test_nargs_required_values  s    
z+TestMultipleArgs.test_nargs_required_valuesN)r   r   r   rO   r}  r  r  r  r   r   r   r   ru  ~  s
   ru  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 )NrL   r	  rv  rm   rd  rw  rx  ry  r   r  r  rq   rb   rZ   -z--zeroappend_constr   r   r`  rW  r   r   r   r   rO     s    zTestMultipleArgsAppend.setUpc                 C   s"   |  g dd ddgddg d S )N)r   4-3r   r  rz  Z666)   )rn   i  rx  rZ   r   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 argumentsr  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  rd  r  r  r"  r   r   r   r   test_nargs_append_simple  s    

z/TestMultipleArgsAppend.test_nargs_append_simplec                 C   s    |  g dd g ddg  d S )N)r  r  rm  r  r  )r  r  r  r  r"  r   r   r   r   test_nargs_append_const  s    
z.TestMultipleArgsAppend.test_nargs_append_constN)r   r   r   rO   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 )TestVersionc              
   C   sj   t tdd| _tjd d  }z8tjtjddtjd< | 	dgd W |tjd d < n|tjd d < 0 d S )Nr   )rM   r   rZ   r[   r   r   zbar 0.1
)
r   r	   r&   r?   r   r   r   r   curdirrD   )r   r   r   r   r   test_version  s    zTestVersion.test_versionc                 C   s   t td| _| dgd d S )NrL   r   zno such option: --version)r   r	   r&   r>   r   r   r   r   test_no_version  s    zTestVersion.test_no_versionN)r   r   r   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S )	TestConflictingDefaultsz4Conflicting default values: the last one should win.c                 C   s   t tdddddgd| _d S )Nr   r   r   rn   rL  rM  )r   r   r&   r   r   r   r   rO     s    zTestConflictingDefaults.setUpc                 C   s*   | j jddddd | g ddig  d S )Nr   r   r   r   rL  r&   r   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 )Nr   r   r   rL  r  r   r   r   r   test_conflict_default_none  s    z2TestConflictingDefaults.test_conflict_default_noneN)r   r   r   r   rO   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 rK   rN   r   r   r   r   rO     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--spamr   zspam spam spam spamr]   r   Zspamrn   )r   r&   add_option_groupr   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rF   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 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   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--baconrb   r   )r&   r  Z	set_titler   r2   Zget_option_groupr  r   r   r   test_group_manipulate  s    
z%TestOptionGroup.test_group_manipulateN)	r   r   r   rO   r  r  r  r  r  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)rM   r   r   r   r!  r  r   r   r   )r   r	   MyOptionr&   r   r   r   r   r   rO     s
    zTestExtendAddTypes.setUpc                 C   s:   t jtjrt tj nt jtjr6t tj d S r   )r   r   isdirr   TESTFNrmdirisfileunlinkr   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 )N%s: file does not exist%s: not a regular file)r   r   existsr   r  r   r   r   r   
check_file  s
    z&TestExtendAddTypes.MyOption.check_filer  r   N)r   r   r   r  r   r   r   r   r   r   r   r   r    s   
r  c                 C   s.   t t j | dt jdgt jddg  d S )Nr   -afoorZ   )r   r!  )r   Zcreate_empty_filer  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 )Nr   r  r  )r>   r   r  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 )Nr   r  r  )r   mkdirr   r  r>   r   r   r   r   test_filetype_notfile  s    z(TestExtendAddTypes.test_filetype_notfileN)
r   r   r   rO   r  r   r  r  r  r  r   r   r   r   r    s   r  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 )Nr   --appleextendr   appler9  rM  )r  r   r&   r  r   r   r   rO   $  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)r  c              	   C   s@   |dkr&| d}||g | nt| |||||| d S )Nr  ,)splitensure_valuer  r   take_action)r   r]   r   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   r  )  s   


r  c                 C   s   |  ddgdg dig  d S )Nz	-afoo,barz--apple=blahr  )rZ   r[   r   r"  r   r   r   r   test_extend_add_action6  s    

z+TestExtendAddActions.test_extend_add_actionc                 C   s   |  g ddg dig  d S )N)r   rZ   z-abarz--apple=x,yr  )rZ   r[   r   r   r"  r   r   r   r   test_extend_add_action_normal;  s    

z2TestExtendAddActions.test_extend_add_action_normalN)r   r   r   rO   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 )
TestCallbackc              	   C   s8   t dd d| jdt ddd| jdddg}t|d	| _d S )
Nr   rt   ru   r   r   r   filename)r]   rt   rB   r   rM  )r   process_optr   r&   r  r   r   r   rO   C  s    
zTestCallback.setUpc                 C   s   |dkrd|  |jdg |  |jg  | || ju  | |d u  |  t|jdd i d|j_n||dkr|  |jdg |  |jdg | || ju  |  |d |  t|jd dd t|j|j	| n| 
d|  d S )	Nr   r  r   r   r   rZ   r  r   z!Unknown option %r in process_opt.)r)   r   r   r2   r&   r(   r   r   setattrr   r5   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 )Nr   z
--file=foorZ   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 )NrL   r   r   z--testrt   c                   S   s   d S r   r   r   r   r   r   <lambda>p      z1TestCallback.test_callback_help.<locals>.<lambda>r   rZ   )r]   rt   rB   r   z%Options:
  -t TEST, --test=TEST  foo
)r   r	   r   r   rI   )r   r&   rH   r   r   r   test_callback_helpi  s    


zTestCallback.test_callback_helpN)r   r   r   rO   r  r  r  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 )	Nr	  rv  rt   rd  r   points)r]   rt   rx   rB   r   r   rM  )r   process_tuplerb   r   r&   r  r   r   r   rO   y  s    zTestCallbackExtraArgs.setUpc                 C   sp   |  |d | |tu  |dkr0|  |d n|dkrD|  |d tt||d}t|j|j	| d S )Nrd  r	  z1,2,3rv  4,5,6r  )
r)   r2   rb   r_   mapr  getattrr   r   r  )r   r   r   r   r  lenrB   r   r   r   r    s    z#TestCallbackExtraArgs.process_tuplec                 C   s   |  g ddddgig  d S )N)z-p1,2,3rv  r  r  rn   rq   rd  )r  rG     r"  r   r   r   r   test_callback_extra_args  s    

z.TestCallbackExtraArgs.test_callback_extra_argsN)r   r   r   rO   r  r  r   r   r   r   r  x  s   r  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 )rt   thingsr]   rt   r   )r   r.   	process_n).0r   r   r   r   
<listcomp>  s   
z0TestCallbackMeddleArgs.setUp.<locals>.<listcomp>r   irM  )ranger   r&   r  r   r   r   rO     s    

zTestCallbackMeddleArgs.setUpc                 C   st   t |dd  }|j}t||k r4| d||f  |j|jg }|t|d|  |j	| |d|= d S )Nrn   z$Expected %d arguments for %s option.r   )
rb   rargsr  r5   r   r  r   r  r_   Zlargs)r   r   r   r   r  rr   r  r   r   r   r   r    s    z TestCallbackMeddleArgs.process_nc                 C   s"   |  g ddddgiddg d S )N)r~  rZ   r  r[   r   quxr  r   )r[   r   r  rn   rd  r"  r   r   r   r   test_callback_meddle_args  s    

z0TestCallbackMeddleArgs.test_callback_meddle_argsc                 C   s   |  g dddgidg d S )N)z-2rZ   rU   r  )rZ   rU   rq   r"  r   r   r   r   #test_callback_meddle_args_separator  s    
z:TestCallbackMeddleArgs.test_callback_meddle_args_separatorN)r   r   r   rO   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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 )Nr   r  rt   rq   r   )r]   rr   rt   rB   rX   --bobrd  rb   rM  )r   process_manyr   r&   r  r   r   r   rO     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 )	Nr   rY   r  )dingdongrX   r  r  )ifr   r   r)   r  r   r   r   r    s    z!TestCallbackManyArgs.process_manyc                 C   s   |  g dd d dg  d S )N)r   rZ   r[   r  r  r  rX   rz  2rm  r  z-666r   0)r  Zbobr"  r   r   r   r   test_many_args  s    
z#TestCallbackManyArgs.test_many_argsN)r   r   r   rO   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S )TestCallbackCheckAbbrevc                 C   s    t  | _| jjdd| jd d S )N	--foo-barrt   ru   )r   r&   r   check_abbrevr   r   r   r   rO     s    
zTestCallbackCheckAbbrev.setUpc                 C   s   |  |d d S )Nr  r  r   r   r   r   r&   r   r   r   r    s    z$TestCallbackCheckAbbrev.check_abbrevc                 C   s   |  dgi g  d S )Nr  r"  r   r   r   r   test_abbrev_callback_expansion  s    z6TestCallbackCheckAbbrev.test_abbrev_callback_expansionN)r   r   r   rO   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 )Nr   rb   rq   r!  )rB   rr   r   rX   r   rR   r   rU  
--callbackrt   cr  r  )r   variable_argsr   r	   r&   r  r   r   r   rO     s    zTestCallbackVarArgs.setUpc                 C   s   |  |d u  g }|j}|r~|d }|d d dkr@t|dks~|d d dkrlt|dkrl|d dkrlq~q|| |d= qt|j|j| d S )Nr   rq   rU   rn   rC  )r2   r  r  r  r  r   r   )r   r   r   r   r&   r  argr   r   r   r    s     


z!TestCallbackVarArgs.variable_argsc                 C   s"   |  g ddd ddgdg  d S )N)z-a3r*  r  rZ   r[   )rd  r+  rZ   r[   r!  rR   r  r"  r   r   r   r   test_variable_args  s    
z&TestCallbackVarArgs.test_variable_argsc                 C   s$   |  g dd dg dddg d S )N)rU  37rU   xxxrX   helloT)r  rU   r  r  r  r"  r   r   r   r   %test_consume_separator_stop_at_option  s    
z9TestCallbackVarArgs.test_consume_separator_stop_at_optionc                 C   s$   |  g dd d g dddg d S )N)r  rU  rZ   rC  r[   )rZ   rC  r[   r  r  r"  r   r   r   r   %test_positional_arg_and_variable_args  s    
z9TestCallbackVarArgs.test_positional_arg_and_variable_argsc                 C   s    |  g dd ddgdg  d S )N)rU  rZ   rX   TrZ   r  r"  r   r   r   r   test_stop_at_option  s    
z'TestCallbackVarArgs.test_stop_at_optionc                 C   s   |  g dd d S )N)rU  rm  r*  r   zno such option: -5r  r   r   r   r   test_stop_at_invalid_option  s    z/TestCallbackVarArgs.test_stop_at_invalid_optionN)
r   r   r   rO   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 )Nr   r   ra   r   zincrement verbosityr]   r   r   r  r  r  r   r   r   rO   	  s    zConflictBase.setUpc                 C   s   d|j _d S )Nrn   )r   show_versionr  r   r   r   r    s    zConflictBase.show_versionN)r   r   r   rO   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)r   r   rt   show versionr]   rt   r   z5option -v/--version: conflicting option string(s): -vz conflicting option string(s): -vz-v/--version)r:   r  r   r)   r"   Z	option_id)r   r6   r9   r   r   r   assertTrueconflict_error  s    z%TestConflict.assertTrueconflict_errorc                 C   s   |  | jj d S r   )r  r&   r   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  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 )Nr   z'invalid conflict_resolution value 'foo')r:   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resolver   r   rt   r  r  )r  rO   r&   r  r   r  r   r   r   r   rO   -  s
    
zTestConflictResolve.setUpc                 C   s   | j d}| j d}| j d}| ||u  | ||u | |jdg | |jdg | |jdg | |jg  | |jdg d S )Nr   r   r   )r&   r   r2   r)   r   r   )r   ra  Zverbose_optZversion_optr   r   r   test_conflict_resolve3  s    z)TestConflictResolve.test_conflict_resolvec                 C   s   |  dgd d S )Nr   z}Options:
  --verbose      increment verbosity
  -h, --help     show this help message and exit
  -v, --version  show version
rD   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 )Nr   rn   r   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 )Nr   r   rn   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 )Nr   r   rn   r  r"  r   r   r   r   test_conflict_resolve_long_optsR  s    
z3TestConflictResolve.test_conflict_resolve_long_optsN)	r   r   r   rO   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 )NrL   r  r   	--dry-runr   dry_runzdon't do anythingr   r_  r   zdry run mode)r]   ro   r   r   )r   r	   r&   r  r   r   r   r   r   rO   X  s    

zTestConflictOverride.setUpc                 C   s0   | j d}| |jdg | |jdg d S )Nr  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 )Nr   zXOptions:
  -h, --help     show this help message and exit
  -n, --dry-run  dry run mode
r  r   r   r   r   test_conflict_override_helpg  s    z0TestConflictOverride.test_conflict_override_helpc                 C   s   |  dgddig  d S )Nr   r  r   r"  r   r   r   r   test_conflict_override_argsn  s    z0TestConflictOverride.test_conflict_override_argsN)r   r   r   rO   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 )NP   )make_parserr&   r   r   r   r   rO     s    zTestHelp.setUpc              	   C   sx   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W  d    S 1 sj0    Y  d S )Nr   r   r!  ZAPPLEzthrow APPLEs at basket)rB   r   metavarr   rX   r  rb   r  ZNUMzeshout "boo!" NUM times (in order to frighten away all the evil spirits that cause trouble and mayhem)r  r  rZ   z*store FOO in the foo list for later fooing)r]   rB   r   r   COLUMNSrM  )r   r   EnvironmentVarGuardr.   r   )r   columnsr,   envr   r   r   r    s    


zTestHelp.make_parserc              
   C   sX   t jd d  }z4tjddt jd< | dg| W |t jd d < n|t jd d < 0 d S )NrZ   zbar.pyr   r   )r?   r   r   r   r   rD   )r   r=   r   r   r   r   assertHelpEquals  s
    zTestHelp.assertHelpEqualsc                 C   s   |  t d S r   )r!  _expected_help_basicr   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_firstr   r   r   r   test_help_long_opts_first  s    
z"TestHelp.test_help_long_opts_firstc                 C   sH   t  ,}d|d< t | j_| t W d    n1 s:0    Y  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_linesr   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 )NrL   r   r      olé!r  uK   Options:
  -h, --help  show this help message and exit
  -a          olé!
)r   r	   r&   r   r!  r   expectr   r   r   test_help_unicode  s    zTestHelp.test_help_unicodec                 C   s    t tdd| _d}| | d S )Nr,  )rM   r  u>   olé!

Options:
  -h, --help  show this help message and exit
)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-gr   zGroup option.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   r   r  r!  epilog)r   r  r.  r   r   r   test_help_description_groups  s    
z%TestHelp.test_help_description_groupsN)r   r   r   rO   r  r!  r#  r$  r&  r(  r+  r/  r0  r2  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 )N--f)r8  r  --fier4  )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 )Nr4  )r8  r  r5  z,ambiguous option: --f (--fie, --foo, --foz?))r:   r   r   )r   r   Zwordmapr   r   r   test_match_abbrev_errorG  s    
z'TestMatchAbbrev.test_match_abbrev_errorN)r   r   r   r6  r7  r   r   r   r   r3  >  s   r3  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 )Nr   r   -l)r   r&   r   rb   r   r   r   r   rO   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 )Nrg   z!invalid literal for int().*: '?'?Z0xOoopsz*invalid literal for int().*: s?'?0xOoops'?)r:   r   rb   r   r0   compiler   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0b11rd  Z0b)r)   r   rb   r   r   r   r   test_parse_num_ok_  s    z!TestParseNumber.test_parse_num_okc                 C   s`   |  g ddddg  |  g ddddg  | dgd	 | d
gd | ddgd d S )N)r   r   r9  Z0x20r       )r   l)r   Z0b0101z-l010rG  r>  z-n008z'option -n: invalid integer value: '008'z-l0b0123z*option -l: invalid integer value: '0b0123'r9  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   rO   r;  r?  rB  r   r   r   r   r8  O  s   
r8  c                   @   s   e Zd Zdd ZdS )MiscTestCasec                 C   s   h d}t j| t|d d S )N>   Z
NO_DEFAULTZcheck_builtinZAmbiguousOptionError)	blacklist)r   Zcheck__all__optparse)r   rD  r   r   r   test__all__u  s    zMiscTestCase.test__all__N)r   r   r   rF  r   r   r   r   rC  t  s   rC  __main__)Fr?   r   r0   r   Zunittestior   r   r   rE  r   r   r   r   r   r	   r
   r   r   r   r   r   r   	Exceptionr   r   ZTestCaser%   rJ   r   r   r   r   r   r   r   r   r   r  rK  rT  r^  ru  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r"  r%  r'  r)  r*  r  r3  r8  rC  r   mainr   r   r   r   <module>	   st   4  O
3*N #:"+65
+!w%
