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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m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 ZG dd de	jZG dd deZefZedei 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 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Z.G d:d; d;eZ/G d<d= d=eZ0G d>d? d?eZ1G d@dA dAeZ2G dBdC dCeZ3G dDdE dEeZ4G dFdG dGeZ5G dHdI dIeZ6G dJdK dKeZ7G dLdM dMeZ8G dNdO dOeZ9G dPdQ dQeZ:G dRdS dSeZ;G dTdU dUeZ<G dVdW dWeZ=G dXdY dYeZ>G dZd[ d[eZ?G d\d] d]eZ@G d^d_ d_eZAG d`da daeZBG dbdc dceZCG ddde deeZDG dfdg dgeZEG dhdi dieZFG djdk dkeZGG dldm dmeZHG dndo doeZIG dpdq dqeZJG drds dseZKG dtdu dueZLG dvdw dweZMG dxdy dyeZNG dzd{ d{eZOG d|d} d}eZPG d~d deZQG dd deZRG dd deZSG dd deZTG dd deZUG dd deZVG dd deZWG dd deZXG dd deZYG dd deZZG dd deZ[G dd deZ\G dd deZ]G dd deZ^G dd deZ_G dd deZ`G dd deZaG dd deZbG dd deZcG dd deZdG dd deZeG dd deZfG dd deZgG dd deZhG dd deZiG dd deZjG dd deZkG dd deeZlG dd deeZmG dd deZnG dd dZoeodZpeodZqeodZrG dd deZsG dd deeZtG ddĄ deeZuG ddƄ deeZvG ddȄ deZwexeyedɃoez d kdʡG dd̄ deeZ{G dd΄ deeZ|G ddЄ deZ}G dd҄ deZ~G ddԄ deZG ddք deZG dd؄ deZG ddڄ deZG dd܄ deZG ddބ deZG dd deZG dd deZG dd deZG dd deZG dd deeZG dd deeZG dd deeZG dd deeZG dd deeZG dd deeZG dd deeZG dd deeZG dd deZG dd deeZG dd deeZG dd deeZG dd  d eeZG dd deeZG dd deeZG dd deeZG dd deeZG d	d
 d
eZG dd deZG dd deZG dd deZefZedei ZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZG d&d' d'eZG d(d) d)eZG d*d+ d+eZG d,d- d-eZG d.d/ d/eZG d0d1 d1eZG d2d3 d3eZG d4d5 d5eZG d6d7 d7eZG d8d9 d9eZG d:d; d;eZG d<d= d=eZG d>d? d?eZG d@dA dAeZG dBdC dCeZG dDdE dEeZG dFdG dGeZG dHdI dIeZG dJdK dKeZG dLdM dMeZG dNdO dOeZG dPdQ dQeZG dRdS dSeZG dTdU dUeZG dVdW dWeZG dXdY dYeZG dZd[ d[eZG d\d] d]eZG d^d_ d_eZG d`da daeZG dbdc dceZG ddde deeZG dfdg dgeZG dhdi dieZG djdk dkeZG dldm dmeZG dndo doeZG dpdq dqeZG drds dseZG dtdu dueZG dvdw dweZG dxdy dyeZG dzd{ d{eZG d|d} d}eZG d~d deZՐdd Zeאdkr6eփ  dS (      N)StringIO)support)mockc               @   s   e Zd ZdS )StdIOBufferN)__name__
__module____qualname__ r	   r	   #/usr/lib/python3.7/test_argparse.pyr      s   r   c               @   s   e Zd Zdd ZdS )TestCasec             C   s"   t  }|d | |j d S )NCOLUMNS)r   EnvironmentVarGuardZunset
addCleanup__exit__)selfenvr	   r	   r
   setUp   s    
zTestCase.setUpN)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S )TempDirMixinc             C   s$   t  | _t | _t| j d S )N)tempfileZmkdtemptemp_dirosgetcwdold_dirchdir)r   r	   r	   r
   r   "   s    

zTempDirMixin.setUpc             C   sf   t | j xFt j| jddD ]2\}}}x&|D ]}t t j| j|tj	 q.W qW t
| jd d S )NF)topdownT)r   r   r   walkr   chmodpathjoinstatS_IWRITEshutilZrmtree)r   rootdirsfilesnamer	   r	   r
   tearDown'   s
    
"zTempDirMixin.tearDownc          	   C   sB   t j| j|}t|d}|| W d Q R X t |tj d S )Nw)	r   r   r   r   openwriter   r   S_IREAD)r   filenameZ	file_pathfiler	   r	   r
   create_readonly_file.   s    z!TempDirMixin.create_readonly_fileN)r   r   r   r   r&   r-   r	   r	   r	   r
   r       s   r   c               @   s   e Zd Zdd ZdS )Sigc             O   s   || _ || _d S )N)argskwargs)r   r/   r0   r	   r	   r
   __init__6   s    zSig.__init__N)r   r   r   r1   r	   r	   r	   r
   r.   4   s   r.   c               @   s$   e Zd Zdd Zdd Zdd ZdS )NSc             K   s   | j | d S )N)__dict__update)r   r0   r	   r	   r
   r1   =   s    zNS.__init__c             C   s4   t | j }ddd |D }dt| j|f S )Nz, c             S   s   g | ]}d | qS )z%s=%rr	   ).0tupr	   r	   r
   
<listcomp>B   s    zNS.__repr__.<locals>.<listcomp>z%s(%s))sortedr3   itemsr   typer   )r   Zsorted_itemsZ	kwarg_strr	   r	   r
   __repr__@   s    zNS.__repr__c             C   s   t | t |kS )N)vars)r   otherr	   r	   r
   __eq__E   s    z	NS.__eq__N)r   r   r   r1   r;   r>   r	   r	   r	   r
   r2   ;   s   r2   c               @   s   e Zd ZdddZdS )ArgumentParserErrorNc             C   s,   t | ||| || _|| _|| _|| _d S )N)	Exceptionr1   messagestdoutstderr
error_code)r   rA   rB   rC   rD   r	   r	   r
   r1   K   s
    zArgumentParserError.__init__)NNN)r   r   r   r1   r	   r	   r	   r
   r?   I   s   r?   c       
      O   s   t tjtst tjtr"| ||S tj}tj}t t_t t_zy\| ||}xLtt|D ]<}t||tjkrzt||| t||tjkrZt||| qZW |S  t	k
r   t
 d j}tj }tj }	td||	|Y nX W d |t_|t_X d S )N   
SystemExit)
isinstancesysrC   r   rB   listr<   getattrsetattrrF   exc_infocodegetvaluer?   )

parse_argsr/   r0   Z
old_stdoutZ
old_stderrresultkeyrM   rB   rC   r	   r	   r
   stderr_to_parser_errorS   s,    



rR   c                   s4   e Zd Z fddZ fddZ fddZ  ZS )ErrorRaisingArgumentParserc                s   t t| j}t|f||S )N)superrS   rO   rR   )r   r/   r0   rO   )	__class__r	   r
   rO   u   s    z%ErrorRaisingArgumentParser.parse_argsc                s   t t| j}t|f||S )N)rT   rS   exitrR   )r   r/   r0   rV   )rU   r	   r
   rV   y   s    zErrorRaisingArgumentParser.exitc                s   t t| j}t|f||S )N)rT   rS   errorrR   )r   r/   r0   rW   )rU   r	   r
   rW   }   s    z ErrorRaisingArgumentParser.error)r   r   r   rO   rV   rW   __classcell__r	   r	   )rU   r
   rS   s   s   rS   c               @   s   e Zd ZdZdd ZdS )ParserTesterMetaclassa}  Adds parser tests using the class attributes.

    Classes of this type should specify the following attributes:

    argument_signatures -- a list of Sig objects which specify
        the signatures of Argument objects to be created
    failures -- a list of args lists that should cause the parser
        to fail
    successes -- a list of (initial_args, options, remaining_args) tuples
        where initial_args specifies the string args to be parsed,
        options is a dict that should match the vars() of the options
        parsed out of initial_args, and remaining_args should be any
        remaining unparsed arguments
    c             C   s   |dkrd S t | dst | _t | ds.t| _dd }dd }dd	 }d
d }dd }G dd dt}	x0|||gD ]"}
x||gD ]}|	| |
| qW qrW d S )NParserTestCaseparser_signatureparser_classc             S   s"   x|D ]}| j |j|j qW dS )z(Add all arguments directly to the parserN)add_argumentr/   r0   )parserargument_signaturessigr	   r	   r
   	no_groups   s    
z1ParserTesterMetaclass.__init__.<locals>.no_groupsc             S   s,   |  d}x|D ]}|j|j|j qW dS )z4Add all arguments under a single group in the parserfooN)add_argument_groupr]   r/   r0   )r^   r_   groupr`   r	   r	   r
   	one_group   s    

