B
    u9ai                 @   s   d dl Z d dlZd dlZd dlZd dlmZ G dd de jZG dd dejZ	dddZ
d	d
 Zedkrdejkr~ed ndejkre   ne
  dS )    N)supportc               @   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 )samplecmdclassc             C   s   t d d S )NzHello from preloop)print)self r   /usr/lib/python3.7/test_cmd.pypreloop   s    zsamplecmdclass.preloopc             C   s   t d d S )NzHello from postloop)r   )r   r   r   r   postloop   s    zsamplecmdclass.postloopc             G   s   t d d S )Nz"This is the completedefault method)r   )r   Zignoredr   r   r   completedefault   s    zsamplecmdclass.completedefaultc             C   s   t d d S )Nzcomplete command)r   )r   r   r   r   complete_command   s    zsamplecmdclass.complete_commandc             C   s   d S )Nr   )r   sr   r   r   do_shell   s    zsamplecmdclass.do_shellc             C   sh   |  }t|dkr td d S ydd |D }W n tk
rN   td d S X t|d |d   d S )N   z*** invalid number of argumentsc             S   s   g | ]}t |qS r   )int).0ir   r   r   
<listcomp>   s    z)samplecmdclass.do_add.<locals>.<listcomp>z*** arguments should be numbersr      )splitlenr   
ValueError)r   r   lr   r   r   do_add   s    zsamplecmdclass.do_addc             C   s   t d d S )Nzhelp text for add)r   )r   r   r   r   help_add   s    zsamplecmdclass.help_addc             C   s   dS )NTr   )r   argr   r   r   do_exit   s    zsamplecmdclass.do_exitN)__name__
__module____qualname__r   r	   r
   r   r   r   r   r   r   r   r   r   r      s   {r   c               @   s>   e Zd ZG dd dejZG dd deZdd Zdd Zd	S )
TestAlternateInputc               @   s   e Zd Zdd Zdd ZdS )zTestAlternateInput.simplecmdc             C   s   t || jd d S )N)file)r   stdout)r   argsr   r   r   do_print   s    z%TestAlternateInput.simplecmd.do_printc             C   s   dS )NTr   )r   r"   r   r   r   do_EOF   s    z#TestAlternateInput.simplecmd.do_EOFN)r   r   r   r#   r$   r   r   r   r   	simplecmd   s   r%   c               @   s   e Zd Zdd ZdS )zTestAlternateInput.simplecmd2c             C   s   t d| jd dS )Nz*** Unknown syntax: EOF)r    T)r   r!   )r   r"   r   r   r   r$      s    z$TestAlternateInput.simplecmd2.do_EOFN)r   r   r   r$   r   r   r   r   
simplecmd2   s   r&   c             C   sB   t d}t  }| j||d}d|_|  | | d d S )Nzprint test
print test2)stdinr!   Fz(Cmd) test
(Cmd) test2
(Cmd) )ioStringIOr%   use_rawinputcmdloopassertMultiLineEqualgetvalue)r   inputoutputcmdr   r   r   test_file_with_missing_final_nl   s    

z2TestAlternateInput.test_file_with_missing_final_nlc             C   sx   t d}t  }| j||d}d|_|  | | d t d}t  }||_||_|  | | d d S )Nzprint test
print test2)r'   r!   Fz5(Cmd) test
(Cmd) test2
(Cmd) *** Unknown syntax: EOF
zprint 

z,(Cmd) 
(Cmd) 
(Cmd) *** Unknown syntax: EOF
)	r(   r)   r&   r*   r+   r,   r-   r'   r!   )r   r.   r/   r0   r   r   r   test_input_reset_at_EOF   s    



z*TestAlternateInput.test_input_reset_at_EOFN)	r   r   r   r0   Cmdr%   r&   r1   r2   r   r   r   r   r      s   	r   c             C   s&   ddl m} t||  tt d S )Nr   )test_cmd)testr4   r   Zrun_doctestZrun_unittestr   )verboser4   r   r   r   	test_main   s    r7   c             C   sP   t d}|jtjtjgddd}|d | }td |j	dd| d d S )	Ntracer   r   )Z
ignoredirsr8   countz4import importlib; importlib.reload(cmd); test_main()zWriting coverage results...T)Zshow_missingZsummarycoverdir)
r   import_moduleZTracesysbase_prefixbase_exec_prefixrunresultsr   Zwrite_results)r:   r8   Ztracerrr   r   r   test_coverage   s    


rB   __main__z-cz/tmp/cmd.coverz-i)N)r0   r<   Zunittestr(   r5   r   r3   r   ZTestCaser   r7   rB   r   argvr+   r   r   r   r   <module>   s    3
	