z1ParserTesterMetaclass.__init__.<locals>.one_groupc             S   s8   x2t |D ]&\}}| d| }|j|j|j q
W dS )z0Add each argument in its own group to the parserzfoo:%iN)	enumeraterc   r]   r/   r0   )r^   r_   ir`   rd   r	   r	   r
   many_groups   s    z3ParserTesterMetaclass.__init__.<locals>.many_groupsc             S   s
   |  |S )z#Parse the args by passing in a list)rO   )r^   r/   r	   r	   r
   listargs   s    z0ParserTesterMetaclass.__init__.<locals>.listargsc             S   s,   t j}|d g| t _z|  S |t _X dS )z(Parse the args by defaulting to sys.argvr   N)rH   argvrO   )r^   r/   Zold_sys_argvr	   r	   r
   sysargs   s
    z/ParserTesterMetaclass.__init__.<locals>.sysargsc               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
z0ParserTesterMetaclass.__init__.<locals>.AddTestsc          	   S   s   || _ || _| j j}| jj}xf| j| jgD ]V}|j}|||f}d|}	|fdd}
y
|	|
_W n tk
rr   Y nX t||	|
 q*W d S )N_c             S   s   ||  d S )Nr	   )r   	test_funcr	   r	   r
   wrapper   s    zJParserTesterMetaclass.__init__.<locals>.AddTests.__init__.<locals>.wrapper)_add_arguments_parse_argsr   test_failurestest_successesr   	TypeErrorrK   )r   Z
tester_clsadd_argumentsrO   Zadd_arguments_nameZparse_args_namerm   Z	func_namenames	test_namern   r	   r	   r
   r1      s    


z9ParserTesterMetaclass.__init__.<locals>.AddTests.__init__c             S   s.   |j j}|j j}|j||}| ||j |S )N)r[   r/   r0   r\   ro   r_   )r   testerr/   r0   r^   r	   r	   r
   _get_parser   s
    z<ParserTesterMetaclass.__init__.<locals>.AddTests._get_parserc          
   S   sJ   |  |}x:|jD ]0}| }|jt|d || W d Q R X qW d S )N)msg)rx   failuressplitassertRaisesr?   rO   )r   rw   r^   args_strr/   r	   r	   r
   rq      s
    
z>ParserTesterMetaclass.__init__.<locals>.AddTests.test_failuresc             S   sL   |  |}x<|jD ]2\}}t|tr,| }| ||}||| qW d S )N)rx   	successesrG   strr{   rp   assertEqual)r   rw   r^   r/   expected_nsZ	result_nsr	   r	   r
   rr      s    

z?ParserTesterMetaclass.__init__.<locals>.AddTests.test_successesN)r   r   r   r1   rx   rq   rr   r	   r	   r	   r
   AddTests   s   r   )hasattrr.   r[   rS   r\   object)clsr%   basesbodydictra   re   rh   ri   rk   r   rt   rO   r	   r	   r
   r1      s    

	-zParserTesterMetaclass.__init__N)r   r   r   __doc__r1   r	   r	   r	   r
   rY      s   rY   rZ   c               @   sh   e Zd ZdZedgZdddddgZdedd	fd
edd	fdedd	fdedd	fdedd	fgZdS )TestOptionalsSingleDashz1Test an Optional with a single-dash option stringz-xaz--fooz-x --fooz-x -y N)xz-x az-xaz-x -1z-1z-x-1)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r      s   
r   c               @   s  e Zd ZdZedddedddded	gZd
ddddddddddgZdeddddfdeddddfdeddd
dfdeddd
dfdeddd
dfdeddd
dfdeddd
dfdeddd
dfd eddddfdeddddfd!eddd
dfd"eddd
dfgZdS )#TestOptionalsSingleDashCombinedz1Test an Optional with a single-dash option stringz-x
store_true)actionz-yyystore_const*   )r   constz-zr   z--fooz-xaz-x --fooz-x -zz-z -xz-yxz-yz az-yyyxz-yyyzaz-xyzar   FN)r   yyyzTz-zaz-z az-xzaz-xz az-x -zaz-x -z az-yz-x -yyy -zaz-x -yyy -z a)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s$   

r   c               @   sj   e Zd ZdZedgZddddddgZded	d
fdedd
fdedd
fdedd
fdedd
fgZd	S )TestOptionalsSingleDashLongzATest an Optional with a multi-character single-dash option stringz-foor   z--fooz
-foo --fooz-foo -yz-fooar   N)rb   z-foo az-foo -1z-1z-fo az-f a)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   "  s   
r   c               @   s   e Zd ZdZedededgZdddddd	d
gZdeddddfdeddddfdeddddfdeddddfdeddddfdeddddfdeddddfgZdS )&TestOptionalsSingleDashSubsetAmbiguousz=Test Optionals where option strings are subsets of each otherz-fz-foobarz-foorabz-fooz-foz-foo bz-foobz-foobaz-foorar   N)ffoobarfoorabz-f ar   z-faz-foaZoaz-fooaZooaz	-foobar az	-foorab a)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   0  s   r   c               @   s   e Zd ZdZededgZdddddd	d
gZdedddfdedddfdedddfdedddfdedddfdedddfdedddfgZdS ) TestOptionalsSingleDashAmbiguousz7Test Optionals that partially match but are not subsetsz-foobarz-foorabz-fz-f az-faz-foaz-fooz-foz-foo br   N)r   r   z-foob ar   z-foor az-fooba az-foora az	-foobar az	-foorab a)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   @  s   r   c               @   sb   e Zd ZdZedddgZdddddd	gZd
eddfdeddfdeddfdeddfgZdS )TestOptionalsNumericz(Test an Optional with a short opt stringz-1one)destr   z-1 --fooz-1 -yz-1 -1z-1 -2r   N)r   z-1 az-1az-1-2z-2)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   P  s   r   c               @   sj   e Zd ZdZedgZddddddgZded	d
fdedd
fdedd
fdedd
fdedd
fgZd	S )TestOptionalsDoubleDashz1Test an Optional with a double-dash option stringz--fooz-fz-f ar   z--foo -xz--foo --barr   N)rb   z--foo az--foo=az
--foo -2.5z-2.5z
--foo=-2.5)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   ]  s   
r   c            
   @   s   e Zd ZdZedddedgZdddd	d
dgZdedddfdedddfdedddfdedddfdedddfdedddfgZdS )#TestOptionalsDoubleDashPartialMatchz7Tests partial matching with a double-dash option stringz--badgerr   )r   z--batz--barz--bz--baz--b=2z--ba=4z	--badge 5r   FN)badgerZbatz--bat XXz--badTz--badgz--badge)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   k  s   

r   c               @   s   e Zd ZdZedddedgZddddd	gZd
edddfdedddfdedddfdedddfdedddfdedddfdedddfgZdS )"TestOptionalsDoubleDashPrefixMatchz?Tests when one double-dash option string is a prefix of anotherz--badgerr   )r   z--baz--barz--bz--b=2z	--badge 5r   FN)r   Zbaz--ba Xr   z--ba=Xz--badTz--badgz--badge)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   }  s   

r   c               @   s   e Zd ZdZedddededddd	gZdd
ddddgZdeddddfdeddddfdeddddfdeddddfdeddddfdeddddfgZdS )TestOptionalsSingleDoubleDashz<Test an Optional with single- and double-dash option stringsz-fr   )r   z--barz-bazr   r   )r   r   z-fbarz-fbazz-bazfz-b BBr   FN)r   barbazTz--ba Bz
-f --bar Bz-f -bz-ba -f)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   
r   c               @   s   e Zd ZdZedddZedddeded	d
ddgZddddddddddddgZdeddddfdeddddfdeddddfdeddddfdeddddfd eddddfgZ	dS )!!TestOptionalsAlternatePrefixCharsz9Test an Optional with option strings with custom prefixesz+:/F)prefix_charsadd_helpz+fr   )r   z::barz/bazr   r   )r   r   z--barz-fbarz-b Br   z-fz--bar Bz-bazz-hz--helpz+hz::helpz/helpr   N)r   r   r   Tz::ba Bz
+f ::bar Bz+f /bz/ba +f)
r   r   r   r   r.   r[   r_   rz   r2   r~   r	   r	   r	   r
   r     s   
r   c               @   s   e Zd ZdZedddZedddeded	d
ddgZdddddddgZdeddddfdeddddfdeddddfdeddddfdeddddfdeddddfgZ	dS )*TestOptionalsAlternatePrefixCharsAddedHelpzWhen ``-`` not in prefix_chars, default operators created for help
       should use the prefix_chars in use rather than - or --
       http://bugs.python.org/issue9444z+:/T)r   r   z+fr   )r   z::barz/bazr   r   )r   r   z--barz-fbarz-b Br   z-fz--bar Bz-bazr   FN)r   r   r   z::ba Bz
+f ::bar Bz+f /bz/ba +f)
r   r   r   r   r.   r[   r_   rz   r2   r~   r	   r	   r	   r
   r     s   
r   c            	   @   s   e Zd ZdZedddZedddeddded	ddgZd
ddddgZdeddddfdeddddfdeddddfdeddddfgZ	dS )2TestOptionalsAlternatePrefixCharsMultipleShortArgsz@Verify that Optionals must be called with their defined prefixesz+-F)r   r   z-xr   )r   z+yz+zz-wz-xyzz+xz-yz+xyzr   )r   yr   Tz+y -xz+yz -xN)
r   r   r   r   r.   r[   r_   rz   r2   r~   r	   r	   r	   r
   r     s   

r   c               @   sp   e Zd ZdZeddddddgZdd	d
dgZdeddfdeddfdeddfdeddfdeddfgZdS )TestOptionalsShortLongz<Test a combination of single- and double-dash option stringsz-vz	--verbosez-nz--noisyr   )r   z--x --verbosez-Nr   z-v xr   F)verboseTN)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   sf   e Zd ZdZededddgZdgZdedd	d
fded	dd
fdeddd
fdeddd
fgZd	S )TestOptionalsDestz*Tests various means of setting destinationz	--foo-barz--bazzabbaz)r   r   z--foo-bar fr   N)Zfoo_barr   z--baz ggz--foo-bar h --baz ihrg   z--baz j --foo-bar kkj)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   sX   e Zd ZdZededddgZdgZdeddd	fd
eddd	fdeddd	fgZdS )TestOptionalsDefaultz*Tests specifying a default for an Optionalz-xz-yr   )defaultr   r   N)r   r   z-xxr   z-yyr   )	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   s>   e Zd ZdZedgZddgZdeddfdeddfgZdS )TestOptionalsNargsDefaultz7Tests not specifying the number of args for an Optionalz-xr   r   N)r   z-x a)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   
r   c               @   sD   e Zd ZdZedddgZddgZdeddfd	edgdfgZdS )
TestOptionalsNargs1z&Tests specifying 1 arg for an Optionalz-xrE   )nargsr   r   N)r   z-x a)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   r   c               @   sP   e Zd ZdZedddgZdddddd	gZd
eddfdedddgdfgZdS )TestOptionalsNargs3z'Tests specifying 3 args for an Optionalz-x   )r   r   z-x az-x a bza -xza -x br   N)r   z-x a b cbc)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   #  s
   r   c               @   s   e Zd ZdZedddeddddeddd	d
eddedddgZdgZdeddd	ddfdeddd	ddfdeddd	ddfdeddd	ddfdeddd	ddfdedddddfdedddddfdeddd	ddfdeddd	ddfg	Z	dS )TestOptionalsNargsOptionalz0Tests specifying an Optional arg for an Optionalz-w?)r   z-xr   )r   r   z-yspam)r   r   z-z42Z84)r   r:   r   r   2r   NT   )r'   r   r   r   z-w 2z-x 2z-y 2z-z 2   )
r   r   r   r   r.   intr_   rz   r2   r~   r	   r	   r	   r
   r   .  s   
r   c               @   s   e Zd ZdZedddeddddgZdgZd	ed
ddfdeg ddfdedgddfdeddgddfded
g dfded
dgdfded
ddgdfgZd
S )TestOptionalsNargsZeroOrMorez?Tests specifying args for an Optional that accepts zero or morez-x*)r   z-yr   )r   r   r   r   N)r   r   z-x az-x a br   z-y az-y a b)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   E  s   
r   c            	   @   s   e Zd ZdZedddeddddgZdddd	d
gZdedddfdedgddfdeddgddfdeddgdfdedddgdfgZdS )TestOptionalsNargsOneOrMorez>Tests specifying args for an Optional that accepts one or morez-x+)r   z-yr   )r   r   r   za -xza -y br   N)r   r   z-x az-x a br   z-y az-y a b)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   X  s   
r   c            
   @   s   e Zd ZdZedddedeeddgZdd	d
ddgZde	dddfde	dddfde	dddfde	dddfde	dddfde	dddfgZ
dS )TestOptionalsChoicesz,Tests specifying the choices for an Optionalz-fabc)choicesz-g   )r:   r   r   z-f dz-fadz-gaz-g 6r   N)r   r   z-f az-f cr   z-g 0r   z-g 03r   z-fb -g4r      )r   r   r   r   r.   r   ranger_   rz   r2   r~   r	   r	   r	   r
   r   i  s   
r   c               @   sD   e Zd ZdZededdgZddgZdedd	fd
edd	fgZ	dS )TestOptionalsRequiredz)Tests an optional action that is requiredz-xT)r:   requiredr   r   z-x 1rE   )r   z-x42r   N)
r   r   r   r   r.   r   r_   rz   r2   r~   r	   r	   r	   r
   r   z  s
   r   c               @   sB   e Zd ZdZedddgZddgZdedd	fd
edd	fgZdS )TestOptionalsActionStorez&Tests the store action for an Optionalz-xstore)r   r   za -xr   N)r   z-xfoorb   )	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   r   c               @   sB   e Zd ZdZeddedgZdgZdeddfdeedfgZ	dS )	TestOptionalsActionStoreConstz,Tests the store_const action for an Optionalz-yr   )r   r   r   r   N)r   )
r   r   r   r   r.   r   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   r   c               @   sD   e Zd ZdZedddgZdddgZded	d
fdedd
fgZdS )TestOptionalsActionStoreFalsez,Tests the store_false action for an Optionalz-zstore_false)r   r   z-zaz-z ar   T)r   FN)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   
r   c               @   sD   e Zd ZdZedddgZdddgZded	d
fdedd
fgZdS )TestOptionalsActionStoreTruez+Tests the store_true action for an Optionalz--appler   )r   r   z	--apple=bz	--apple br   F)ZappleTN)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   
r   c               @   sX   e Zd ZdZedddgZddddgZded	d
fdedgd
fdeddgd
fgZd	S )TestOptionalsActionAppendz'Tests the append action for an Optionalz--bazappend)r   r   za --bazz	--baz a br   N)r   z--baz az--baz a --baz br   )	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   sb   e Zd ZdZedddgdgZddddgZd	edgd
fdeddgd
fdedddgd
fgZdS )$TestOptionalsActionAppendWithDefaultz'Tests the append action for an Optionalz--bazr   r   )r   r   r   za --bazz	--baz a br   )r   z--baz az--baz a --baz br   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   sl   e Zd ZdZeddededdddgZd	dd
ddgZdeddfdeegdfdeededgdfgZ	dS )TestOptionalsActionAppendConstz-Tests the append_const action for an Optionalz-bappend_const)r   r   z-cr   r   )r   r   r   za -cz-bxz-b xr   N)r   z-b -cx -b -cyzr   yz)
r   r   r   r   r.   r@   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c            	   @   sv   e Zd ZdZeddedgdedddd	gZd
ddddgZdedgdfdedegdfdedededgdfgZ	dS ))TestOptionalsActionAppendConstWithDefaultz-Tests the append_const action for an Optionalz-br   r   )r   r   r   z-cr   r   )r   r   r   za -cz-bxz-b xr   )r   z-b -cx -b -cyzr   r   N)
r   r   r   r   r.   r@   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   sF   e Zd ZdZedddgZddddgZd	ed
dfdeddfgZd
S )TestOptionalsActionCountz&Tests the count action for an Optionalz-xcount)r   r   z-x az-x bz	-x a -x br   N)r   rE   )	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   r   c            	   @   sv   e Zd ZdZedededddgZddgZd	ed
d
ddfdedd
ddfded
dddfdedd
ddfgZd
S )"TestOptionalsAllowLongAbbreviationz2Allow long options to be abbreviated unambiguouslyz--fooz--foobazz--foobler   )r   z--foob 5z--foobr   NF)rb   ZfoobazZfooblez--foo 77z	--fooba ar   z--foobl --foo gr   T)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   st   e Zd ZdZeddZededddedgZd	d
ddgZdeddddfdeddddfdeddddfgZ	dS )%TestOptionalsDisallowLongAbbreviationz1Do not allow abbreviations of long options at allF)allow_abbrevz--fooz--foodler   )r   z--foonlyz-foon 3z--foon 3z--foodz--food --foo 2r   N)rb   ZfoodleZfoonlyz--foo 33z--foonly 7 --foodle --foo 2r   Tr   )
r   r   r   r   r.   r[   r_   rz   r2   r~   r	   r	   r	   r
   r     s   


r   c               @   s4   e Zd ZdZedgZdddgZdeddfgZdS )	TestPositionalsNargsNonez,Test a Positional that doesn't specify nargsrb   r   z-xza br   )rb   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   

r   c               @   s:   e Zd ZdZedddgZdddgZdedgd	fgZd
S )TestPositionalsNargs1z.Test a Positional that specifies an nargs of 1rb   rE   )r   r   z-xza br   )rb   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   #  s   
r   c               @   s>   e Zd ZdZedddgZddddgZd	edd
gdfgZdS )TestPositionalsNargs2z.Test a Positional that specifies an nargs of 2rb   r   )r   r   r   z-xza b cza br   )rb   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   -  s   r   c               @   sR   e Zd ZdZedddgZdgZdeg dfdedgdfd	edd
gdfgZdS )TestPositionalsNargsZeroOrMorez0Test a Positional that specifies unlimited nargsrb   r   )r   z-xr   )rb   r   za br   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   7  s   r   c               @   sT   e Zd ZdZeddddgZdgZdeddfd	ed	gdfd
ed	dgdfgZdS )%TestPositionalsNargsZeroOrMoreDefaultz>Test a Positional that specifies unlimited nargs and a defaultrb   r   r   )r   r   z-xr   )rb   r   za br   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   C  s   r   c               @   sH   e Zd ZdZedddgZddgZdedgdfd	edd
gdfgZdS )TestPositionalsNargsOneOrMorez2Test a Positional that specifies one or more nargsrb   r   )r   r   z-xr   )rb   za br   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   O  s
   r   c               @   sB   e Zd ZdZedddgZddgZdedd	fd
ed
d	fgZdS )TestPositionalsNargsOptionalzTests an Optional Positionalrb   r   )r   z-xza br   N)rb   r   )	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   Z  s
   r   c               @   sD   e Zd ZdZeddddgZddgZdedd	fd
ed
d	fgZdS )#TestPositionalsNargsOptionalDefaultz1Tests an Optional Positional with a default valuerb   r   r   )r   r   z-xza br   )rb   r   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   e  s
   r   c               @   sH   e Zd ZdZeddeddgZdddgZd	ed
dfdeddfgZ	dS ),TestPositionalsNargsOptionalConvertedDefaultznTests an Optional Positional with a default value
    that needs to be converted to the appropriate type.
    rb   r   r   )r   r:   r   z-xza bz1 2r   r   )rb   1rE   N)
r   r   r   r   r.   r   r_   rz   r2   r~   r	   r	   r	   r
   r   p  s
   
r   c               @   s>   e Zd ZdZededgZddddgZdedd	d
fgZdS )TestPositionalsNargsNoneNonez-Test two Positionals that don't specify nargsrb   r   r   z-xr   za b cza br   )rb   r   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   sD   e Zd ZdZededddgZdddd	gZd
eddgdfgZdS )TestPositionalsNargsNone1z6Test a Positional with no nargs followed by one with 1rb   r   rE   )r   r   z--foor   za b cza br   )rb   r   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   sH   e Zd ZdZedddedgZdddd	d
gZdeddgddfgZdS )TestPositionalsNargs2Nonez8Test a Positional with 2 nargs followed by one with nonerb   r   )r   r   r   z--foor   za bza b c dza b cr   r   )rb   r   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   s`   e Zd ZdZededddgZddgZdedg d	fd
eddgd	fdedddgd	fgZdS )"TestPositionalsNargsNoneZeroOrMorez>Test a Positional with no nargs followed by one with unlimitedrb   r   r   )r   r   z--foor   )rb   r   za br   za b cr   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   sT   e Zd ZdZededddgZdddgZd	edd
gdfdedd
dgdfgZdS )!TestPositionalsNargsNoneOneOrMorez@Test a Positional with no nargs followed by one with one or morerb   r   r   )r   r   z--foor   za br   )rb   r   za b cr   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   
r   c               @   sN   e Zd ZdZededddgZdddgZd	ed	d
dfded	ddfgZd
S ) TestPositionalsNargsNoneOptionalz@Test a Positional with no nargs followed by one with an Optionalrb   r   r   )r   r   z--fooza b cr   N)rb   r   za br   )	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   
r   c               @   s`   e Zd ZdZedddedgZddgZdeg dd	fd
edgdd	fdeddgdd	fgZdS )"TestPositionalsNargsZeroOrMoreNonez@Test a Positional with unlimited nargs followed by one with nonerb   r   )r   r   r   z--foor   )rb   r   za br   za b cr   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   sT   e Zd ZdZedddedgZdddgZd	edgd
dfdedd
gddfgZdS )!TestPositionalsNargsOneOrMoreNonezBTest a Positional with one or more nargs followed by one with nonerb   r   )r   r   r   z--foor   za br   )rb   r   za b cr   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   
r   c               @   sP   e Zd ZdZeddddedgZddd	gZd
edd
dfded
ddfgZdS ) TestPositionalsNargsOptionalNonezBTest a Positional with an Optional nargs followed by one with nonerb   r   r   )r   r   r   r   z--fooza b cr   )rb   r   za br   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   
r   c               @   s\   e Zd ZdZedddedddgZddd	gZd
ed	dgg dfded	dgdgdfgZdS )TestPositionalsNargs2ZeroOrMorez=Test a Positional with 2 nargs followed by one with unlimitedrb   r   )r   r   r   r   z--foor   za br   )rb   r   za b cr   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   
r   c               @   sL   e Zd ZdZedddedddgZddd	d
gZded	dgdgdfgZdS )TestPositionalsNargs2OneOrMorez?Test a Positional with 2 nargs followed by one with one or morerb   r   )r   r   r   r   z--foor   za bza b cr   r   )rb   r   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   s\   e Zd ZdZedddedddgZddd	d
gZded	dgddfded	dgddfgZdS )TestPositionalsNargs2Optionalz7Test a Positional with 2 nargs followed by one optionalrb   r   )r   r   r   r   z--foor   za b c dza br   N)rb   r   za b cr   )	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   r   c               @   sj   e Zd ZdZedddedddgZddgZd	eg d	gd
fded	gdgd
fded	dgdgd
fgZdS )TestPositionalsNargsZeroOrMore1z=Test a Positional with unlimited nargs followed by one with 1rb   r   )r   r   rE   r   z--foor   )rb   r   za br   za b cr   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s   r   c               @   s\   e Zd ZdZedddedddgZddd	gZd
ed	gdgdfded	dgdgdfgZdS )TestPositionalsNargsOneOrMore1z?Test a Positional with one or more nargs followed by one with 1rb   r   )r   r   rE   r   z--foor   za br   )rb   r   za b cr   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   
r   c               @   sV   e Zd ZdZedddedddgZddd	gZd
edd
gdfded
dgdfgZdS )TestPositionalsNargsOptional1z?Test a Positional with an Optional nargs followed by one with 1rb   r   )r   r   rE   r   z--fooza b cr   N)rb   r   za br   )	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r     s
   
r   c               @   sb   e Zd ZdZededddedddgZdd	d
gZded
g dgdfded
dgdgdfgZdS )#TestPositionalsNargsNoneZeroOrMore1z=Test three Positionals: no nargs, unlimited nargs and 1 nargsrb   r   r   )r   r   rE   r   z--foor   za br   )rb   r   r   za b cr   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   #  s   

r   c               @   sh   e Zd ZdZededddedddgZdd	d
dgZded
dgdgdfded
ddgdgdfgZdS )"TestPositionalsNargsNoneOneOrMore1z?Test three Positionals: no nargs, one or more nargs and 1 nargsrb   r   r   )r   r   rE   r   z--foor   r   za b cr   )rb   r   r   za b c ddN)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r   2  s   
r   c               @   sb   e Zd ZdZededdddeddd	gZd
ddgZdedddgdfdedddgdfgZdS )!TestPositionalsNargsNoneOptional1z;Test three Positionals: no nargs, optional narg and 1 nargsrb   r   r   g      ?)r   r   r   rE   )r   r   z--foor   za br   )rb   r   r   za b cr   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r  A  s   
r  c               @   s`   e Zd ZdZedddeddddgZdd	gZd
edddfdedddfdedddfgZdS )$TestPositionalsNargsOptionalOptionalzTest two optional nargsrb   r   )r   r   r   )r   r   z--fooza b cr   N)rb   r   r   za br   )	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r  P  s   
r  c               @   sp   e Zd ZdZedddedddgZdgZded	g d
fdedg d
fdeddgd
fdedddgd
fgZd	S )&TestPositionalsNargsOptionalZeroOrMorez1Test an Optional narg followed by unlimited nargsrb   r   )r   r   r   z--foor   N)rb   r   r   za br   za b cr   )	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r  _  s   r  c               @   sf   e Zd ZdZedddedddgZddgZd	ed
d	gdfded	dgdfded	ddgdfgZd
S )%TestPositionalsNargsOptionalOneOrMorez3Test an Optional narg followed by one or more nargsrb   r   )r   r   r   r   z--foor   N)rb   r   za br   za b cr   )	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r  l  s   r  c               @   sL   e Zd ZdZededdgZddddd	gZd
ed
dfdeddfgZ	dS )TestPositionalsChoicesStringz&Test a set of single-character choicesr   Zabcdefg)r   r   z--foor   r   efr   )r   r   N)
r   r   r   r   r.   setr_   rz   r2   r~   r	   r	   r	   r
   r  x  s
   r  c               @   sN   e Zd ZdZedeeddgZddddd	gZd
e	ddfde	ddfgZ
dS )TestPositionalsChoicesIntzTest a set of integer choicesr      )r:   r   r   z--foor   r   r  4r   )r   15   N)r   r   r   r   r.   r   r   r_   rz   r2   r~   r	   r	   r	   r
   r	    s
   r	  c               @   sP   e Zd ZdZedddeddddgZddd	d
dgZded	ddggdfgZdS )TestPositionalsActionAppendzTest the 'append' actionr   r   )r   r   )r   r   r   z--foor   za bza b c dza b cr   r   )r   N)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r    s
   
r  c               @   sn   e Zd ZdZedddeddddgZd	d
gZdedddfdedddfdedddfdedddfgZdS )"TestOptionalsNumericAndPositionalsz;Tests negative number args when numeric options are presentr   r   )r   z-4r   r   )r   r   z-2z-315r   NF)r   r   r   Tz-4 a)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r    s   
r  c            	   @   sz   e Zd ZdZedddeddddgZd	gZd
edddfdedddfdedddfdedddfdedddfgZdS )(TestOptionalsAlmostNumericAndPositionalszBTests negative number args when almost numeric options are presentr   r   )r   z-k4r   r   )r   r   z-k3r   NF)r   r   z-2r   Tz-k4 a)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r    s   
r  c               @   s   e Zd ZedddeddddgZdgZdgedd	d
fdgedd	d
fdgedd	d
fddged	dd
fddged	dd
fddged	dd
fdged	dd
fdged	dd
fgZd	S )$TestEmptyAndSpaceContainingArgumentsr   r   )r   z-yz--yyyr   )r   r   N)r   r   za badgerz	-a badgerz--yyy=a badgerz--yyy=-a badger)r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r    s   
r  c               @   s   e Zd ZeddZedddddedd	ed
deddddgZddgZdedd
ddfdedd
ddfdedd
ddfdeddddfdedd
ddfdedd
ddfgZ	dS ) TestPrefixCharacterOnlyArgumentsz-+)r   -r   r   r   )r   r   r   r   r   r   )r   r:   r   z-+-r   r   )r   r   z-yz+ -r   NF)r   r   r   z- Xr   z+ -3Tz- ===z===)
r   r   r   r.   r[   r   r_   rz   r2   r~   r	   r	   r	   r
   r    s   
r  c               @   s   e Zd ZdZedddedddgZg Zdedg dfdeg g dfd	ed
gg dfded
gdgdfd
edd
gdfdeg d
gdfdedgd
gdfgZdS )TestNargsZeroOrMorez?Tests specifying args for an Optional that accepts zero or morez-xr   )r   r   r   N)r   r   z-x ar   z	-x a -- br   za -xza -x b)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r    s   r  c            	   @   s   e Zd ZdZededddedgZdddgZd	ed	g d
dfded	g ddfded	ddddgd
dfded	ddgd
dfgZd
S )TestNargsRemainderz2Tests specifying a positional with nargs=REMAINDERr   r   z...)r   z-zr   z-z Zr   N)r   r   r   z-z Z XZz
X A B -z ZAr   z	X Y --fooYz--foo)	r   r   r   r   r.   r_   rz   r2   r~   r	   r	   r	   r
   r    s   
r  c               @   s  e Zd ZdZededededdeddd	gZdd
dddddddddddgZdeddg dfdeddg dfdedddgdfdeddg dfdedd g dfd!eddg dfd"edddgdfdedddgdfd#ed$ddgdfd%ed$ddgdfd&edd$dgdfgZ	dS )'TestOptionLikez.Tests options that may or may not be argumentsz-x)r:   z-3r   )r:   r   r   r   )r   z-y2.5z-xaz-x -az-x -3z-x -3.5z-3 -3.5z-x -2.5z	-x -2.5 az-3 -.5za x -1z-x -1 az-3 -1 ar   N)r   r   r   z-x 2.5g      @z-x 2.5 ar   z-3.5g      ?z-3-.5g      z-3 .5za -3.5za -x 1g      ?z-x 1 az-3 1 a)
r   r   r   r   r.   floatr_   rz   r2   r~   r	   r	   r	   r
   r    s&   

r  c               @   s   e Zd ZdZeddejdeddejdeddejd	gZd
gZde	 fde	ddfde	ddgdfde	ddfde	dddfde	ddgddfgZ
dS )TestDefaultSuppressz%Test actions with suppressed defaultsrb   r   )r   r   r   r   z--bazr   )r   r   z-xr   r   )rb   za br   )rb   r   T)r   za --baz)rb   r   z	--baz a b)rb   r   r   N)r   r   r   r   r.   argparseSUPPRESSr_   rz   r2   r~   r	   r	   r	   r
   r    s   r  c               @   s   e Zd ZdZeejdZedddedddedd	d
gZdgZ	de
 fde
ddfde
ddgdfde
ddfde
dddfde
ddgddfgZdS )TestParserDefaultSuppressz4Test actions with a parser-level default of SUPPRESS)argument_defaultrb   r   )r   r   r   z--bazr   )r   z-xr   r   )rb   za br   )rb   r   T)r   za --baz)rb   r   z	--baz a b)rb   r   r   N)r   r   r   r   r.   r  r  r[   r_   rz   r2   r~   r	   r	   r	   r
   r  0  s   

r  c               @   s   e Zd ZdZeddZeddddedd	d
eddd
edddgZdgZdedddddfdedddddfdeddgdddfdedddddfdedddddfdeddgdddfgZ	dS )TestParserDefault42z.Test actions with a parser-level default of 42r   )r   z	--versionversionz1.0)r   r"  rb   r   )r   r   r   z--bazr   )r   z-xr   )rb   r   r   r"  r   za br   Tza --bazz	--baz a bN)
r   r   r   r   r.   r[   r_   rz   r2   r~   r	   r	   r	   r
   r!  D  s   


r!  c                   s   e Zd ZdZ fddZeddZedededd	d
gZdddddgZde	dddgdfde	ddddgdfde	dddgdfde	dddgdfde	ddddgdfde	ddddgdfddddge	dddgdfgZ
  ZS )TestArgumentsFromFilez"Test reading arguments from a filec                sJ   t t|   dddg}x,|D ]$\}}t|d}|| |  qW d S )N)hellozhello world!
)	recursivez-a
A
@hello)Zinvalidz@no-such-path
r'   )rT   r#  r   r(   r)   close)r   
file_textsr   textr,   )rU   r	   r
   r   \  s    

zTestArgumentsFromFile.setUp@)fromfile_prefix_charsz-ar   r   r   )r   r   z-br   z@invalidz@missingzX YNr  )r   r   r   z
X -a A Y Zr  r  z@hello Xzhello world!zX @helloz-a B @recursive Y ZzX @recursive Z -a Br   )r   r   r   r   r   r.   r[   r_   rz   r2   r~   rX   r	   r	   )rU   r
   r#  Y  s   
r#  c                   sf   e Zd ZdZ fddZG dd deZeZeddZ	edd	d
gZ
g ZdedddgdfgZ  ZS )TestArgumentsFromFileConverterz"Test reading arguments from a filec                sF   t t|   dg}x,|D ]$\}}t|d}|| |  qW d S )N)r$  zhello world!
r'   )rT   r+  r   r(   r)   r&  )r   r'  r   r(  r,   )rU   r	   r
   r     s    

z$TestArgumentsFromFileConverter.setUpc               @   s   e Zd Zdd ZdS )z>TestArgumentsFromFileConverter.FromFileConverterArgumentParserc             c   s&   x |  D ]}| sq
|V  q
W d S )N)r{   strip)r   arg_lineargr	   r	   r
   convert_arg_line_to_args  s    zWTestArgumentsFromFileConverter.FromFileConverterArgumentParser.convert_arg_line_to_argsN)r   r   r   r/  r	   r	   r	   r
   FromFileConverterArgumentParser  s   r0  r)  )r*  r   r   )r   z@hello Xr$  zworld!r   )r   )r   r   r   r   r   rS   r0  r\   r.   r[   r_   rz   r2   r~   rX   r	   r	   )rU   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 )TestFileTypeReprc             C   s   t d}| dt| d S )NrzFileType('r'))r  FileTyper   repr)r   r:   r	   r	   r
   test_r  s    
zTestFileTypeRepr.test_rc             C   s    t dd}| dt| d S )NwbrE   zFileType('wb', 1))r  r3  r   r4  )r   r:   r	   r	   r
   	test_wb_1  s    zTestFileTypeRepr.test_wb_1c             C   s"   t jddd}| dt| d S )Nr2  latin_1)encodingz!FileType('r', encoding='latin_1'))r  r3  r   r4  )r   r:   r	   r	   r
   test_r_latin  s    zTestFileTypeRepr.test_r_latinc             C   s$   t jdddd}| dt| d S )Nr'   big5ignore)r9  errorsz/FileType('w', encoding='big5', errors='ignore'))r  r3  r   r4  )r   r:   r	   r	   r
   test_w_big5_ignore  s    z#TestFileTypeRepr.test_w_big5_ignorec             C   s$   t jdddd}| dt| d S )Nr2  rE   replace)r=  z"FileType('r', 1, errors='replace'))r  r3  r   r4  )r   r:   r	   r	   r
   test_r_1_replace  s    z!TestFileTypeRepr.test_r_1_replaceN)r   r   r   r5  r7  r:  r>  r@  r	   r	   r	   r
   r1    s
   r1  c               @   s   e Zd Zdd Zdd ZdS )StdStreamComparerc             C   s
   || _ d S )N)attr)r   rB  r	   r	   r
   r1     s    zStdStreamComparer.__init__c             C   s   |t t| jkS )N)rJ   rH   rB  )r   r=   r	   r	   r
   r>     s    zStdStreamComparer.__eq__N)r   r   r   r1   r>   r	   r	   r	   r
   rA    s   rA  stdinrB   rC   c               @   s    e Zd Zi Zdd Zdd ZdS )RFilec             C   s
   || _ d S )N)r%   )r   r%   r	   r	   r
   r1     s    zRFile.__init__c             C   s`   || j kr| j | }n|  }| j |< |  t|tsD|d}| j|j  koZ|kS   S )Nascii)seenreadr&  rG   r   decoder%   )r   r=   r(  r	   r	   r
   r>     s    


zRFile.__eq__N)r   r   r   rF  r1   r>   r	   r	   r	   r
   rD    s   rD  c            	       s   e Zd ZdZ fddZede dededdgZddd	gZ	d
e
ded
dfde
ed
eddfde
ed
eddfde
eedfde
deddfgZ  ZS )TestFileTypeRz8Test the FileType option/argument type for reading filesc                sR   t t|   x4dD ],}ttj| j|d}|| |	  qW | 
d d S )N)rb   r   r'   readonly)rT   rI  r   r(   r   r   r   r   r)   r&  r-   )r   	file_namer,   )rU   r	   r
   r     s    

zTestFileTypeR.setUpz-x)r:   r   r2  r   znon-existent-file.txtrb   N)r   r   z
-x foo barr   z
bar -x fooz-x - -rJ  )r   r   r   r   r   r.   r  r3  r_   rz   r2   rD  eq_stdinr~   rX   r	   r	   )rU   r
   rI    s   	
rI  c                   sP   e Zd ZdZ fddZededddgZdgZ	d	e
ed
dfgZ  ZS )TestFileTypeDefaultsz<Test that a file is not created unless the default is neededc                s:   t t|   ttj| jdd}|d |	  d S )Ngoodr'   )
rT   rM  r   r(   r   r   r   r   r)   r&  )r   r,   )rU   r	   r
   r     s    
zTestFileTypeDefaults.setUpz-cr2  zno-file.txt)r:   r   r   z-c goodrN  )r   )r   r   r   r   r   r.   r  r3  r_   rz   r2   rD  r~   rX   r	   r	   )rU   r
   rM    s
   rM  c                   s   e Zd ZdZ fddZededdededdgZddgZ	d	e
d
ed	dfde
ed	eddfde
ed	eddfde
eedfgZ  ZS )TestFileTypeRBz8Test the FileType option/argument type for reading filesc                sH   t t|   x4dD ],}ttj| j|d}|| |	  qW d S )N)rb   r   r'   )
rT   rO  r   r(   r   r   r   r   r)   r&  )r   rK  r,   )rU   r	   r
   r     s
    

zTestFileTypeRB.setUpz-xrb)r:   r   r   rb   N)r   r   z
-x foo barr   z
bar -x fooz-x - -)r   r   r   r   r   r.   r  r3  r_   rz   r2   rD  rL  r~   rX   r	   r	   )rU   r
   rO    s   rO  c               @   s"   e Zd Ze Zdd Zdd ZdS )WFilec             C   s
   || _ d S )N)r%   )r   r%   r	   r	   r
   r1     s    zWFile.__init__c             C   sL   || j kr@d}d|jkr"|d}|| |  | j | | j|jkS )NzCheck that file is writable.r   rE  )rF  modeencoder)   r&  addr%   )r   r=   r(  r	   r	   r
   r>     s    



zWFile.__eq__N)r   r   r   r  rF  r1   r>   r	   r	   r	   r
   rQ    s   rQ  geteuidznon-root user requiredc                   s   e Zd ZdZ fddZededdededdgZddd	gZ	d
e
ded
dfde
ed
eddfde
ed
eddfde
eedfgZ  ZS )TestFileTypeWz8Test the FileType option/argument type for writing filesc                s   t t|   | d d S )NrJ  )rT   rV  r   r-   )r   )rU   r	   r
   r   (  s    zTestFileTypeW.setUpz-xr'   )r:   r   r   rJ  rb   N)r   r   z
-x foo barr   z
bar -x fooz-x - -)r   r   r   r   r   r.   r  r3  r_   rz   r2   rQ  	eq_stdoutr~   rX   r	   r	   )rU   r
   rV  #  s   
rV  c               @   s   e Zd ZededdededdgZddgZdede	ddfd	ee	de	d
dfdee	de	d
dfdee
e
dfgZdS )TestFileTypeWBz-xr6  )r:   r   r   rb   N)r   r   z
-x foo barr   z
bar -x fooz-x - -)r   r   r   r.   r  r3  r_   rz   r2   rQ  rW  r~   r	   r	   r	   r
   rX  9  s   rX  c               @   s   e Zd ZdZdd ZdS )TestFileTypeOpenArgsz0Test that open (the builtin) is correctly calledc          	   C   s   t j}|ddf|dddf|ddddf|d	d
ddf|dddddfg}td.}x&|D ]\}}|d |jd|  q^W W d Q R X d S )NrP  )rP  NNr'   rE   )r'   rE   NNr?  )r=  )r'   rZ  Nr?  r6  r;  )r9  )r6  rZ  r;  Nr   l1strict)r'   r   r[  r\  zbuiltins.openrb   )rb   )r  r3  r   ZpatchZassert_called_with)r   ZFTZcasesmr:   r/   r	   r	   r
   test_open_argsK  s    
z#TestFileTypeOpenArgs.test_open_argsN)r   r   r   r   r^  r	   r	   r	   r
   rY  H  s   rY  c               @   sb   e Zd ZdZededededgZddddgZd	e	d
ddfde	dddfde	dddfgZ
dS )TestTypeCallablez,Test some callables as option/argument typesz--eggs)r:   r   r   Z42jz--eggs az	--eggs 2iz--eggs=42 42r   g      E@)eggsr   z--eggs 2j -- -1.5y               @g      z1024.675Ng3333@)r   r   r   r   r.   complexr  r_   rz   r2   r~   r	   r	   r	   r
   r_  Z  s   
r_  c               @   sl   e Zd ZdZG dd deZededededgZg Zde	eded	d
fde	ededd
fgZ
dS )TestTypeUserDefinedz(Test a user-defined option/argument typec               @   s   e Zd Zdd Zdd ZdS )zTestTypeUserDefined.MyTypec             C   s
   || _ d S )N)value)r   rc  r	   r	   r
   r1   n  s    z#TestTypeUserDefined.MyType.__init__c             C   s   t | | jft ||jfkS )N)r:   rc  )r   r=   r	   r	   r
   r>   q  s    z!TestTypeUserDefined.MyType.__eq__N)r   r   r   r1   r>   r	   r	   r	   r
   MyTypel  s   rd  z-x)r:   r   za -x br   r   )r   r   z-xf gr   r   N)r   r   r   r   r   rd  r.   r_   rz   r2   r~   r	   r	   r	   r
   rb  i  s   	
rb  c               @   sj   e Zd ZdZG dd dZededededgZg Zdeeded	d
fdeededd
fgZ	dS )TestTypeClassicClasszTest a classic class typec               @   s   e Zd Zdd Zdd ZdS )zTestTypeClassicClass.Cc             C   s
   || _ d S )N)rc  )r   rc  r	   r	   r
   r1     s    zTestTypeClassicClass.C.__init__c             C   s   t | | jft ||jfkS )N)r:   rc  )r   r=   r	   r	   r
   r>     s    zTestTypeClassicClass.C.__eq__N)r   r   r   r1   r>   r	   r	   r	   r
   C  s   rf  z-x)r:   r   za -x br   r   )r   r   z-xf gr   r   N)
r   r   r   r   rf  r.   r_   rz   r2   r~   r	   r	   r	   r
   re    s   	
re  c               @   s   e Zd ZdZdd ZdS )TestTypeRegistrationz*Test a user-defined type by registering itc             C   sz   dd }t  }|dd| |jddd |jddd | |d td d	d
 | |d td	dd
 d S )Nc             S   s   d|  S )Nzmy_type{%s}r	   )stringr	   r	   r
   get_my_type  s    z.TestTypeRegistration.test.<locals>.get_my_typer:   Zmy_typez-x)r:   r   r   z
my_type{1})r   r   z-x 1 42zmy_type{42})r  ArgumentParserregisterr]   r   rO   r{   r2   )r   ri  r^   r	   r	   r
   test  s    zTestTypeRegistration.testN)r   r   r   r   rl  r	   r	   r	   r
   rg    s   rg  c               @   s   e Zd ZdZG dd dejZG dd dejZeddee	dd	ed
ee
dddgZg ZdedddfdedddfdedddfdedddfgZdS )TestActionUserDefinedz*Test a user-defined option/argument actionc               @   s   e Zd ZdddZdS )z$TestActionUserDefined.OptionalActionNc             C   s   y~| j dkstd| j  |dks.td| tdd}|dkrHd|_n|d	krXd
|_ntd| ||ks|td||f W n, tk
r   t d }td| Y nX t|d| d S )Nr   zdest: %sz-szflag: %sg      ?)r   )g      ?g      ?r   )g       @r   z	value: %szexpected %s, got %srE   zopt_action failed: %s)r   AssertionErrorr2   r   rH   rL   r?   rK   )r   r^   	namespacerc  option_stringr   er	   r	   r
   __call__  s    
z-TestActionUserDefined.OptionalAction.__call__)N)r   r   r   rr  r	   r	   r	   r
   OptionalAction  s   rs  c               @   s   e Zd ZdddZdS )z&TestActionUserDefined.PositionalActionNc             C   s   y|d kst d| | jdks.t d| j tdd}|dkrHd|_n,|dkrXd	|_n|d
krhd|_nt d| ||kst d||f W n, t k
r   t d }td| Y nX t|d| d S )Nzoption_string: %sr   zdest: %sr   )r   )r   r   g      ?)rE   g      ?)r   g      ?z	value: %szexpected %s, got %srE   zarg_action failed: %s)rn  r   r2   r   rH   rL   r?   rK   )r   r^   ro  rc  rp  r   rq  r	   r	   r
   rr    s$    
z/TestActionUserDefined.PositionalAction.__call__)N)r   r   r   rr  r	   r	   r	   r
   PositionalAction  s   rt  z-sr   g      ?)r   r   r:   r   r   r   r   )r   r:   r   r   z-s0.125g      ?)r   r   r   r   z
-s 0.625 1g      ?rE   z84 -s2g       @r   N)r   r   r   r   r  Actionrs  rt  r.   r  r   r_   rz   r2   r~   r	   r	   r	   r
   rm    s   rm  c               @   s*   e Zd ZdZG dd dejZdd ZdS )TestActionRegistrationz5Test a user-defined action supplied by registering itc               @   s   e Zd ZdddZdS )zTestActionRegistration.MyActionNc             C   s   t || jd|  d S )Nzfoo[%s])rK   r   )r   r^   ro  valuesrp  r	   r	   r
   rr    s    z(TestActionRegistration.MyAction.__call__)N)r   r   r   rr  r	   r	   r	   r
   MyAction  s   rx  c             C   s^   t  }|dd| j |jddd | |dgtdd | |dgtd	d d S )
Nr   Z	my_actionr   )r   r   zfoo[1])r   r   zfoo[42])r  rj  rk  rx  r]   r   rO   r2   )r   r^   r	   r	   r
   rl    s
    zTestActionRegistration.testN)r   r   r   r   r  ru  rx  rl  r	   r	   r	   r
   rv    s   rv  c                   s   e Zd ZdZdd Zd4ddZ 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d0d1 Zd2d3 Z  ZS )5TestAddSubparserszTest the add_subparsers methodc             O   s   | j tf|| d S )N)r|   r?   )r   r/   r0   r	   r	   r
   assertArgumentParserError  s    z+TestAddSubparsers.assertArgumentParserErrorFNc             C   sz  |r0t dd|d}|j|d d d ddd	 nt ddd
}|jdddd	 |jdtdd ddi}|rzd|d< d|d< nd|d< |jf |}| |j tdd}|rd|d< |rddg|d< |jd7|}|jdtdd |jd d!d"d# td$d}	|rd%|	d< |jd8|	}
|
jd'd(d)d# |
jd*td+d,d- td.d}|rJd/|d< |jd9|}|jd1td2d |jd3d4d5d6 |S ):NPROGzmain description)progdescriptionr   r   r   rb   r   zfoo help)r   help)r|  r}  z--foor   zbar help)r:   r~  r   FZCOMMANDmetavarZcommandstitlezcommand helpr~  z1 description)r}  z1 helpZ1alias1Z1alias2aliasesr   z-wzw helpr   r   zx help)r   r~  z2 descriptionz2 helpr   z-yZ123zy helpr   r   zz help)r:   r   r~  z3 descriptionz3 helpr   tzt helpuz...zu help)r   r~  )r   )r   )r   )	rS   r]   r  add_subparsersrz  dict
add_parserr   ra  )r   subparser_helpr   r  r^   Zsubparsers_kwargs
subparsersZparser1_kwargsparser1Zparser2_kwargsparser2Zparser3_kwargsZparser3r	   r	   r
   rx     sN    




zTestAddSubparsers._get_parserc                s&   t    |  | _| jdd| _d S )NT)r  )rT   r   rx   r^   command_help_parser)r   )rU   r	   r
   r   B  s    

zTestAddSubparsers.setUpc             C   s*   x$dD ]}|  }| | jj| qW d S )N)r   r   za az0.5 az0.5 1z0.5 1 -yz0.5 2 -w)r{   rz  r^   rO   )r   r}   r/   r	   r	   r
   test_parse_args_failuresG  s    
z*TestAddSubparsers.test_parse_args_failuresc             C   s   |  | jd tddddd |  | jd tdd	d
ddgd |  | jd tddd dd |  | jd tddddddddgd d S )Nz0.5 1 b -w 7Fg      ?   r   )rb   r   r'   r   z0.25 --foo 2 -y 2 3j -- -1jTg      ?r   y              @y             )rb   r   r   r   z--foo 0.125 1 cg      ?r   z-1.5 3 11 -- a --foo 7 -- bg         r   z--foor   z--)rb   r   r  r  )r   r^   rO   r{   r2   )r   r	   r	   r
   test_parse_argsN  s    z!TestAddSubparsers.test_parse_argsc          	   C   s   |  | jd tdddddg f |  | jd tddddddgf |  | jd	 tddddddgf |  | jd
 tdddddddgf |  | jd tdddddddddgf d S )Nz0.5 1 b -w 7Fg      ?r  r   )rb   r   r'   r   z0.5 -p 1 b -w 7z-pz0.5 1 b -w 7 -pz0.5 1 b -q -rs -w 7z-qz-rsz0.5 -W 1 b -X Y -w 7 Zz-Wz-Xr  r  )r   r^   parse_known_argsr{   r2   )r   r	   r	   r
   test_parse_known_argsa  s    z'TestAddSubparsers.test_parse_known_argsc             C   sX   t  }|jddd |jdd}|d}|d | tddd	d
|d  d S )Nz--foor   )r   r   )r   r   r   Fr   )rb   r   r   z1 2)rS   r]   r  r  r   r2   rO   r{   )r   r^   r  r  r	   r	   r
   	test_destw  s    

zTestAddSubparsers.test_destc             C   s,   | dg}| |jd | |j d d S )Nrunr	   )rO   r   commandrz  )r   r^   retr	   r	   r
   _test_required_subparsers  s    z+TestAddSubparsers._test_required_subparsersc             C   s0   t  }|jdd}d|_|d | | d S )Nr  )r   Tr  )rS   r  r   r  r  )r   r^   r  r	   r	   r
   &test_required_subparsers_via_attribute  s
    
z8TestAddSubparsers.test_required_subparsers_via_attributec             C   s,   t  }|jddd}|d | | d S )Nr  T)r   r   r  )rS   r  r  r  )r   r^   r  r	   r	   r
   "test_required_subparsers_via_kwarg  s    
z4TestAddSubparsers.test_required_subparsers_via_kwargc             C   s6   t  }|jdd}|d |d}| |j d S )Nr  )r   r  r	   )rS   r  r  rO   assertIsNoner  )r   r^   r  r  r	   r	   r
    test_required_subparsers_default  s
    

z2TestAddSubparsers.test_required_subparsers_defaultc             C   s8   t  }|jddd}|d |d}| |j d S )Nr  F)r   r   r  r	   )rS   r  r  rO   r  r  )r   r^   r  r  r	   r	   r
   test_optional_subparsers  s
    

z*TestAddSubparsers.test_optional_subparsersc             C   s.   |  | j d |  | j td d S )Nz)usage: PROG [-h] [--foo] bar {1,2,3} ...
aJ              usage: PROG [-h] [--foo] bar {1,2,3} ...

            main description

            positional arguments:
              bar         bar help
              {1,2,3}     command help

            optional arguments:
              -h, --help  show this help message and exit
              --foo       foo help
            )r   r^   format_usageformat_helptextwrapdedent)r   r	   r	   r
   	test_help  s    zTestAddSubparsers.test_helpc             C   s6   | j dd}| | d | | td d S )Nz+:-)r   z)usage: PROG [-h] [++foo] bar {1,2,3} ...
aJ              usage: PROG [-h] [++foo] bar {1,2,3} ...

            main description

            positional arguments:
              bar         bar help
              {1,2,3}     command help

            optional arguments:
              -h, --help  show this help message and exit
              ++foo       foo help
            )rx   r   r  r  r  r  )r   r^   r	   r	   r
   test_help_extra_prefix_chars  s
    
z.TestAddSubparsers.test_help_extra_prefix_charsc             C   s6   t ddd}|jdddd | | td d S )	Nr{  zmain description)r|  r}  z--non-breakingr   uR   help message containing non-breaking spaces shall not wrap at non-breaking spaces)r   r~  uB              usage: PROG [-h] [--non-breaking]

            main description

            optional arguments:
              -h, --help      show this help message and exit
              --non-breaking  help message containing non-breaking spaces shall not
                              wrap at non-breaking spaces
        )rS   r]   r   r  r  r  )r   r^   r	   r	   r
   test_help_non_breaking_spaces  s    
	z/TestAddSubparsers.test_help_non_breaking_spacesc             C   s6   | j dd}| | d | | td d S )Nz+:/)r   z)usage: PROG [+h] [++foo] bar {1,2,3} ...
aJ              usage: PROG [+h] [++foo] bar {1,2,3} ...

            main description

            positional arguments:
              bar         bar help
              {1,2,3}     command help

            optional arguments:
              +h, ++help  show this help message and exit
              ++foo       foo help
            )rx   r   r  r  r  r  )r   r^   r	   r	   r
    test_help_alternate_prefix_chars  s
    
z2TestAddSubparsers.test_help_alternate_prefix_charsc             C   s.   |  | j d |  | j td d S )Nz)usage: PROG [-h] [--foo] bar {1,2,3} ...
a              usage: PROG [-h] [--foo] bar {1,2,3} ...

            main description

            positional arguments:
              bar         bar help
              {1,2,3}     command help
                1         1 help
                2         2 help
                3         3 help

            optional arguments:
              -h, --help  show this help message and exit
              --foo       foo help
            )r   r  r  r  r  r  )r   r	   r	   r
   test_parser_command_help  s
    z*TestAddSubparsers.test_parser_command_helpc             C   sx   t ddd}|jdddd |jdd	d
 |jdddd}|d}|d}| | d | | td d S )Nr{  zmain description)r|  r}  z--foor   zfoo help)r   r~  r   zbar help)r~  subcommandszcommand helpzadditional text)r  r}  r~  r   r   z'usage: PROG [-h] [--foo] bar {1,2} ...
a              usage: PROG [-h] [--foo] bar {1,2} ...

            main description

            positional arguments:
              bar         bar help

            optional arguments:
              -h, --help  show this help message and exit
              --foo       foo help

            subcommands:
              command help

              {1,2}       additional text
            )	rS   r]   r  r  r   r  r  r  r  )r   r^   r  r  r  r	   r	   r
   test_subparser_title_help  s    


z+TestAddSubparsers.test_subparser_title_helpc          	   C   s:   |  t}| j|  W d Q R X | ||jj d S )N)r|   r?   r^   rO   r{   r   	exceptionrB   )r   r}   Zexpected_helpcmr	   r	   r
   _test_subparser_help   s    z&TestAddSubparsers._test_subparser_helpc             C   s   |  dtd d S )Nz5.0 1 -ha              usage: PROG bar 1 [-h] [-w W] {a,b,c}

            1 description

            positional arguments:
              {a,b,c}     x help

            optional arguments:
              -h, --help  show this help message and exit
              -w W        w help
            )r  r  r  )r   r	   r	   r
   test_subparser1_help%  s    
z&TestAddSubparsers.test_subparser1_helpc             C   s   |  dtd d S )Nz5.0 2 -ha#              usage: PROG bar 2 [-h] [-y {1,2,3}] [z [z ...]]

            2 description

            positional arguments:
              z           z help

            optional arguments:
              -h, --help  show this help message and exit
              -y {1,2,3}  y help
            )r  r  r  )r   r	   r	   r
   test_subparser2_help3  s    
z&TestAddSubparsers.test_subparser2_helpc          	   C   s\   | j dd}| |d tddd ddg f | |d tddd ddg f d S )	NT)r  z0.5 1alias1 bFg      ?r   )rb   r   r'   r   z0.5 1alias2 b)rx   r   r  r{   r2   )r   r^   r	   r	   r
   test_alias_invocationA  s    z'TestAddSubparsers.test_alias_invocationc             C   s"   | j dd}| |jd  d S )NT)r  z0.5 1alias3 b)rx   rz  rO   r{   )r   r^   r	   r	   r
   test_error_alias_invocationL  s    z-TestAddSubparsers.test_error_alias_invocationc             C   s.   | j ddd}d | _| | td d S )NT)r  r  a              usage: PROG [-h] [--foo] bar COMMAND ...

            main description

            positional arguments:
              bar                   bar help

            optional arguments:
              -h, --help            show this help message and exit
              --foo                 foo help

            commands:
              COMMAND
                1 (1alias1, 1alias2)
                                    1 help
                2                   2 help
                3                   3 help
            )rx   ZmaxDiffr   r  r  r  )r   r^   r	   r	   r
   test_alias_helpQ  s    z!TestAddSubparsers.test_alias_help)FNF)r   r   r   r   rz  rx   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rX   r	   r	   )rU   r
   ry    s4    
6	ry  c               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	TestPositionalsGroupsz@Tests that order of group positionals matches construction orderc             C   sZ   t  }|d |d}|d |d tdddd}|d	 }| || d S )
Nrb   r   r   r   r   r   r   )rb   r   r   z1 2 3)rS   r]   rc   r2   rO   r{   r   )r   r^   rd   expectedrP   r	   r	   r
   test_nongroup_firsto  s    



z)TestPositionalsGroups.test_nongroup_firstc             C   sZ   t  }|d}|d |d |d tdddd}|d	 }| || d S )
Nxxxrb   r   r   r   r   r   )rb   r   r   z1 2 3)rS   rc   r]   r2   rO   r{   r   )r   r^   rd   r  rP   r	   r	   r
   test_group_firsty  s    



z&TestPositionalsGroups.test_group_firstc             C   sp   t  }|d}|d |d |d |d}|d tddd	d
d}|d }| || d S )Nr  rb   r   r   r   frellr   r   r   r  )rb   r   r   r  z1 2 3 4)rS   rc   r]   r2   rO   r{   r   )r   r^   rd   r  rP   r	   r	   r
   test_interleaved_groups  s    





z-TestPositionalsGroups.test_interleaved_groupsN)r   r   r   r   r  r  r  r	   r	   r	   r
   r  l  s   

r  c                   s   e Zd ZdZdd Z 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  ZS ) TestParentParsersz5Tests that parsers can be created with parent parsersc             O   s   | j tf|| d S )N)r|   r?   )r   r/   r0   r	   r	   r
   rz    s    z+TestParentParsers.assertArgumentParserErrorc                s   t    tdd| _| jd | jd}|d | jd tdd| _| jd | jd | jd	}|d
 tdd| _| jd tdd| _| jd tdd| _	| j	
 }|jddd |jddd tjtjd | _d S )NF)r   z--wr   z-yr   r   z-br   z--dz-ar   )r   r   )rT   r   rS   wxyz_parentr]   rc   abcd_parentw_parentz_parentab_mutex_parentadd_mutually_exclusive_groupr   r   basenamerH   rj   main_program)r   Zx_groupc_grouprd   )rU   r	   r
   r     s(    



zTestParentParsers.setUpc             C   s2   t | jgd}| |d tdddd d S )N)parentsz-y 1 2 --w 3r   r   r   )r'   r   r   )rS   r  r   rO   r{   r2   )r   r^   r	   r	   r
   test_single_parent  s    z$TestParentParsers.test_single_parentc             C   s,   |  | jj t| jgd}|  |j d S )N)r  )_test_mutex_abr  rO   rS   )r   r^   r	   r	   r
   test_single_parent_mutex  s    z*TestParentParsers.test_single_parent_mutexc             C   s0   | j g}td|d}t|gd}| |j d S )NF)r   r  )r  )r  rS   r  rO   )r   r  r^   r	   r	   r
   test_single_granparent_mutex  s    z.TestParentParsers.test_single_granparent_mutexc             C   s   |  |g tddd |  |dgtddd |  |dgtddd | |ddg | |ddg | |dg | |ddg | |ddg d S )NF)r   r   z-aTz-bz-c)r   r2   rz  )r   rO   r	   r	   r
   r    s    z TestParentParsers._test_mutex_abc             C   s@   | j | jg}t|d}| |d tdd ddd dd d S )N)r  z--d 1 --w 2 3 4r   r   r   r  )r   r   r  r'   r   r   )r  r  rS   r   rO   r{   r2   )r   r  r^   r	   r	   r
   test_multiple_parents  s    
z'TestParentParsers.test_multiple_parentsc          
   C   sb   | j | jg}t|d}| |d tdddd dd | |jd  | |jd	  d S )
N)r  z
-a --w 2 3TFr   r   )r   r   r'   r   r   z-a --w 2 3 -bz-a -b --w 2 3)r  r  rS   r   rO   r{   r2   rz  )r   r  r^   r	   r	   r
   test_multiple_parents_mutex  s    
z-TestParentParsers.test_multiple_parents_mutexc             C   s    | j tjtj| j| jgd d S )N)r  )r|   r  ArgumentErrorrj  r  r  )r   r	   r	   r
   test_conflicting_parents  s    z*TestParentParsers.test_conflicting_parentsc             C   s    | j tjtj| j| jgd d S )N)r  )r|   r  r  rj  r  r  )r   r	   r	   r
   test_conflicting_parents_mutex  s    z0TestParentParsers.test_conflicting_parents_mutexc             C   s:   | j | jg}t|d}| |d td d dd d S )N)r  z1 2r   )r'   r   r   )r  r  rS   r   rO   r{   r2   )r   r  r^   r	   r	   r
   test_same_argument_name_parents  s    
z1TestParentParsers.test_same_argument_name_parentsc          	   C   sP   t  }| }|jd| jgd}|d | |d tddddd	 d S )
Nr   )r  rq  zbar -b 1 --d 2 3 4r   r   r   r  )r   r   r  rq  )	rS   r  r  r  r]   r   rO   r{   r2   )r   r^   r  Zabcde_parserr	   r	   r
   test_subparser_parents  s    
z(TestParentParsers.test_subparser_parentsc             C   s   t  }| }| jg}|jd|d}|d}|d | j| jg}|jd|d}|d | |d	 t
dd	d
d | |d	 t
d	ddd dd
d | |jd	  | |jd	  d S )Nrb   )r  r  r   r   rq  zfoo -a 4TFr  )r   r   r   zbar -b  --w 2 3 4r   r   )r   r   r'   r   r   rq  zfoo -a -b 4zbar -b -a 4)rS   r  r  r  rc   r]   r  r   rO   r{   r2   rz  )r   r^   r  r  Z
abc_parserr  Zwxyzabe_parserr	   r	   r
   test_subparser_parents_mutex  s"    


z.TestParentParsers.test_subparser_parents_mutexc          	   C   sJ   | j | jg}t|d}| }| j}| |td||r<dnd d S )N)r  aR              usage: {}{}[-h] [-b B] [--d D] [--w W] [-y Y] a z

            positional arguments:
              a
              z

            optional arguments:
              -h, --help  show this help message and exit
              -b B
              --w W

            c:
              --d D

            x:
              -y Y
         r   )	r  r  rS   r  r  r   r  r  format)r   r  r^   parser_helpprognamer	   r	   r
   test_parent_help	  s    

z"TestParentParsers.test_parent_helpc          	   C   s   t dd}|jddd}|d |d | }|d |d	 t |gd
}| t|jddd	dg | }| j}| 	|t
d||rdnd d S )NF)r   r   gd)r  r}  z-wz-xz-yz-z)r  r  r  a	              usage: {}{}[-h] [-w W] [-x X] [-y Y | -z Z]

            optional arguments:
              -h, --help  show this help message and exit
              -y Y
              -z Z

            g:
              gd

              -w W
              -x X
        r  r   )rS   rc   r]   r  r|   r?   rO   r  r  r   r  r  r  )r   parentr   r]  r^   r  r  r	   r	   r
   test_groups_parents$	  s    






z%TestParentParsers.test_groups_parents)r   r   r   r   rz  r   r  r  r  r  r  r  r  r  r  r  r  r  r  rX   r	   r	   )rU   r
   r    s    

r  c               @   s$   e Zd Zdd Zdd Zdd ZdS ) TestMutuallyExclusiveGroupErrorsc             C   s    t  }| j}|t|jdd d S )Nrb   )r  )rS   r|   rs   r  )r   r^   raisesr	   r	   r
   test_invalid_add_argument_groupH	  s    z@TestMutuallyExclusiveGroupErrors.test_invalid_add_argument_groupc             C   sl   t  }| }|j}| j}|t|ddd |t|d |t|ddd |t|ddd |t|dtjd d S )Nz--fooT)r   r   r   )r   rE   )rS   r  r]   r|   
ValueErrorr  PARSER)r   r^   rd   r]   r  r	   r	   r
   test_invalid_add_argumentM	  s    z:TestMutuallyExclusiveGroupErrors.test_invalid_add_argumentc             C   sp   t dd}| }|jddd |jddd | }|jddd |jd	dd d
}| | t| d S )Nr{  )r|  z--foor   )r   z--barr   z--soupz--nutsz            usage: PROG [-h] [--foo | --bar] [--soup | --nuts]

            optional arguments:
              -h, --help  show this help message and exit
              --foo
              --bar
              --soup
              --nuts
              )rS   r  r]   r   r  r  r  )r   r^   Zgroup1Zgroup2r  r	   r	   r
   r  X	  s    

z*TestMutuallyExclusiveGroupErrors.test_helpN)r   r   r   r  r  r  r	   r	   r	   r
   r  F	  s   r  c               @   sL   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S )MEMixinc             C   s8   | j ddj}t}x | jD ]}| |||  qW d S )NF)r   )
get_parserrO   r?   rz   r|   r{   )r   rO   rW   args_stringr	   r	   r
   test_failures_when_not_requiredn	  s    z'MEMixin.test_failures_when_not_requiredc             C   s>   | j ddj}t}x&| jdg D ]}| |||  q W d S )NT)r   r   )r  rO   r?   rz   r|   r{   )r   rO   rW   r  r	   r	   r
   test_failures_when_requiredt	  s    z#MEMixin.test_failures_when_requiredc             C   sH   | j ddj}| j| j }x(|D ] \}}|| }| || q W d S )NF)r   )r  rO   r~   successes_when_not_requiredr{   r   )r   rO   r~   r  r   	actual_nsr	   r	   r
    test_successes_when_not_requiredz	  s
    z(MEMixin.test_successes_when_not_requiredc             C   s>   | j ddj}x*| jD ] \}}|| }| || qW d S )NT)r   )r  rO   r~   r{   r   )r   rO   r  r   r  r	   r	   r
   test_successes_when_required	  s    z$MEMixin.test_successes_when_requiredc             C   s,   | j ddj}| j}| | t| d S )NF)r   )r  r  usage_when_not_requiredr   r  r  )r   r  expected_usager	   r	   r
   test_usage_when_not_required	  s    z$MEMixin.test_usage_when_not_requiredc             C   s,   | j ddj}| j}| | t| d S )NT)r   )r  r  usage_when_requiredr   r  r  )r   r  r  r	   r	   r
   test_usage_when_required	  s    z MEMixin.test_usage_when_requiredc             C   s2   | j ddj}| j| j }| | t| d S )NF)r   )r  r  r  r~  r   r  r  )r   r  r~  r	   r	   r
   test_help_when_not_required	  s    z#MEMixin.test_help_when_not_requiredc             C   s2   | j ddj}| j| j }| | t| d S )NT)r   )r  r  r  r~  r   r  r  )r   r  r~  r	   r	   r
   test_help_when_required	  s    zMEMixin.test_help_when_requiredN)r   r   r   r  r  r  r  r  r  r  r  r	   r	   r	   r
   r  l	  s   r  c               @   sx   e Zd ZdddZddgZdedddfd	ed
ddfdedddfdedd
dfgZdedddfgZdZdZ	dZ
dS )TestMutuallyExclusiveSimpleNc             C   s:   t dd}|j|d}|jddd |jddd	d
d |S )Nr{  )r|  )r   z--barzbar help)r~  z--bazr   r  zbaz help)r   r   r~  )rS   r  r]   )r   r   r^   rd   r	   r	   r
   r  	  s
    
z&TestMutuallyExclusiveSimple.get_parserz--bar X --baz Yz--bar X --bazz--bar Xr   )r   r   z--bar X --bar Zr  z--baz Yr  z--bazr   z;        usage: PROG [-h] [--bar BAR | --baz [BAZ]]
        z;        usage: PROG [-h] (--bar BAR | --baz [BAZ])
        z
        optional arguments:
          -h, --help   show this help message and exit
          --bar BAR    bar help
          --baz [BAZ]  baz help
        )N)r   r   r   r  rz   r2   r~   r  r  r  r~  r	   r	   r	   r
   r  	  s   
r  c            
   @   s   e Zd ZdddZdgZdedddddfded	ddddfd
edddddfdedd	dddfgZdedddddfgZdZdZ	dZ
dS )TestMutuallyExclusiveLongNc             C   sR   t dd}|jddd |jddd |j|d}|jd	d
d |jddd |S )Nr{  )r|  z--abcdez
abcde help)r~  z--fghijz
fghij help)r   z--klmnoz
klmno helpz--pqrstz
pqrst help)rS   r]   r  )r   r   r^   rd   r	   r	   r
   r  	  s    
z$TestMutuallyExclusiveLong.get_parserz--klmno X --pqrst Yz	--klmno Xr   )ZabcdeZfghijZklmnoZpqrstz--abcde Y --klmno Xr  z	--pqrst Xz--pqrst X --fghij Yr   zi    usage: PROG [-h] [--abcde ABCDE] [--fghij FGHIJ]
                [--klmno KLMNO | --pqrst PQRST]
    zi    usage: PROG [-h] [--abcde ABCDE] [--fghij FGHIJ]
                (--klmno KLMNO | --pqrst PQRST)
    z
    optional arguments:
      -h, --help     show this help message and exit
      --abcde ABCDE  abcde help
      --fghij FGHIJ  fghij help
      --klmno KLMNO  klmno help
      --pqrst PQRST  pqrst help
    )N)r   r   r   r  rz   r2   r~   r  r  r  r~  r	   r	   r	   r
   r  	  s   
		r  c               @   sf   e Zd Zdd ZdgZdedddfded	ddfd
edddfgZdedddfgZdZdZ	dZ
dS )$TestMutuallyExclusiveFirstSuppressedc             C   s:   t dd}|j|d}|jdtjd |jdddd	 |S )
Nr{  )r|  )r   z-x)r~  z-yr   zy help)r   r~  )rS   r  r]   r  r  )r   r   r^   rd   r	   r	   r
   r  	  s
    
z/TestMutuallyExclusiveFirstSuppressed.get_parserz-x X -yz-x Xr   T)r   r   z	-x X -x Yr  z-yNFr   z&        usage: PROG [-h] [-y]
        z$        usage: PROG [-h] -y
        zx
        optional arguments:
          -h, --help  show this help message and exit
          -y          y help
        )r   r   r   r  rz   r2   r~   r  r  r  r~  r	   r	   r	   r
   r  	  s   r  c            	   @   s   e Zd Zdd ZdddgZdedddd	fd
edddd	fdedddd	fdedddd	fgZdedddd	fgZd ZZ	dZ
dS )#TestMutuallyExclusiveManySuppressedc             C   sN   t dd}|j|d}|j}|ddtjd |ddtjd |d	tjd
 |S )Nr{  )r|  )r   z--spamr   )r   r~  z--badgerr   z	--bladder)r~  )rS   r  r]   r  r  )r   r   r^   rd   rT  r	   r	   r
   r  
  s    
z.TestMutuallyExclusiveManySuppressed.get_parserz--spam --badgerz--badger --bladder Bz--bladder B --spamz--spamTN)r   r   Zbladderz--badgerFz--bladder Br   z--spam --spamr   z!        usage: PROG [-h]
        z[
        optional arguments:
          -h, --help  show this help message and exit
        )r   r   r   r  rz   r2   r~   r  r  r  r~  r	   r	   r	   r
   r  
  s   
r  c            
   @   s   e Zd Zdd ZdddddgZded	d
ddfdeddddfdedd
dgdfdedd
dddgdfgZdedd
ddfgZdZdZ	dZ
d
S )*TestMutuallyExclusiveOptionalAndPositionalc             C   sJ   t dd}|j|d}|jdddd |jdd	d
 |jddddd |S )Nr{  )r|  )r   z--foor   FOO)r   r~  z--spamSPAM)r~  r   r   r   BADGER)r   r   r~  )rS   r  r]   )r   r   r^   rd   r	   r	   r
   r  1
  s    
z5TestMutuallyExclusiveOptionalAndPositional.get_parserz--foo --spam Sz
--spam S XzX --foozX Y Z --spam Sz	--foo X Yz--fooTNr   )rb   r   r   z--spam SFSzX Y Zr  r  r   zM        usage: PROG [-h] [--foo | --spam SPAM | badger [badger ...]]
        zM        usage: PROG [-h] (--foo | --spam SPAM | badger [badger ...])
        z
        positional arguments:
          badger       BADGER

        optional arguments:
          -h, --help   show this help message and exit
          --foo        FOO
          --spam SPAM  SPAM
        )r   r   r   r  rz   r2   r~   r  r  r  r~  r	   r	   r	   r
   r  /
  s   	
r  c               @   s   e Zd Zdd ZddddgZdedd	d	d	d	d
fded	dd	d	d	d
fded	d	dd	d	d
fdedd	d	dd	d
fded	dd	d	dd
fded	d	dddd
fgZded	d	d	d	d	d
fded	d	d	dd	d
fded	d	d	d	dd
fgZd ZZ	dZ
dS )#TestMutuallyExclusiveOptionalsMixedc             C   sj   t dd}|jdddd |j|d}|jddd	d |jd
ddd |jdddd |jdddd |S )Nr{  )r|  z-xr   zx help)r   r~  )r   z-aza helpz-bzb helpz-yzy helpz-czc help)rS   r]   r  )r   r   r^   rd   r	   r	   r
   r  ^
  s    
z.TestMutuallyExclusiveOptionalsMixed.get_parserz-a -bz-b -cz-a -cz-a -b -cz-aTF)r   r   r   r   r   z-bz-cz-a -xz-y -bz-x -y -cr   z-xz-yz:        usage: PROG [-h] [-x] [-a] [-b] [-y] [-c]
        z
        optional arguments:
          -h, --help  show this help message and exit
          -x          x help
          -a          a help
          -b          b help
          -y          y help
          -c          c help
        N)r   r   r   r  rz   r2   r~   r  r  r  r~  r	   r	   r	   r
   r  \
  s   

r  c               @   s\   e Zd ZdddZddgZdedddfd	edd
dfgZdedddfgZdZdZ	dZ
dS )TestMutuallyExclusiveInGroupNc             C   sD   t dd}|jddd}|j|d}|jddd	 |jd
dd	 |S )Nr{  )r|  zTitled groupzGroup description)r  r}  )r   z--barzbar help)r~  z--bazzbaz help)rS   rc   r  r]   )r   r   r^   Ztitled_groupmutex_groupr	   r	   r
   r  
  s    

z'TestMutuallyExclusiveInGroup.get_parserz--bar X --baz Yz--baz X --bar Yz--bar Xr   )r   r   z--baz Yr  r   z9        usage: PROG [-h] [--bar BAR | --baz BAZ]
        z9        usage: PROG [-h] (--bar BAR | --baz BAZ)
        z
        optional arguments:
          -h, --help  show this help message and exit

        Titled group:
          Group description

          --bar BAR   bar help
          --baz BAZ   baz help
        )N)r   r   r   r  rz   r2   r~   r  r  r  r~  r	   r	   r	   r
   r  
  s   

r  c               @   s   e Zd Zdd ZdddgZdedddd	dd
fdedddd	dd
fdedddd	dd
fdedddd	dd
fdedddd	dd
fgZd	edddd	dd
fdedddd	dd
fgZd ZZ	dZ
dS )1TestMutuallyExclusiveOptionalsAndPositionalsMixedc             C   sh   t dd}|jddd |jdddd	 |j|d
}|jdddd |jdddd	 |jdddd	 |S )Nr{  )r|  r   zx help)r~  z-yr   zy help)r   r~  )r   r   r   za help)r   r~  z-bzb helpz-czc help)rS   r]   r  )r   r   r^   rd   r	   r	   r
   r  
  s    
z<TestMutuallyExclusiveOptionalsAndPositionalsMixed.get_parserzX A -bz-b -cz-c X AzX Ar  Fr   )r   r   r   r   r   zX -bNTzX -czX A -yzX -y -bzX -yz6        usage: PROG [-h] [-y] [-b] [-c] x [a]
        a  
        positional arguments:
          x           x help
          a           a help

        optional arguments:
          -h, --help  show this help message and exit
          -y          y help
          -b          b help
          -c          c help
        )r   r   r   r  rz   r2   r~   r  r  r  r~  r	   r	   r	   r
   r  
  s   

r  c                   s   e Zd Zd fdd	Z  ZS )MEPBaseNc                s(   t t| j|d}t|jd|gd}|S )N)r   F)r|  r   r  )rT   r  r  rS   r|  )r   r   r  r^   )rU   r	   r
   r  
  s    zMEPBase.get_parser)N)r   r   r   r  rX   r	   r	   )rU   r
   r  
  s   r  c               @   s   e Zd ZdS )&TestMutuallyExclusiveGroupErrorsParentN)r   r   r   r	   r	   r	   r
   r  
  s   r  c               @   s   e Zd ZdS )!TestMutuallyExclusiveSimpleParentN)r   r   r   r	   r	   r	   r
   r  
  s   r  c               @   s   e Zd ZdS )TestMutuallyExclusiveLongParentN)r   r   r   r	   r	   r	   r
   r  
  s   r  c               @   s   e Zd ZdS )*TestMutuallyExclusiveFirstSuppressedParentN)r   r   r   r	   r	   r	   r
   r  
  s   r  c               @   s   e Zd ZdS ))TestMutuallyExclusiveManySuppressedParentN)r   r   r   r	   r	   r	   r
   r  
  s   r  c               @   s   e Zd ZdS )0TestMutuallyExclusiveOptionalAndPositionalParentN)r   r   r   r	   r	   r	   r
   r  
  s   r  c               @   s   e Zd ZdS ))TestMutuallyExclusiveOptionalsMixedParentN)r   r   r   r	   r	   r	   r
   r    s   r  c               @   s   e Zd ZdS )7TestMutuallyExclusiveOptionalsAndPositionalsMixedParentN)r   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 )TestSetDefaultsc          
   C   s   t  }|jdd |jddd | tdddd|g  | tdddd|g t  | tdddd|g tdd | tdddd|g tddd	 d S )
Nrb   )r   r   rE   )r   r   )r   r   r   r   r   )r   r   )rS   set_defaultsr   r2   rO   )r   r^   r	   r	   r
   test_set_defaults_no_args  s    z)TestSetDefaults.test_set_defaults_no_argsc          	   C   s   t  }|jddd |jddd | tddd|g  | tddd|g t  | tddd|g tdd | td	dd|d
  | td	dd|d
 t  | td	dd|d
 tdd d S )Nrb   r   )r   r   z-xZxfoox)r   r   )r   r   z-x 1)rS   r  r]   r   r2   rO   r{   )r   r^   r	   r	   r
   test_set_defaults_with_args  s    z+TestSetDefaults.test_set_defaults_with_argsc             C   sR   t  }|jdd | }|d}|jdd | tddd|d  d S )Nrb   )r   r   r   )r   )r   r   )rS   r  r  r  r   r2   rO   r{   )r   r^   r  Zparser_ar	   r	   r
   test_set_defaults_subparsers/  s    
z,TestSetDefaults.test_set_defaults_subparsersc             C   s>   t dd}|jdd t |gd}| tdd|g  d S )NF)r   rb   )r   )r  )rS   r  r   r2   rO   )r   r  r^   r	   r	   r
   test_set_defaults_parents8  s    
z)TestSetDefaults.test_set_defaults_parentsc             C   sL   t  }| d}|jdd |jdd | tdd|dg d S )Nr   rE   )rb   r   )r  rj  r  r  r  r   r2   rO   )r   r^   Zxparserr	   r	   r
   )test_set_defaults_on_parent_and_subparser>  s
    z9TestSetDefaults.test_set_defaults_on_parent_and_subparserc             C   s   t  }|jddddd |d |jddd	 |jd
dd |jdddd | tddddd|g  |jddddd | tddddd|g  d S )NWr   r  r  )r'   r   r   r   z-wz-xXX)r   r   r   )r   r   ZZ)r   r   WWYY)rS   r  r]   r   r2   rO   )r   r^   r	   r	   r
   &test_set_defaults_same_as_add_argumentE  s    
z6TestSetDefaults.test_set_defaults_same_as_add_argumentc             C   s   t  }|jddddd |d}|d |jdd	d
 |jddd |jdddd | tdd	ddd|g  |jddddd | tddddd|g  d S )Nr  r   r  r  )r'   r   r   r   rb   z-wz-xr	  )r   r   r   )r   r   r
  )r   r   r  r  )rS   r  rc   r]   r   r2   rO   )r   r^   rd   r	   r	   r
   ,test_set_defaults_same_as_add_argument_groupV  s    

z<TestSetDefaults.test_set_defaults_same_as_add_argument_groupN)
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S )TestGetDefaultc             C   s   t  }| |d | |d |d | |d | |d |jdtdd | |d | d|d |jdd | d|d | d|d d S )	Nrb   r   z--fooz--barr   )r:   r   r   )rb   )rS   r  get_defaultr]   r   r   r  )r   r^   r	   r	   r
   test_get_defaulto  s    
zTestGetDefault.test_get_defaultN)r   r   r   r  r	   r	   r	   r
   r  m  s   r  c               @   s   e Zd Zdd Zdd ZdS )TestNamespaceContainsSimplec             C   s$   t  }| d| | d| d S )Nr   r   )r  	NamespaceassertNotIn)r   nsr	   r	   r
   
test_empty  s    z&TestNamespaceContainsSimple.test_emptyc             C   sN   t jddd}| d| | d| | d| | d| | d| d S )	NrE   r   )r   r   r   r   r   Zxxr   )r  r  r  assertIn)r   r  r	   r	   r
   test_non_empty  s    z*TestNamespaceContainsSimple.test_non_emptyN)r   r   r   r  r  r	   r	   r	   r
   r    s   r  c               @   s   e Zd Zdd ZdS )TestHelpFormattingMetaclassc             C   s>   |dkrd S G dd dt }xdD ]\}}|| || q"W d S )NHelpTestCasec               @   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 )z6TestHelpFormattingMetaclass.__init__.<locals>.AddTestsc          	   S   sp   || _ || _x^| j| j| jgD ]J}d|j|f }|fdd}y
||_W n tk
rZ   Y nX t||| qW d S )Nz%s_%sc             S   s   ||  d S )Nr	   )r   rm   r	   r	   r
   test_wrapper  s    zUTestHelpFormattingMetaclass.__init__.<locals>.AddTests.__init__.<locals>.test_wrapper)func_suffixstd_nametest_format
test_printtest_print_filer   rs   rK   )r   Z
test_classr  r  rm   rv   r  r	   r	   r
   r1     s    
z?TestHelpFormattingMetaclass.__init__.<locals>.AddTests.__init__c             S   s   t j|jj|jj}x$t|dg D ]}|j|j|j q"W t|dg }x>|D ]6\}}|j|j|j}x|D ]}|j|j|j qjW qLW t|dg }|r| }	x|D ]}
|	j	|
j|
j qW |S )Nr_   argument_group_signaturessubparsers_signatures)
r  rj  r[   r/   r0   rJ   r]   rc   r  r  )r   rw   r^   Zargument_sigZ
group_sigsZ	group_sigZargument_sigsrd   Zsubparsers_sigsr  Zsubparser_sigr	   r	   r
   rx     s(    


zBTestHelpFormattingMetaclass.__init__.<locals>.AddTests._get_parserc             S   s&   t || j}t|}||| d S )N)rJ   r  r  r  r   )r   rw   parser_textZexpected_textr	   r	   r
   _test  s    
z<TestHelpFormattingMetaclass.__init__.<locals>.AddTests._testc             S   s,   |  |}t|d| j }| ||  d S )Nz	format_%s)rx   rJ   r  r$  )r   rw   r^   r  r	   r	   r
   r    s    
zBTestHelpFormattingMetaclass.__init__.<locals>.AddTests.test_formatc          
   S   sr   |  |}t|d| j }tt| j}tt| jt  z|  tt| j }W d tt| j| X | || d S )Nzprint_%s)	rx   rJ   r  rH   r  rK   r   rN   r$  )r   rw   r^   print_Z
old_streamr#  r	   r	   r
   r    s    
zATestHelpFormattingMetaclass.__init__.<locals>.AddTests.test_printc             S   s@   |  |}t|d| j }t }|| | }| || d S )Nzprint_%s)rx   rJ   r  r   rN   r$  )r   rw   r^   r%  Zsfiler#  r	   r	   r
   r     s    
zFTestHelpFormattingMetaclass.__init__.<locals>.AddTests.test_print_fileN)	r   r   r   r1   rx   r$  r  r  r   r	   r	   r	   r
   r     s   r   ))usagerB   )r~  rB   )r   )r   r%   r   r   r   r  r  r	   r	   r
   r1     s
    Hz$TestHelpFormattingMetaclass.__init__N)r   r   r   r1   r	   r	   r	   r
   r    s   r  r  c               @   sn   e Zd ZdZeddddZedddd	d
eddddedddedddedddgZg ZdZed Z	dZ
dS )TestHelpBiggerOptionalsz;Make sure that argument help aligns when options are longerr{  DESCRIPTIONEPILOG)r|  r}  epilogz-vz	--versionr"  z0.1)r   r"  z-xr   zX HELP)r   r~  z--yzY HELP)r~  rb   zFOO HELPr   zBAR HELPz;        usage: PROG [-h] [-v] [-x] [--y Y] foo bar
        ab  
        DESCRIPTION

        positional arguments:
          foo            FOO HELP
          bar            BAR HELP

        optional arguments:
          -h, --help     show this help message and exit
          -v, --version  show program's version number and exit
          -x             X HELP
          --y Y          Y HELP

        EPILOG
    z        0.1
        N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   r'    s   

r'  c               @   s<   e Zd ZdZdd ZejZejZejZdZ	e	d Z
ejZdS )TestShortColumnszTest extremely small number of columns.

    TestCase prevents "COLUMNS" from being too small in the tests themselves,
    but we don't want any exceptions thrown in such cases. Only ugly representation.
    c             C   s$   t  }|dd | |j d S )Nr   r  )r   r   r  r   r   )r   r   r	   r	   r
   r     s    zTestShortColumns.setUpz        usage: PROG
               [-h]
               [-v]
               [-x]
               [--y Y]
               foo
               bar
        a  
        DESCRIPTION

        positional arguments:
          foo
            FOO HELP
          bar
            BAR HELP

        optional arguments:
          -h, --help
            show this
            help
            message and
            exit
          -v, --version
            show
            program's
            version
            number and
            exit
          -x
            X HELP
          --y Y
            Y HELP

        EPILOG
    N)r   r   r   r   r   r'  r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   r+    s   	r+  c               @   s   e Zd ZdZeddddZedddd	d
eddddedddedddedddgZedddedddeddddgfgZdZed  Z	d!Z
d"S )#TestHelpBiggerOptionalGroupsz;Make sure that argument help aligns when options are longerr{  r(  r)  )r|  r}  r*  z-vz	--versionr"  z0.1)r   r"  z-xr   zX HELP)r   r~  z--yzY HELP)r~  rb   zFOO HELPr   zBAR HELPzGROUP TITLEzGROUP DESCRIPTION)r}  r   zBAZ HELPz-zr   zZ HELP)r   r~  zN        usage: PROG [-h] [-v] [-x] [--y Y] [-z Z [Z ...]] foo bar baz
        a  
        DESCRIPTION

        positional arguments:
          foo            FOO HELP
          bar            BAR HELP

        optional arguments:
          -h, --help     show this help message and exit
          -v, --version  show program's version number and exit
          -x             X HELP
          --y Y          Y HELP

        GROUP TITLE:
          GROUP DESCRIPTION

          baz            BAZ HELP
          -z Z [Z ...]   Z HELP

        EPILOG
    z        0.1
        N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   r,  H  s   



r,  c               @   s^   e Zd ZdZedddZedddded	d
dedddedddgZg ZdZed Z	dZ
dS )TestHelpBiggerPositionalsz4Make sure that help aligns when arguments are longerUSAGEr(  )r&  r}  z-xr   zX HELP)r   r~  z--yzY HELP)r~  ZekiekiekifekangzEKI HELPr   zBAR HELPz        usage: USAGE
        a   
        DESCRIPTION

        positional arguments:
          ekiekiekifekang  EKI HELP
          bar              BAR HELP

        optional arguments:
          -h, --help       show this help message and exit
          -x               X HELP
          --y Y            Y HELP
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   r-  w  s   

r-  c               @   sf   e Zd ZdZedddZedddded	d
ddgZedddeddddgfgZdZed Z	dZ
dS )TestHelpReformattingz>Make sure that text after short names starts on the first liner{  ze   oddly    formatted
description

that is so long that it should go onto multiple lines when wrapped)r|  r}  z-xr	  zoddly
    formatted -x help)r  r~  r   r   znormal y helpr  z'
    oddly formatted group

description)r}  z-ar   z` oddly 
formatted    -a  help  
    again, so long that it should be wrapped over multiple lines)r   r~  z2        usage: PROG [-h] [-x XX] [-a] yyy
        a  
        oddly formatted description that is so long that it should go onto multiple
        lines when wrapped

        positional arguments:
          yyy         normal y help

        optional arguments:
          -h, --help  show this help message and exit
          -x XX       oddly formatted -x help

        title:
          oddly formatted group description

          -a          oddly formatted -a help again, so long that it should be wrapped
                      over multiple lines
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   r/    s   
r/  c               @   sb   e Zd ZdZedddZedddded	d
ddgZededdddgfgZdZed Z	dZ
dS )TestHelpWrappingShortNamesz>Make sure that text after short names starts on the first liner{  zZD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
DD
D)r|  r}  z-xr	  zxXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HX)r  r~  r   r   zdYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHALPHASz-ar   zPAHHH HHAAHHH HHAAHHH HHAAHHH HHAAHHH HHAAHHH HHAAHHH HHAAHHH HHAAHHH HHAAHHH HHA)r   r~  z2        usage: PROG [-h] [-x XX] [-a] yyy
        a  
        D DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD
        DD DD DD DD D

        positional arguments:
          yyy         YH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH
                      YHYH YHYH YHYH YHYH YHYH YHYH YHYH YH

        optional arguments:
          -h, --help  show this help message and exit
          -x XX       XHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH
                      HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HX

        ALPHAS:
          -a          AHHH HHAAHHH HHAAHHH HHAAHHH HHAAHHH HHAAHHH HHAAHHH HHAAHHH
                      HHAAHHH HHAAHHH HHA
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   r0    s   r0  c               @   s|   e Zd ZdZedddZeddddd	ed
dddeddddgZededdddeddddgfgZdZed Z	dZ
dS )TestHelpWrappingLongNamesz<Make sure that text after long names starts on the next liner.  zZD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD D)r&  r}  z-vz	--versionr"  zZV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV V)r   r"  z-xXXXXXXXXXXXXXXXXXXXXXXXXXzdXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XH)r  r~  r   ZyyyyyyyyyyyyyyyyyyyyyyyyyzdYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHr1  z-aZAAAAAAAAAAAAAAAAAAAAAAAAAzdAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHr   ZzzzzzzzzzzzzzzzzzzzzzzzzzzdZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHz        usage: USAGE
        ar  
        D DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD
        DD DD DD DD D

        positional arguments:
          yyyyyyyyyyyyyyyyyyyyyyyyy
                                YH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH
                                YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YH

        optional arguments:
          -h, --help            show this help message and exit
          -v, --version         show program's version number and exit
          -x XXXXXXXXXXXXXXXXXXXXXXXXX
                                XH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH
                                XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XH

        ALPHAS:
          -a AAAAAAAAAAAAAAAAAAAAAAAAA
                                AH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH
                                AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AH
          zzzzzzzzzzzzzzzzzzzzzzzzz
                                ZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH
                                ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZH
        zs        V VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV
        VV VV VV VV V
        N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   r2    s   r2  c            	   @   s   e Zd ZdZeddZeddddedd	d
dedddeddddeddddgZededdddeddddeddd	deddddgfgZdZed Z	dZ
dS )TestHelpUsagezTest basic usage messagesr{  )r|  z-wr   r'   )r   r~  z-xr   r   r   )r~  r   r   )r~  r   r   r   rd   z-yr   z-zr   r   r  rq  z        usage: PROG [-h] [-w W [W ...]] [-x [X [X ...]]] [-y [Y]] [-z Z Z Z]
                    a b b [c] [d [d ...]] e [e ...]
        a  
        positional arguments:
          a               a
          b               b
          c               c

        optional arguments:
          -h, --help      show this help message and exit
          -w W [W ...]    w
          -x [X [X ...]]  x

        group:
          -y [Y]          y
          -z Z Z Z        z
          d               d
          e               e
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   r4  (  s    

r4  c               @   sp   e Zd ZdZedddZg Zededdded	d	dgfed
edddedddgfgZdZed Z	dZ
dS )TestHelpOnlyUserGroupszTest basic usage messagesr{  F)r|  r   Zxxxxz-xr   )r~  r   Zyyyyr   z-yr   z.        usage: PROG [-x X] [-y Y] a b
        zn
        xxxx:
          -x X  x
          a     a

        yyyy:
          b     b
          -y Y  y
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   r5  T  s   

	r5  c               @   sR   e Zd ZdZeddZedddeddded	ed
gZg ZdZed Z	dZ
dS )TestHelpUsageLongProgz*Test usage messages where the prog is long<PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP)r|  z-wr  )r  z-xr   r   r   zz        usage: PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
               [-h] [-w W] [-x X] a b
        z
        positional arguments:
          a
          b

        optional arguments:
          -h, --help  show this help message and exit
          -w W
          -x X
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   r6  s  s   




r6  c               @   sf   e Zd ZdZeddZedddeddded	d
dedddededgZg ZdZed Z	dZ
dS ) TestHelpUsageLongProgOptionsWrapzATest usage messages where the prog is long and the optionals wrapr7  )r|  z-wWWWWWWWWWWWWWWWWWWWWWWWWW)r  z-xr3  z-yYYYYYYYYYYYYYYYYYYYYYYYYYz-zZZZZZZZZZZZZZZZZZZZZZZZZZr   r   a          usage: PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
               [-h] [-w WWWWWWWWWWWWWWWWWWWWWWWWW] [-x XXXXXXXXXXXXXXXXXXXXXXXXX]
               [-y YYYYYYYYYYYYYYYYYYYYYYYYY] [-z ZZZZZZZZZZZZZZZZZZZZZZZZZ]
               a b
        a8  
        positional arguments:
          a
          b

        optional arguments:
          -h, --help            show this help message and exit
          -w WWWWWWWWWWWWWWWWWWWWWWWWW
          -x XXXXXXXXXXXXXXXXXXXXXXXXX
          -y YYYYYYYYYYYYYYYYYYYYYYYYY
          -z ZZZZZZZZZZZZZZZZZZZZZZZZZ
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   r8    s   





r8  c               @   sF   e Zd ZdZedddZedededgZg ZdZed	 Z	d
Z
dS )$TestHelpUsageLongProgPositionalsWrapzCTest usage messages where the prog is long and the positionals wrapr7  F)r|  r   aaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccz        usage: PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
               aaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbb
               ccccccccccccccccccccccccc
        z
        positional arguments:
          aaaaaaaaaaaaaaaaaaaaaaaaa
          bbbbbbbbbbbbbbbbbbbbbbbbb
          ccccccccccccccccccccccccc
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   r<    s   
r<  c               @   sl   e Zd ZdZeddZedddeddded	d
dedddedededgZg ZdZed Z	dZ
dS )TestHelpUsageOptionalsWrapz,Test usage messages where the optionals wrapr{  )r|  z-wr9  )r  z-xr3  z-yr:  z-zr;  r   r   r   z        usage: PROG [-h] [-w WWWWWWWWWWWWWWWWWWWWWWWWW] [-x XXXXXXXXXXXXXXXXXXXXXXXXX]
                    [-y YYYYYYYYYYYYYYYYYYYYYYYYY] [-z ZZZZZZZZZZZZZZZZZZZZZZZZZ]
                    a b c
        aD  
        positional arguments:
          a
          b
          c

        optional arguments:
          -h, --help            show this help message and exit
          -w WWWWWWWWWWWWWWWWWWWWWWWWW
          -x XXXXXXXXXXXXXXXXXXXXXXXXX
          -y YYYYYYYYYYYYYYYYYYYYYYYYY
          -z ZZZZZZZZZZZZZZZZZZZZZZZZZ
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   r@    s   





r@  c               @   sV   e Zd ZdZeddZedededededed	gZg Zd
Zed Z	dZ
dS )TestHelpUsagePositionalsWrapz.Test usage messages where the positionals wrapr{  )r|  z-xz-yz-zr=  r>  r?  z        usage: PROG [-h] [-x X] [-y Y] [-z Z]
                    aaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbb
                    ccccccccccccccccccccccccc
        a  
        positional arguments:
          aaaaaaaaaaaaaaaaaaaaaaaaa
          bbbbbbbbbbbbbbbbbbbbbbbbb
          ccccccccccccccccccccccccc

        optional arguments:
          -h, --help            show this help message and exit
          -x X
          -y Y
          -z Z
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rA    s   

rA  c               @   sb   e Zd ZdZeddZedddeddded	d
dedededgZg ZdZed Z	dZ
dS )%TestHelpUsageOptionalsPositionalsWrapz<Test usage messages where the optionals and positionals wrapr{  )r|  z-xr3  )r  z-yr:  z-zr;  r=  r>  r?  a          usage: PROG [-h] [-x XXXXXXXXXXXXXXXXXXXXXXXXX] [-y YYYYYYYYYYYYYYYYYYYYYYYYY]
                    [-z ZZZZZZZZZZZZZZZZZZZZZZZZZ]
                    aaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbb
                    ccccccccccccccccccccccccc
        ae  
        positional arguments:
          aaaaaaaaaaaaaaaaaaaaaaaaa
          bbbbbbbbbbbbbbbbbbbbbbbbb
          ccccccccccccccccccccccccc

        optional arguments:
          -h, --help            show this help message and exit
          -x XXXXXXXXXXXXXXXXXXXXXXXXX
          -y YYYYYYYYYYYYYYYYYYYYYYYYY
          -z ZZZZZZZZZZZZZZZZZZZZZZZZZ
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rB    s   




rB  c               @   sP   e Zd ZdZeddZedddeddded	d
dgZg ZdZed Z	dZ
dS )TestHelpUsageOptionalsOnlyWrapz@Test usage messages where there are only optionals and they wrapr{  )r|  z-xr3  )r  z-yr:  z-zr;  z        usage: PROG [-h] [-x XXXXXXXXXXXXXXXXXXXXXXXXX] [-y YYYYYYYYYYYYYYYYYYYYYYYYY]
                    [-z ZZZZZZZZZZZZZZZZZZZZZZZZZ]
        z
        optional arguments:
          -h, --help            show this help message and exit
          -x XXXXXXXXXXXXXXXXXXXXXXXXX
          -y YYYYYYYYYYYYYYYYYYYYYYYYY
          -z ZZZZZZZZZZZZZZZZZZZZZZZZZ
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rC  9  s   


rC  c               @   sF   e Zd ZdZedddZedededgZg ZdZed	 Z	d
Z
dS ) TestHelpUsagePositionalsOnlyWrapzBTest usage messages where there are only positionals and they wrapr{  F)r|  r   r=  r>  r?  z~        usage: PROG aaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbb
                    ccccccccccccccccccccccccc
        z
        positional arguments:
          aaaaaaaaaaaaaaaaaaaaaaaaa
          bbbbbbbbbbbbbbbbbbbbbbbbb
          ccccccccccccccccccccccccc
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rD  S  s   
rD  c            
   @   s   e Zd ZdZeddZededdeddd	d
ddeddddeddddgdddedddeddddgZeded d!ded"d#d$dgfgZd%Z	e	d& Z
d'Zd(S ))TestHelpVariableExpansionz:Test that variables are expanded properly in help messagesr{  )r|  z-xz"x %(prog)s %(default)s %(type)s %%)r:   r~  z-yr   r   XXXz y %(prog)s %(default)s %(const)s)r   r   r   r~  z--foor   z$foo %(prog)s %(default)s %(choices)s)r   r~  z--barr   rE   r   ZBBBz!bar %(prog)s %(default)s %(dest)s)r   r   r  r~  r   zspam %(prog)s %(default)s)r~  r   g      ?zbadger %(prog)s %(default)s)r   r~  rd   z-aza %(prog)s %(default)sz-brZ  zb %(prog)s %(default)szw        usage: PROG [-h] [-x X] [-y] [--foo {a,b,c}] [--bar BBB] [-a A] [-b B]
                    spam badger
        a  
        positional arguments:
          spam           spam PROG None
          badger         badger PROG 0.5

        optional arguments:
          -h, --help     show this help message and exit
          -x X           x PROG None int %
          -y             y PROG 42 XXX
          --foo {a,b,c}  foo PROG None a, b, c
          --bar BBB      bar PROG baz bar

        group:
          -a A           a PROG None
          -b B           b PROG -1
        r   N)r   r   r   r   r.   r[   r   r_   r!  r&  r~  r"  r	   r	   r	   r
   rE  k  s&   



rE  c               @   s4   e Zd ZdZedddZg Zg ZdZed Z	dZ
dS )	&TestHelpVariableExpansionUsageSuppliedz@Test that variables are expanded properly when usage= is presentr{  z%(prog)s FOO)r|  r&  z         usage: PROG FOO
        z[
        optional arguments:
          -h, --help  show this help message and exit
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rG    s   rG  c               @   s0   e Zd ZdZedddZg Zg ZdZeZ	dZ
dS )$TestHelpVariableExpansionNoArgumentsz;Test that variables are expanded properly with no argumentsr{  F)r|  r   z        usage: PROG
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rH    s   rH  c               @   sF   e Zd ZdZedejdZedddedddgZg Z	d	Z
d
Zd
ZdS )TestHelpSuppressUsagez3Test that items can be suppressed in usage messagesr{  )r|  r&  z--foozfoo help)r~  r   z	spam helpz        positional arguments:
          spam        spam help

        optional arguments:
          -h, --help  show this help message and exit
          --foo FOO   foo help
        r   N)r   r   r   r   r.   r  r  r[   r_   r!  r~  r&  r"  r	   r	   r	   r
   rI    s   
rI  c               @   sJ   e Zd ZdZedddZedejdedddgZg Z	d	Z
e
d
 ZdZdS )TestHelpSuppressOptionalz?Test that optional arguments can be suppressed in help messagesr{  F)r|  r   z--foo)r~  r   z	spam helpz!        usage: PROG spam
        zA
        positional arguments:
          spam  spam help
        r   N)r   r   r   r   r.   r[   r  r  r_   r!  r&  r~  r"  r	   r	   r	   r
   rJ    s   rJ  c               @   s\   e Zd ZdZeddZedddedddgZed	ed
ejdgfgZ	dZ
e
d ZdZdS )TestHelpSuppressOptionalGroupz<Test that optional groups can be suppressed in help messagesr{  )r|  z--foozfoo help)r~  r   z	spam helprd   z--barz2        usage: PROG [-h] [--foo FOO] spam
        z
        positional arguments:
          spam        spam help

        optional arguments:
          -h, --help  show this help message and exit
          --foo FOO   foo help
        r   N)r   r   r   r   r.   r[   r_   r  r  r!  r&  r~  r"  r	   r	   r	   r
   rK    s   

rK  c               @   sH   e Zd ZdZeddZedddedejdgZg Z	dZ
e
d	 Zd
ZdS )TestHelpSuppressPositionalzATest that positional arguments can be suppressed in help messagesr{  )r|  z--foozfoo help)r~  r   z-        usage: PROG [-h] [--foo FOO]
        zz
        optional arguments:
          -h, --help  show this help message and exit
          --foo FOO   foo help
        r   N)r   r   r   r   r.   r[   r  r  r_   r!  r&  r~  r"  r	   r	   r	   r
   rL    s   

rL  c               @   s>   e Zd ZdZeddZeddddgZg ZdZed	 Z	d
Z
dS )TestHelpRequiredOptionalz.Test that required options don't look optionalr{  )r|  z--fooTzfoo help)r   r~  z+        usage: PROG [-h] --foo FOO
        zz
        optional arguments:
          -h, --help  show this help message and exit
          --foo FOO   foo help
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rM    s   
rM  c               @   sN   e Zd ZdZeddddZedddd	ed
dddgZg ZdZed Z	dZ
dS )TestHelpAlternatePrefixCharsz:Test that options display with different prefix charactersr{  z^;F)r|  r   r   z^^foor   zfoo help)r   r~  z;bz;;barzbar help)r~  z-        usage: PROG [^^foo] [;b BAR]
        zq
        optional arguments:
          ^^foo              foo help
          ;b BAR, ;;bar BAR  bar help
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rN  #  s   rN  c               @   sH   e Zd ZdZedddZedddedd	dgZg Zd
Zed Z	dZ
dS )TestHelpNoHelpOptionalz=Test that the --help argument can be suppressed help messagesr{  F)r|  r   z--foozfoo help)r~  r   z	spam helpz-        usage: PROG [--foo FOO] spam
        z
        positional arguments:
          spam       spam help

        optional arguments:
          --foo FOO  foo help
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rO  8  s   
rO  c               @   s>   e Zd ZdZeddZededgZg ZdZed Z	dZ
d	S )
TestHelpNonez1Test that no errors occur if no help is specifiedr{  )r|  z--foor   z2        usage: PROG [-h] [--foo FOO] spam
        z
        positional arguments:
          spam

        optional arguments:
          -h, --help  show this help message and exit
          --foo FOO
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rP  O  s   

rP  c            	   @   sj   e Zd ZdZeddZeddddded	d
dddedddddedddddgZg ZdZed Z	dZ
dS )TestHelpTupleMetavarz"Test specifying metavar as a tupler{  )r|  z-wr'   r   )ZW1ZW2)r~  r   r  z-xr   r   )ZX1ZX2z-yr   r   )ZY1ZY2ZY3z-zr   r   )ZZ1z]        usage: PROG [-h] [-w W1 [W2 ...]] [-x [X1 [X2 ...]]] [-y Y1 Y2 Y3] [-z [Z1]]
        z
        optional arguments:
          -h, --help        show this help message and exit
          -w W1 [W2 ...]    w
          -x [X1 [X2 ...]]  x
          -y Y1 Y2 Y3       y
          -z [Z1]           z
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rQ  g  s   
rQ  c               @   sd   e Zd ZdZedejddZedddedd	dgZed
ddedddgfgZ	dZ
e
d ZdZdS )TestHelpRawTextzTest the RawTextHelpFormatterr{  z7Keep the formatting
    exactly as it is written

here
)r|  formatter_classr}  z--fooz-    foo help should also
appear as given here)r~  r   z	spam helpr  z?    This text
  should be indented
    exactly like it is here
)r}  z--barzbar helpz>        usage: PROG [-h] [--foo FOO] [--bar BAR] spam
        a  
        Keep the formatting
            exactly as it is written

        here

        positional arguments:
          spam        spam help

        optional arguments:
          -h, --help  show this help message and exit
          --foo FOO       foo help should also
                      appear as given here

        title:
              This text
            should be indented
              exactly like it is here

          --bar BAR   bar help
        r   N)r   r   r   r   r.   r  RawTextHelpFormatterr[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rR    s   

rR  c               @   sd   e Zd ZdZedejddZedddedd	dgZed
ddedddgfgZ	dZ
e
d ZdZdS )TestHelpRawDescriptionzTest the RawTextHelpFormatterr{  z7Keep the formatting
    exactly as it is written

here
)r|  rS  r}  z--fooz4  foo help should not
    retain this odd formatting)r~  r   z	spam helpr  z?    This text
  should be indented
    exactly like it is here
)r}  z--barzbar helpz>        usage: PROG [-h] [--foo FOO] [--bar BAR] spam
        a  
        Keep the formatting
            exactly as it is written

        here

        positional arguments:
          spam        spam help

        optional arguments:
          -h, --help  show this help message and exit
          --foo FOO   foo help should not retain this odd formatting

        title:
              This text
            should be indented
              exactly like it is here

          --bar BAR   bar help
        r   N)r   r   r   r   r.   r  RawDescriptionHelpFormatterr[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rU    s   

rU  c            	   @   s   e Zd ZdZedejddZedddedd	d
dedddedddddgZedddede	dddgfgZ
dZed ZdZdS )TestHelpArgumentDefaultsz&Test the ArgumentDefaultsHelpFormatterr{  r}  )r|  rS  r}  z--fooz)foo help - oh and by the way, %(default)s)r~  z--barr   zbar help)r   r~  r   z	spam helpr   r   Zwoodenzbadger help)r   r   r~  r  )r}  z--bazr   zbaz help)r:   r   r~  zO        usage: PROG [-h] [--foo FOO] [--bar] [--baz BAZ] spam [badger]
        a  
        description

        positional arguments:
          spam        spam help
          badger      badger help (default: wooden)

        optional arguments:
          -h, --help  show this help message and exit
          --foo FOO   foo help - oh and by the way, None
          --bar       bar help (default: False)

        title:
          description

          --baz BAZ   baz help (default: 42)
        r   N)r   r   r   r   r.   r  ArgumentDefaultsHelpFormatterr[   r_   r   r!  r&  r~  r"  r	   r	   r	   r
   rW    s   


rW  c               @   sB   e Zd ZdZedddZeddddd	gZg Zd
Zed Z	dZ
dS )TestHelpVersionActionz,Test the default help for the version actionr{  r}  )r|  r}  z-Vz	--versionr"  z3.6)r   r"  z&        usage: PROG [-h] [-V]
        z
        description

        optional arguments:
          -h, --help     show this help message and exit
          -V, --version  show program's version number and exit
        r   N)r   r   r   r   r.   r[   r_   r!  r&  r~  r"  r	   r	   r	   r
   rY    s   rY  c               @   sT   e Zd ZdZeddZeddddejded	d
dedddgZg Z	dZ
e
d ZdS )TestHelpVersionActionSuppresszCTest that the --version argument can be suppressed in help messagesr{  )r|  z-vz	--versionr"  z1.0)r   r"  r~  z--foozfoo help)r~  r   z	spam helpz2        usage: PROG [-h] [--foo FOO] spam
        z
        positional arguments:
          spam        spam help

        optional arguments:
          -h, --help  show this help message and exit
          --foo FOO   foo help
        N)r   r   r   r   r.   r[   r  r  r_   r!  r&  r~  r	   r	   r	   r
   rZ    s   


rZ  c               @   sL   e Zd ZdZedddZeddddd	gZd
d dD ZdZed Z	dZ
dS )TestHelpSubparsersOrderingz5Test ordering of subcommands in help matches the coder{  zdisplay some subcommands)r|  r}  z-vz	--versionr"  z0.1)r   r"  c             C   s   g | ]}t |d qS ))r%   )r.   )r5   r%   r	   r	   r
   r7   >  s   z%TestHelpSubparsersOrdering.<listcomp>)r   r   r   r  rq  z6        usage: PROG [-h] [-v] {a,b,c,d,e} ...
        z
        display some subcommands

        positional arguments:
          {a,b,c,d,e}

        optional arguments:
          -h, --help     show this help message and exit
          -v, --version  show program's version number and exit
        z        0.1
        N)r   r   r   r   r.   r[   r_   r"  r&  r~  r"  r	   r	   r	   r
   r[  8  s   
r[  c               @   sP   e Zd ZdZedddZeddddd	gZd
Zdd eD ZdZ	e	d Z
dZdS )"TestHelpSubparsersWithHelpOrderingz5Test ordering of subcommands in help matches the coder{  zdisplay some subcommands)r|  r}  z-vz	--versionr"  z0.1)r   r"  ))r   za subcommand help)r   zb subcommand help)r   zc subcommand help)r  zd subcommand help)rq  ze subcommand helpc             C   s   g | ]\}}t ||d qS ))r%   r~  )r.   )r5   r%   r~  r	   r	   r
   r7   b  s   z-TestHelpSubparsersWithHelpOrdering.<listcomp>z6        usage: PROG [-h] [-v] {a,b,c,d,e} ...
        a  
        display some subcommands

        positional arguments:
          {a,b,c,d,e}
            a            a subcommand help
            b            b subcommand help
            c            c subcommand help
            d            d subcommand help
            e            e subcommand help

        optional arguments:
          -h, --help     show this help message and exit
          -v, --version  show program's version number and exit
        z        0.1
        N)r   r   r   r   r.   r[   r_   Zsubcommand_datar"  r&  r~  r"  r	   r	   r	   r
   r\  U  s   r\  c               @   s`   e Zd ZdZdd ZeddejdZede	ded	eded
e
ddgZg ZdZed ZdZdS )TestHelpMetavarTypeFormatterr   c             C   s   | S )Nr	   )rh  r	   r	   r
   custom_type  s    z(TestHelpMetavarTypeFormatter.custom_typer{  r}  )r|  r}  rS  r   )r:   z-bz-cz
SOME FLOAT)r:   r  zF        usage: PROG [-h] [-b custom_type] [-c SOME FLOAT] int
        z
        description

        positional arguments:
          int

        optional arguments:
          -h, --help      show this help message and exit
          -b custom_type
          -c SOME FLOAT
        N)r   r   r   r   r^  r.   r  MetavarTypeHelpFormatterr[   r   r  r_   r!  r&  r~  r"  r	   r	   r	   r
   r]    s   


r]  c               @   s   e Zd ZdZdd Zd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 )!TestInvalidArgumentConstructorsz-Test a bunch of invalid Argument constructorsc             O   s"   t  }| jt|jf|| d S )N)r  rj  r|   rs   r]   )r   r/   r0   r^   r	   r	   r
   assertTypeError  s    z/TestInvalidArgumentConstructors.assertTypeErrorc             O   s"   t  }| jt|jf|| d S )N)r  rj  r|   r  r]   )r   r/   r0   r^   r	   r	   r
   assertValueError  s    z0TestInvalidArgumentConstructors.assertValueErrorc             C   s<   | j dd d | j ddd | j ddd | j di d d S )	Nz-x)r   z-yrb   )callbackr	   )Zcallback_args)Zcallback_kwargs)ra  )r   r	   r	   r
   test_invalid_keyword_arguments  s    z>TestInvalidArgumentConstructors.test_invalid_keyword_argumentsc             C   s&   |    xdD ]}| j |d qW d S )N)r   r   )r   )ra  )r   r   r	   r	   r
   test_missing_destination  s    
z8TestInvalidArgumentConstructors.test_missing_destinationc             C   s   |  d |  d d S )Nz--z---)rb  )r   r	   r	   r
   test_invalid_option_strings  s    
z;TestInvalidArgumentConstructors.test_invalid_option_stringsc             C   s$   | j ddd | j dttfd d S )Nz--foor   )r:   )rb  r   r  )r   r	   r	   r
   test_invalid_type  s    z1TestInvalidArgumentConstructors.test_invalid_typec          	   C   sl   | j ddd | j ddd | j ddd t }| t}|jddd W d Q R X | dt|j d S )	Nz-xrb   )r   r   z--foo)r   r   z
store-truezunknown action)	rb  r  rj  r|   r  r]   r  r   r  )r   r^   r  r	   r	   r
   test_invalid_action  s    z3TestInvalidArgumentConstructors.test_invalid_actionc          	   C   sN   t  }|jdd | t}|jddd W d Q R X | dt|j d S )Nrb   )r   r   r   z+dest supplied twice for positional argument)r  rj  r]   r|   r  r  r   r  )r   r^   r  r	   r	   r
   test_multiple_dest  s    z2TestInvalidArgumentConstructors.test_multiple_destc             C   sL   xFdD ]>}x8t tdt ddt ddgD ]}| jd	d|i| q(W qW d S )
N)r   r   r   r   r   )r:   r   )r   Zab)r   -xr   )rj  )r  r   ra  )r   r   Zattrsr	   r	   r
   test_no_argument_actions  s    
z8TestInvalidArgumentConstructors.test_no_argument_actionsc             C   s2   x,dD ]$}| j dd|d | j dd|d qW d S )N)r   r   r   z-xrb   )r   r   r   )r   r   )ra  )r   r   r	   r	   r
   !test_no_argument_no_const_actions  s    
zATestInvalidArgumentConstructors.test_no_argument_no_const_actionsc             C   sd   x^dD ]V}| j dd|d | j dd|d x0dD ](}| j dd||d | j dd||d q0W qW d S )	N)r   r   z-xr   )r   r   r   )rE   r   r   rb   )r   r   r   )rb  )r   r   r   r	   r	   r
   #test_more_than_one_argument_actions  s    


zCTestInvalidArgumentConstructors.test_more_than_one_argument_actionsc             C   s"   xdD ]}| j dd|d qW d S )N)r   r   z-xr   )r   r   )ra  )r   r   r	   r	   r
   test_required_const_actions  s    
z;TestInvalidArgumentConstructors.test_required_const_actionsc             C   s4   | j ddd | j dddd | j ddtjd d S )Nr  parsers)r   r{  )r   r|  )r   r\   )ra  r  rj  )r   r	   r	   r
   "test_parsers_action_missing_params  s    zBTestInvalidArgumentConstructors.test_parsers_action_missing_paramsc             C   s   | j ddd d S )Nrb   T)r   )ra  )r   r	   r	   r
   test_required_positional  s    z8TestInvalidArgumentConstructors.test_required_positionalc                s`   G dd dt  G  fdddt}t }| j |jd|  d | j |jd|  d d S )Nc               @   s   e Zd ZdS )zITestInvalidArgumentConstructors.test_user_defined_action.<locals>.SuccessN)r   r   r   r	   r	   r	   r
   Success  s   rr  c                   s"   e Zd Zd fdd	Zdd ZdS )zHTestInvalidArgumentConstructors.test_user_defined_action.<locals>.ActionFc                s"   |dkr| kr| kr  d S )Nr   r	   )r   option_stringsr   r   r   r   )rr  r	   r
   r1     s    zQTestInvalidArgumentConstructors.test_user_defined_action.<locals>.Action.__init__c             _   s   d S )Nr	   )r   r/   r0   r	   r	   r
   rr    s    zQTestInvalidArgumentConstructors.test_user_defined_action.<locals>.Action.__call__N)F)r   r   r   r1   rr  r	   )rr  r	   r
   ru    s   ru  z--spam)r   r   r   r   )r@   r   r  rj  r|   r]   )r   ru  r^   r	   )rr  r
   test_user_defined_action  s    z8TestInvalidArgumentConstructors.test_user_defined_actionN)r   r   r   r   ra  rb  rd  re  rf  rg  rh  ri  rk  rl  rm  rn  rp  rq  rt  r	   r	   r	   r
   r`    s    	
r`  c               @   s   e Zd Zdd Zdd ZdS )TestActionsReturnedc             C   sX   t  }|d}| |jd |dd}| |jd |dd}| |jd d S )	Nz--foorb   z-bz--barr   z-xz-yr   )r  rj  r]   r   r   )r   r^   r   r	   r	   r
   r  "  s    
zTestActionsReturned.test_destc             C   s   t  }|jddddtddgddd	d
	}| |jd | |jd | |jd | |jt | |j	ddg | |j
d | |jd | |jd	 d S )Nz--foor   r   r   rE   r   r  ZBARr   )r   r   r   r:   r   r~  r  r   )r  rj  r]   r   r   r   r   r   r:   r   r~  r  r   )r   r^   r   r	   r	   r
   	test_misc+  s    

zTestActionsReturned.test_miscN)r   r   r   r  rv  r	   r	   r	   r
   ru     s   	ru  c               @   s$   e Zd Zdd Zdd Zdd ZdS )TestConflictHandlingc             C   s   | j ttjdd d S )Nrb   )conflict_handler)r|   r  r  rj  )r   r	   r	   r
   test_bad_type@  s    
z"TestConflictHandling.test_bad_typec             C   sD   t  }|d | t j|jd |d | t j|jd d S )Nz-xz--spam)r  rj  r]   r|   r  )r   r^   r	   r	   r
   test_conflict_errorD  s    


z(TestConflictHandling.test_conflict_errorc             C   sz   t j}|ddd}|jddd |jddd | | td |jd	d
d |jd	dd | | td d S )Nr{  Zresolve)r|  rx  z-xzOLD X)r~  zNEW Xz            usage: PROG [-h] [-x X]

            optional arguments:
              -h, --help  show this help message and exit
              -x X        NEW X
            z--spamZOLD_SPAM)r  ZNEW_SPAMz            usage: PROG [-h] [-x X] [--spam NEW_SPAM]

            optional arguments:
              -h, --help       show this help message and exit
              -x X             NEW X
              --spam NEW_SPAM
            )r  rj  r]   r   r  r  r  )r   r  r^   r	   r	   r
   test_resolve_errorM  s    z'TestConflictHandling.test_resolve_errorN)r   r   r   ry  rz  r{  r	   r	   r	   r
   rw  >  s   	rw  c               @   sX   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd ZdS )TestOptionalsHelpVersionActionsz!Test the help and version actionsc          	   C   s<   |  t}||  W d Q R X | | |jj d S )N)r|   r?   rO   r{   r   r  r  rB   )r   r^   r}   r  r	   r	   r
   assertPrintHelpExitn  s    z3TestOptionalsHelpVersionActions.assertPrintHelpExitc             G   s   |  t|j| d S )N)r|   r?   rO   )r   r^   r/   r	   r	   r
   rz  s  s    z9TestOptionalsHelpVersionActions.assertArgumentParserErrorc             C   sD   t  }|jddddd | |d | |d | tt|d d S )	Nz-vz	--versionr"  z1.0)r   r"  z-hz--helpformat_version)rS   r]   r}  r|   AttributeErrorrJ   )r   r^   r	   r	   r
   test_versionv  s
    z,TestOptionalsHelpVersionActions.test_versionc          	   C   sR   t dd}|jddddd | t}|dg W d Q R X | d|jj d S )	NZPPP)r|  z-vz	--versionr"  z%(prog)s 3.5)r   r"  zPPP 3.5
)rS   r]   r|   r?   rO   r   r  rB   )r   r^   r  r	   r	   r
   test_version_format}  s
    
z3TestOptionalsHelpVersionActions.test_version_formatc             C   sH   t dd}|jddddd | |d | |d	 | tt|d
 d S )NF)r   z-vz	--versionr"  z1.0)r   r"  z-hz--helpr~  )rS   r]   rz  r|   r  rJ   )r   r^   r	   r	   r
   test_version_no_help  s
    
z4TestOptionalsHelpVersionActions.test_version_no_helpc          	   C   sP   t dd}|jdddd | t}|dg W d Q R X | d|jj d S )NrF  )r|  z-Vr"  z%(prog)s 3.7)r   r"  zXXX 3.7
)rS   r]   r|   r?   rO   r   r  rB   )r   r^   r  r	   r	   r
   test_version_action  s
    
z3TestOptionalsHelpVersionActions.test_version_actionc             C   s>   t dd}| |d | |d | |d | |d d S )NF)r   z-hz--helpz-vz	--version)rS   rz  )r   r^   r	   r	   r
   test_no_help  s
    
z,TestOptionalsHelpVersionActions.test_no_helpc             C   sZ   t  }|jddd |jddd | |d | |d | |d | tt|d d S )	Nz-xr~  )r   z-yr"  z-vz	--versionr~  )rS   r]   r}  rz  r|   r  rJ   )r   r^   r	   r	   r
   test_alternate_help_version  s    z;TestOptionalsHelpVersionActions.test_alternate_help_versionc             C   s   t  }|jdddd |jddd |d d	dd
ddg}|ddg }xV|D ]N}x|D ]}d||f }qXW | ||d  | ||d  | tt|d qNW d S )Nz	--versionr"  z1.0)r   r"  z-xr   )r   r   r   rb   z-x barzbaz -xz--bad-optionzfoo bar bazz	%s %%s %sz-hz--helpr~  )rS   r]   r}  r|   r  rJ   )r   r^   Zvalid_prefixesZvalid_suffixesprefixsuffixr  r	   r	   r
   !test_help_version_extra_arguments  s    


zATestOptionalsHelpVersionActions.test_help_version_extra_argumentsN)r   r   r   r   r}  rz  r  r  r  r  r  r  r  r	   r	   r	   r
   r|  k  s   	r|  c               @   sP   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdS )TestStringsz3Test str()  and repr() on Optionals and Positionalsc             C   s&   x t tgD ]}| ||| q
W d S )N)r   r4  r   )r   objZresult_stringfuncr	   r	   r
   assertStringEqual  s    zTestStrings.assertStringEqualc          
   C   s:   t jdddgdddddd	d
gddd}d}| || d S )Nz--fooz-az-br   r   r   r   rE   r   r   ZHELPZMETAVAR)rs  r   r:   r   r   r   r~  r  zAction(option_strings=['--foo', '-a', '-b'], dest='b', nargs='+', const=None, default=42, type='int', choices=[1, 2, 3], help='HELP', metavar='METAVAR'))r  ru  r  )r   optionrh  r	   r	   r
   test_optional  s    zTestStrings.test_optionalc          
   C   s8   t jg dtdddddgddd}d	t }| || d S )
Nr   r   g      @g      ?g      ?zH HH HzMV MV MV)rs  r   r:   r   r   r   r~  r  zAction(option_strings=[], dest='x', nargs='?', const=None, default=2.5, type=%r, choices=[0.5, 1.5, 2.5], help='H HH H', metavar='MV MV MV'))r  ru  r  r  )r   argumentrh  r	   r	   r
   test_argument  s    zTestStrings.test_argumentc             C   s"   t jddd}d}| || d S )Nr   r   )rb   r   zNamespace(bar='spam', foo=42))r  r  r  )r   r  rh  r	   r	   r
   test_namespace  s    zTestStrings.test_namespacec             C   s$   t jf ddi}d}| || d S )N"quotezNamespace(**{'"': 'quote'}))r  r  r  )r   r  rh  r	   r	   r
   'test_namespace_starkwargs_notidentifier  s    z3TestStrings.test_namespace_starkwargs_notidentifierc             C   s,   t jf ddiddi}d}| || d S )Nr   rE   r  r  z Namespace(a=1, **{'"': 'quote'}))r  r  r  )r   r  rh  r	   r	   r
   2test_namespace_kwargs_and_starkwargs_notidentifier  s    z>TestStrings.test_namespace_kwargs_and_starkwargs_notidentifierc             C   s$   t jf ddi}d}| || d S )NZvalidTzNamespace(valid=True))r  r  r  )r   r  rh  r	   r	   r
   $test_namespace_starkwargs_identifier  s    z0TestStrings.test_namespace_starkwargs_identifierc             C   s&   t jdd}dt j }| || d S )Nr{  )r|  zvArgumentParser(prog='PROG', usage=None, description=None, formatter_class=%r, conflict_handler='error', add_help=True))r  rj  HelpFormatterr  )r   r^   rh  r	   r	   r
   test_parser  s    zTestStrings.test_parserN)r   r   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d ZdS )TestNamespacec             C   sF   t  }| tt|d t jddd}| |jd | |jd d S )Nr   r   r   )r   r   )r  r  r|   r  rJ   r   r   r   )r   r  r	   r	   r
   test_constructor   s
    zTestNamespace.test_constructorc             C   s   t jddd}t jddd}t jdd}t jdd}| || | || | || | || | || | ||k | ||k | ||k | ||k d S )NrE   r   )r   r   )r   r   )r   )r   )r  r  r   ZassertNotEqual
assertTrue)r   Zns1Zns2Zns3Zns4r	   r	   r
   test_equality  s    zTestNamespace.test_equalityc             C   s6   t jddd}| |d t | |d t d S )NrE   r   )r   r   )r  r  ZassertIsr>   NotImplemented__ne__)r   r  r	   r	   r
   $test_equality_returns_notimplemented  s    z2TestNamespace.test_equality_returns_notimplementedN)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S )TestEncodingc          	   C   s>   t j|\}}|d7 }t|ddd}|  W d Q R X d S )Nz.pyr2  zutf-8)r9  )r   r   splitextr(   rG  )r   r   rl   r   r	   r	   r
   _test_module_encoding%  s    z"TestEncoding._test_module_encodingc             C   s   |  tj d S )N)r  r  __file__)r   r	   r	   r
   test_argparse_module_encoding+  s    z*TestEncoding.test_argparse_module_encodingc             C   s   |  t d S )N)r  r  )r   r	   r	   r
   "test_test_argparse_module_encoding.  s    z/TestEncoding.test_test_argparse_module_encodingN)r   r   r   r  r  r  r	   r	   r	   r
   r  #  s   r  c               @   s   e Zd Zdd ZdS )TestArgumentErrorc             C   s$   d}t d |}| t|| d S )Nzmy error here)r  r  r   r   )r   ry   rW   r	   r	   r
   test_argument_error7  s    z%TestArgumentError.test_argument_errorN)r   r   r   r  r	   r	   r	   r
   r  5  s   r  c               @   s   e Zd Zdd ZdS )TestArgumentTypeErrorc          	   C   sX   dd }t ddd}|jd|d | t}|dg W d Q R X | d	|jj d S )
Nc             S   s   t dd S )Nzspam!)r  ArgumentTypeError)rh  r	   r	   r
   r   D  s    z<TestArgumentTypeError.test_argument_type_error.<locals>.spamr{  F)r|  r   r   )r:   rF  z-usage: PROG x
PROG: error: argument x: spam!
)rS   r]   r|   r?   rO   r   r  rC   )r   r   r^   r  r	   r	   r
   test_argument_type_errorB  s    z.TestArgumentTypeError.test_argument_type_errorN)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S )TestMessageContentErrorc          	   C   s.  t ddd}|jdtd |jdtdd |jd	td
d | t}|g  W d Q R X t|j}| |d | |d | |d	 | t}|dg W d Q R X t|j}| 	|d | |d | |d	 | t}|ddg W d Q R X t|j}| 	|d | 	|d | |d	 d S )Nr{  r   )r|  r&  req_pos)r:   z-req_optT)r:   r   Zneed_oner   )r:   r   req_optZmyXargumentz
-req_opt=1)
rS   r]   r   r   r|   r?   rO   r  assertRegexr  )r   r^   r  ry   r	   r	   r
   %test_missing_argument_name_in_messageT  s,    


z=TestMessageContentError.test_missing_argument_name_in_messagec          	   C   s   t ddd}|jdtd |jdtdd |jd	td
dd | t}|g  W d Q R X t|j}| 	|d | 	|d | 
|d | t}|dg W d Q R X t|j}| 	|d | 
|d | 
|d d S )Nr{  r   )r|  r&  r  )r:   z	--req_optT)r:   r   z	--opt_optr   )r:   r   r   r  Zopt_optz--req_opt=1)rS   r]   r   r   boolr|   r?   rO   r  r  r  )r   r^   r  ry   r	   r	   r
   %test_optional_optional_not_in_messagem  s"    


z=TestMessageContentError.test_optional_optional_not_in_messagec          	   C   sl   t ddd}|d |jdddd | t}|g  W d Q R X t|j}| |d | |d d S )	Nr{  r   )r|  r&  r  Zoptional_positionalr   r`  )r   r   )	rS   r]   r|   r?   rO   r   r  r  r  )r   r^   r  ry   r	   r	   r
   'test_optional_positional_not_in_message  s    

z?TestMessageContentError.test_optional_positional_not_in_messageN)r   r   r   r  r  r  r	   r	   r	   r
   r  R  s   r  c               @   s   e Zd Zdd ZdS )TestTypeFunctionCallOnlyOncec                sH    fdd}t  }|jd|dd |d } tdd| d S )	Nc                s     | d dS )Nzspam!foo_converted)r   )Zstring_to_convert)r   r	   r
   r     s    zLTestTypeFunctionCallOnlyOnce.test_type_function_call_only_once.<locals>.spamz--foor   )r:   r   z--foo spam!r  )rb   )r  rj  r]   rO   r{   r   r2   )r   r   r^   r/   r	   )r   r
   !test_type_function_call_only_once  s
    z>TestTypeFunctionCallOnlyOnce.test_type_function_call_only_onceN)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 )
TestTypeFunctionCalledOnDefaultc                sD    fdd}t  }|jd|dd |g } tdd| d S )Nc                s     | d dS )Nr   r  )r   )int_to_convert)r   r	   r
   r     s    z]TestTypeFunctionCalledOnDefault.test_type_function_call_with_non_string_default.<locals>.spamz--foor   )r:   r   )rb   )r  rj  r]   rO   r   r2   )r   r   r^   r/   r	   )r   r
   /test_type_function_call_with_non_string_default  s
    
zOTestTypeFunctionCalledOnDefault.test_type_function_call_with_non_string_defaultc             C   s@   dd }t  }|jd|dd |g }| tdd| d S )Nc             S   s   dS )Nr  r	   )r  r	   r	   r
   r     s    zYTestTypeFunctionCalledOnDefault.test_type_function_call_with_string_default.<locals>.spamz--foo0)r:   r   r  )rb   )r  rj  r]   rO   r   r2   )r   r   r^   r/   r	   r	   r
   +test_type_function_call_with_string_default  s
    
zKTestTypeFunctionCalledOnDefault.test_type_function_call_with_string_defaultc             C   s@   dd }t  }|jd|dd |g }| tdd| d S )Nc             S   s   | d S )Nr   r	   )Zstr_to_convertr	   r	   r
   extend  s    zYTestTypeFunctionCalledOnDefault.test_no_double_type_conversion_of_default.<locals>.extendz--testr   )r:   r   z**)rl  )r  rj  r]   rO   r   r2   )r   r  r^   r/   r	   r	   r
   )test_no_double_type_conversion_of_default  s
    
zITestTypeFunctionCalledOnDefault.test_no_double_type_conversion_of_defaultc             C   s8   t  }|jddtg dd |g }| |jg  d S )Nz--testrl  r   )r   r:   r   r   )r  rj  r]   r   rO   r   rl  )r   r^   r/   r	   r	   r
   test_issue_15906  s
    


z0TestTypeFunctionCalledOnDefault.test_issue_15906N)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 )TestParseKnownArgsc             C   s   t  }|d d S )Nr	   )r  rj  rO   )r   r^   r	   r	   r
   test_arguments_tuple  s    z'TestParseKnownArgs.test_arguments_tuplec             C   s   t  }|g  d S )N)r  rj  rO   )r   r^   r	   r	   r
   test_arguments_list  s    z&TestParseKnownArgs.test_arguments_listc             C   s    t  }|d |d d S )Nr   )r   )r  rj  r]   rO   )r   r^   r	   r	   r
   test_arguments_tuple_positional  s    
z2TestParseKnownArgs.test_arguments_tuple_positionalc             C   s"   t  }|d |dg d S )Nr   )r  rj  r]   rO   )r   r^   r	   r	   r
   test_arguments_list_positional  s    
z1TestParseKnownArgs.test_arguments_list_positionalc             C   sJ   t  }|d |d \}}| tdd| | ddg| d S )Nz--fooz--foo F --bar --bazF)rb   z--barz--baz)r  rj  r]   r  r{   r   r2   )r   r^   r/   extrasr	   r	   r
   test_optionals  s
    
z!TestParseKnownArgs.test_optionalsc             C   s|   t  }|jdddtd |jddd |d d	d
ddddg}||\}}| tddd	d| | d
ddg| d S )Nz-vr   rE   )r   r   r:   z--spamr   )r   r   r   rf  z--foor   r  r   T)vr   r   )r  rj  r]   r   r  r   r2   )r   r^   rj   r/   r  r	   r	   r
   
test_mixed  s    
zTestParseKnownArgs.test_mixedN)	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d Zdd Zd	S )
TestIntermixedArgsc          	   C   s  t jdd}|jddd |jdddd	}|d
 |jddtd d }||}| tdd
ddddgd| ||\}}| tdd
dg d| | dddg| d }|	|\}}| tdd
ddgd| | dddg| | 
|j | |jd d S )Nr{  )r|  z--foorb   )r   z--barr   T)r   r   cmdrestr   )r   r:   zcmd --foo x 1 --bar y 2 3r   r   rE   r   r   )r   r  rb   r  r   r   r   z!cmd --foo x 1 --error 2 --bar y 3z--error)r  rj  r]   r   r{   parse_intermixed_argsr   r2   r  parse_known_intermixed_argsr  r&  r   )r   r^   r   rj   r/   r  r	   r	   r
   
test_basic  s"    

zTestIntermixedArgs.test_basicc          	   C   sj   t dd}|d |d |jddd d }| t}|| W d Q R X | t|jd	 d S )
Nr{  )r|  z-zr   r   z...)r   z
X A B -z Zz\.\.\.)	rS   r]   r{   r|   rs   r  r  r   r  )r   r^   rj   r  r	   r	   r
   test_remainder  s    


z!TestIntermixedArgs.test_remainderc             C   s   t dd}|jdd}|jdddd |jd	d
d |jddddd |d }| tddgdd d| | t|jd  | |j	d d S )Nr{  )r|  T)r   z--foor   r  )r   r~  z--spamr  )r~  r   r   r   r  )r   r   r~  z	1 --foo 2r   r   )r   rb   r   z1 2)
rS   r  r]   r  r{   r   r2   r|   r?   r   )r   r^   rd   r/   r	   r	   r
   test_exclusive#  s    
z!TestIntermixedArgs.test_exclusivec             C   sh   t dd}|jdd}|jdddd |jd	d
d |jddddd | t|jg  | |jd d S )Nr{  )r|  T)r   z--foor   r  )r   r~  z--spamr  )r~  r   r   r   r  )r   r   r~  )rS   r  r]   r|   rs   r  r   r   )r   r^   rd   r	   r	   r
   test_exclusive_incompatible/  s    
z.TestIntermixedArgs.test_exclusive_incompatibleN)r   r   r   r  r  r  r  r	   r	   r	   r
   r    s   r  c               @   s   e Zd Zdd ZdS )!TestIntermixedMessageContentErrorc          	   C   s   t ddd}|jdtd |jdtdd | t}|g  W d Q R X t|j}| |d | |d	 | t}|	g  W d Q R X t|j}| 
|d | |d	 d S )
Nr{  r   )r|  r&  r  )r:   z-req_optT)r:   r   r  )rS   r]   r   r   r|   r?   rO   r  r  r  ZassertNotRegex)r   r^   r  ry   r	   r	   r
   r  <  s    

zGTestIntermixedMessageContentError.test_missing_argument_name_in_messageN)r   r   r   r  r	   r	   r	   r
   r  9  s   r  c               @   s  e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zd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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dDdE Z%dFdG Z&dHdI Z'dJdK Z(dLdM Z)dNdO Z*dPdQ Z+dRdS Z,dTdU Z-dVdW Z.dXdY Z/dZd[ Z0d\d] Z1d^d_ Z2d`S )aTestAddArgumentMetavarz,length of metavar tuple does not match nargsc             C   s   t  }|jd||d d S )Nz--foo)r   r  )r  rj  r]   )r   r   r  r^   r	   r	   r
   do_test_no_exceptionU  s    z+TestAddArgumentMetavar.do_test_no_exceptionc          	   C   sH   t  }| t}|jd||d W d Q R X | |jjd | j d S )Nz--foo)r   r  r   )	r  rj  r|   r  r]   r   r  r/   EXPECTED_MESSAGE)r   r   r  r^   r  r	   r	   r
   do_test_exceptionY  s    z(TestAddArgumentMetavar.do_test_exceptionc             C   s   | j d dd d S )Nr   )r   r  )r  )r   r	   r	   r
   test_nargs_None_metavar_stringa  s    z5TestAddArgumentMetavar.test_nargs_None_metavar_stringc             C   s   | j d t d d S )N)r   r  )r  tuple)r   r	   r	   r
   test_nargs_None_metavar_length0d  s    z6TestAddArgumentMetavar.test_nargs_None_metavar_length0c             C   s   | j d dd d S )N)r   )r   r  )r  )r   r	   r	   r
   test_nargs_None_metavar_length1g  s    z6TestAddArgumentMetavar.test_nargs_None_metavar_length1c             C   s   | j d dd d S )N)r   r   )r   r  )r  )r   r	   r	   r
   test_nargs_None_metavar_length2j  s    z6TestAddArgumentMetavar.test_nargs_None_metavar_length2c             C   s   | j d dd d S )N)r   r   r   )r   r  )r  )r   r	   r	   r
   test_nargs_None_metavar_length3m  s    z6TestAddArgumentMetavar.test_nargs_None_metavar_length3c             C   s   | j ddd d S )Nr   r   )r   r  )r  )r   r	   r	   r
   "test_nargs_optional_metavar_stringr  s    z9TestAddArgumentMetavar.test_nargs_optional_metavar_stringc             C   s   | j dt d d S )Nr   )r   r  )r  r  )r   r	   r	   r
   #test_nargs_optional_metavar_length0u  s    z:TestAddArgumentMetavar.test_nargs_optional_metavar_length0c             C   s   | j ddd d S )Nr   )r   )r   r  )r  )r   r	   r	   r
   #test_nargs_optional_metavar_length1x  s    z:TestAddArgumentMetavar.test_nargs_optional_metavar_length1c             C   s   | j ddd d S )Nr   )r   r   )r   r  )r  )r   r	   r	   r
   #test_nargs_optional_metavar_length2{  s    z:TestAddArgumentMetavar.test_nargs_optional_metavar_length2c             C   s   | j ddd d S )Nr   )r   r   r   )r   r  )r  )r   r	   r	   r
   #test_nargs_optional_metavar_length3~  s    z:TestAddArgumentMetavar.test_nargs_optional_metavar_length3c             C   s   | j ddd d S )Nr   r   )r   r  )r  )r   r	   r	   r
   $test_nargs_zeroormore_metavar_string  s    z;TestAddArgumentMetavar.test_nargs_zeroormore_metavar_stringc             C   s   | j dt d d S )Nr   )r   r  )r  r  )r   r	   r	   r
   %test_nargs_zeroormore_metavar_length0  s    z<TestAddArgumentMetavar.test_nargs_zeroormore_metavar_length0c             C   s   | j ddd d S )Nr   )r   )r   r  )r  )r   r	   r	   r
   %test_nargs_zeroormore_metavar_length1  s    z<TestAddArgumentMetavar.test_nargs_zeroormore_metavar_length1c             C   s   | j ddd d S )Nr   )r   r   )r   r  )r  )r   r	   r	   r
   %test_nargs_zeroormore_metavar_length2  s    z<TestAddArgumentMetavar.test_nargs_zeroormore_metavar_length2c             C   s   | j ddd d S )Nr   )r   r   r   )r   r  )r  )r   r	   r	   r
   %test_nargs_zeroormore_metavar_length3  s    z<TestAddArgumentMetavar.test_nargs_zeroormore_metavar_length3c             C   s   | j ddd d S )Nr   r   )r   r  )r  )r   r	   r	   r
   #test_nargs_oneormore_metavar_string  s    z:TestAddArgumentMetavar.test_nargs_oneormore_metavar_stringc             C   s   | j dt d d S )Nr   )r   r  )r  r  )r   r	   r	   r
   $test_nargs_oneormore_metavar_length0  s    z;TestAddArgumentMetavar.test_nargs_oneormore_metavar_length0c             C   s   | j ddd d S )Nr   )r   )r   r  )r  )r   r	   r	   r
   $test_nargs_oneormore_metavar_length1  s    z;TestAddArgumentMetavar.test_nargs_oneormore_metavar_length1c             C   s   | j ddd d S )Nr   )r   r   )r   r  )r  )r   r	   r	   r
   $test_nargs_oneormore_metavar_length2  s    z;TestAddArgumentMetavar.test_nargs_oneormore_metavar_length2c             C   s   | j ddd d S )Nr   )r   r   r   )r   r  )r  )r   r	   r	   r
   $test_nargs_oneormore_metavar_length3  s    z;TestAddArgumentMetavar.test_nargs_oneormore_metavar_length3c             C   s   | j ddd d S )Nz...r   )r   r  )r  )r   r	   r	   r
   #test_nargs_remainder_metavar_string  s    z:TestAddArgumentMetavar.test_nargs_remainder_metavar_stringc             C   s   | j dt d d S )Nz...)r   r  )r  r  )r   r	   r	   r
   $test_nargs_remainder_metavar_length0  s    z;TestAddArgumentMetavar.test_nargs_remainder_metavar_length0c             C   s   | j ddd d S )Nz...)r   )r   r  )r  )r   r	   r	   r
   $test_nargs_remainder_metavar_length1  s    z;TestAddArgumentMetavar.test_nargs_remainder_metavar_length1c             C   s   | j ddd d S )Nz...)r   r   )r   r  )r  )r   r	   r	   r
   $test_nargs_remainder_metavar_length2  s    z;TestAddArgumentMetavar.test_nargs_remainder_metavar_length2c             C   s   | j ddd d S )Nz...)r   r   r   )r   r  )r  )r   r	   r	   r
   $test_nargs_remainder_metavar_length3  s    z;TestAddArgumentMetavar.test_nargs_remainder_metavar_length3c             C   s   | j ddd d S )NzA...r   )r   r  )r  )r   r	   r	   r
    test_nargs_parser_metavar_string  s    z7TestAddArgumentMetavar.test_nargs_parser_metavar_stringc             C   s   | j dt d d S )NzA...)r   r  )r  r  )r   r	   r	   r
   !test_nargs_parser_metavar_length0  s    z8TestAddArgumentMetavar.test_nargs_parser_metavar_length0c             C   s   | j ddd d S )NzA...)r   )r   r  )r  )r   r	   r	   r
   !test_nargs_parser_metavar_length1  s    z8TestAddArgumentMetavar.test_nargs_parser_metavar_length1c             C   s   | j ddd d S )NzA...)r   r   )r   r  )r  )r   r	   r	   r
   !test_nargs_parser_metavar_length2  s    z8TestAddArgumentMetavar.test_nargs_parser_metavar_length2c             C   s   | j ddd d S )NzA...)r   r   r   )r   r  )r  )r   r	   r	   r
   !test_nargs_parser_metavar_length3  s    z8TestAddArgumentMetavar.test_nargs_parser_metavar_length3c             C   s   | j ddd d S )NrE   r   )r   r  )r  )r   r	   r	   r
   test_nargs_1_metavar_string  s    z2TestAddArgumentMetavar.test_nargs_1_metavar_stringc             C   s   | j dt d d S )NrE   )r   r  )r  r  )r   r	   r	   r
   test_nargs_1_metavar_length0  s    z3TestAddArgumentMetavar.test_nargs_1_metavar_length0c             C   s   | j ddd d S )NrE   )r   )r   r  )r  )r   r	   r	   r
   test_nargs_1_metavar_length1  s    z3TestAddArgumentMetavar.test_nargs_1_metavar_length1c             C   s   | j ddd d S )NrE   )r   r   )r   r  )r  )r   r	   r	   r
   test_nargs_1_metavar_length2  s    z3TestAddArgumentMetavar.test_nargs_1_metavar_length2c             C   s   | j ddd d S )NrE   )r   r   r   )r   r  )r  )r   r	   r	   r
   test_nargs_1_metavar_length3  s    z3TestAddArgumentMetavar.test_nargs_1_metavar_length3c             C   s   | j ddd d S )Nr   r   )r   r  )r  )r   r	   r	   r
   test_nargs_2_metavar_string  s    z2TestAddArgumentMetavar.test_nargs_2_metavar_stringc             C   s   | j dt d d S )Nr   )r   r  )r  r  )r   r	   r	   r
   test_nargs_2_metavar_length0  s    z3TestAddArgumentMetavar.test_nargs_2_metavar_length0c             C   s   | j ddd d S )Nr   )r   )r   r  )r  )r   r	   r	   r
   test_nargs_2_metavar_length1  s    z3TestAddArgumentMetavar.test_nargs_2_metavar_length1c             C   s   | j ddd d S )Nr   )r   r   )r   r  )r  )r   r	   r	   r
   test_nargs_2_metavar_length2  s    z3TestAddArgumentMetavar.test_nargs_2_metavar_length2c             C   s   | j ddd d S )Nr   )r   r   r   )r   r  )r  )r   r	   r	   r
   test_nargs_2_metavar_length3  s    z3TestAddArgumentMetavar.test_nargs_2_metavar_length3c             C   s   | j ddd d S )Nr   r   )r   r  )r  )r   r	   r	   r
   test_nargs_3_metavar_string  s    z2TestAddArgumentMetavar.test_nargs_3_metavar_stringc             C   s   | j dt d d S )Nr   )r   r  )r  r  )r   r	   r	   r
   test_nargs_3_metavar_length0  s    z3TestAddArgumentMetavar.test_nargs_3_metavar_length0c             C   s   | j ddd d S )Nr   )r   )r   r  )r  )r   r	   r	   r
   test_nargs_3_metavar_length1  s    z3TestAddArgumentMetavar.test_nargs_3_metavar_length1c             C   s   | j ddd d S )Nr   )r   r   )r   r  )r  )r   r	   r	   r
   test_nargs_3_metavar_length2  s    z3TestAddArgumentMetavar.test_nargs_3_metavar_length2c             C   s   | j ddd d S )Nr   )r   r   r   )r   r  )r  )r   r	   r	   r
   test_nargs_3_metavar_length3  s    z3TestAddArgumentMetavar.test_nargs_3_metavar_length3N)3r   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  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r	   r	   r	   r
   r  Q  s`   r  c               @   s   e Zd Zdd Zdd ZdS )TestImportStarc             C   s$   xt jD ]}| tt | qW d S )N)r  __all__r  r   )r   r%   r	   r	   r
   rl    s    zTestImportStar.testc             C   s0   dd t t D }| t|ttj d S )Nc             S   s0   g | ](\}}| d s|dkst|s|qS )rl   ngettext)
startswithinspectZismodule)r5   r%   rc  r	   r	   r
   r7     s   zJTestImportStar.test_all_exports_everything_but_modules.<locals>.<listcomp>)r<   r  r9   r   r8   r  )r   r9   r	   r	   r
   'test_all_exports_everything_but_modules  s    z6TestImportStar.test_all_exports_everything_but_modulesN)r   r   r   rl  r	  r	   r	   r	   r
   r    s   r  c               @   s   e Zd Zdd Zdd ZdS )TestWrappingMetavarc             C   s"   t d| _d}| jjd|d d S )NZ9this_is_spammy_prog_with_a_long_name_sorry_about_the_namez<http[s]://example:1234>z--proxy)r  )rS   r^   r]   )r   r  r	   r	   r
   r     s    zTestWrappingMetavar.setUpc             C   s    | j  }| |td d S )Na(              usage: this_is_spammy_prog_with_a_long_name_sorry_about_the_name
                   [-h] [--proxy <http[s]://example:1234>]

            optional arguments:
              -h, --help            show this help message and exit
              --proxy <http[s]://example:1234>
            )r^   r  r   r  r  )r   	help_textr	   r	   r
   test_help_with_metavar  s    

z*TestWrappingMetavar.test_help_with_metavarN)r   r   r   r   r  r	   r	   r	   r
   r
    s   	r
  c               C   s   t t i t_t t_d S )N)r   Zrun_unittestr   rD  rF  r  rQ  r	   r	   r	   r
   	test_main#  s    
r  __main__)codecsr  r   r!   r   rH   r  r   Zunittestr  ior   rl  r   r   r   r   r   r   r.   r2   r@   r?   rR   rj  rS   r:   rY   r   rZ   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   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  r  r  r  r  r	  r  r  r  r  r  r  r  r  r  r  r!  r#  r+  r1  rA  rL  rW  Z	eq_stderrrD  rI  rM  rO  rQ  ZskipIfr   rU  rV  rX  rY  r_  rb  re  rg  rm  rv  ry  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/  r0  r2  r4  r5  r6  r8  r<  r@  rA  rB  rC  rD  rE  rG  rH  rI  rJ  rK  rL  rM  rN  rO  rP  rQ  rR  rU  rW  rY  rZ  r[  r\  r]  r`  ru  rw  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r   r	   r	   r	   r
   <module>   s  
 q






##
C  i' 4&0#+!$-*(-	


^R$7/4(6,$&"$.10(+"~-LG%=1*? ,