Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_cmd.cpython-311.opt-1.pyc
�

�Ke���>�dZddlZddlZddlZddlZddlZddlmZGd�dej��Z	Gd�dej
��Zd�Zd	�Z
ed
krNdejvr
e
d��dSd
ejvre	�����dSej��dSdS)z@
Test script for the 'cmd' module
Original by Michael Schneider
�N)�supportc�N�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
dS)
�samplecmdclassa
    Instance the sampleclass:
    >>> mycmd = samplecmdclass()

    Test for the function parseline():
    >>> mycmd.parseline("")
    (None, None, '')
    >>> mycmd.parseline("?")
    ('help', '', 'help ')
    >>> mycmd.parseline("?help")
    ('help', 'help', 'help help')
    >>> mycmd.parseline("!")
    ('shell', '', 'shell ')
    >>> mycmd.parseline("!command")
    ('shell', 'command', 'shell command')
    >>> mycmd.parseline("func")
    ('func', '', 'func')
    >>> mycmd.parseline("func arg1")
    ('func', 'arg1', 'func arg1')


    Test for the function onecmd():
    >>> mycmd.onecmd("")
    >>> mycmd.onecmd("add 4 5")
    9
    >>> mycmd.onecmd("")
    9
    >>> mycmd.onecmd("test")
    *** Unknown syntax: test

    Test for the function emptyline():
    >>> mycmd.emptyline()
    *** Unknown syntax: test

    Test for the function default():
    >>> mycmd.default("default")
    *** Unknown syntax: default

    Test for the function completedefault():
    >>> mycmd.completedefault()
    This is the completedefault method
    >>> mycmd.completenames("a")
    ['add']

    Test for the function completenames():
    >>> mycmd.completenames("12")
    []
    >>> mycmd.completenames("help")
    ['help']

    Test for the function complete_help():
    >>> mycmd.complete_help("a")
    ['add']
    >>> mycmd.complete_help("he")
    ['help']
    >>> mycmd.complete_help("12")
    []
    >>> sorted(mycmd.complete_help(""))
    ['add', 'exit', 'help', 'life', 'meaning', 'shell']

    Test for the function do_help():
    >>> mycmd.do_help("testet")
    *** No help on testet
    >>> mycmd.do_help("add")
    help text for add
    >>> mycmd.onecmd("help add")
    help text for add
    >>> mycmd.onecmd("help meaning")  # doctest: +NORMALIZE_WHITESPACE
    Try and be nice to people, avoid eating fat, read a good book every
    now and then, get some walking in, and try to live together in peace
    and harmony with people of all creeds and nations.
    >>> mycmd.do_help("")
    <BLANKLINE>
    Documented commands (type help <topic>):
    ========================================
    add  help
    <BLANKLINE>
    Miscellaneous help topics:
    ==========================
    life  meaning
    <BLANKLINE>
    Undocumented commands:
    ======================
    exit  shell
    <BLANKLINE>

    Test for the function print_topics():
    >>> mycmd.print_topics("header", ["command1", "command2"], 2 ,10)
    header
    ======
    command1
    command2
    <BLANKLINE>

    Test for the function columnize():
    >>> mycmd.columnize([str(i) for i in range(20)])
    0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19
    >>> mycmd.columnize([str(i) for i in range(20)], 10)
    0  7   14
    1  8   15
    2  9   16
    3  10  17
    4  11  18
    5  12  19
    6  13

    This is an interactive test, put some commands in the cmdqueue attribute
    and let it execute
    This test includes the preloop(), postloop(), default(), emptyline(),
    parseline(), do_help() functions
    >>> mycmd.use_rawinput=0

    >>> mycmd.cmdqueue=["add", "add 4 5", "", "help", "help add", "exit"]
    >>> mycmd.cmdloop()  # doctest: +REPORT_NDIFF
    Hello from preloop
    *** invalid number of arguments
    9
    9
    <BLANKLINE>
    Documented commands (type help <topic>):
    ========================================
    add  help
    <BLANKLINE>
    Miscellaneous help topics:
    ==========================
    life  meaning
    <BLANKLINE>
    Undocumented commands:
    ======================
    exit  shell
    <BLANKLINE>
    help text for add
    Hello from postloop
    c�$�td��dS)NzHello from preloop��print��selfs �7/usr/local/apps/python3/lib/python3.11/test/test_cmd.py�preloopzsamplecmdclass.preloop�s��
�"�#�#�#�#�#�c�$�td��dS)NzHello from postlooprr	s r�postloopzsamplecmdclass.postloop�s��
�#�$�$�$�$�$r
c�$�td��dS)Nz"This is the completedefault methodr)r
�ignoreds  r�completedefaultzsamplecmdclass.completedefault�s��
�2�3�3�3�3�3r
c�$�td��dS)Nzcomplete commandrr	s r�complete_commandzsamplecmdclass.complete_command�s��
� �!�!�!�!�!r
c��dS�N�)r
�ss  r�do_shellzsamplecmdclass.do_shell�s���r
c��|���}t|��dkrtd��dS	d�|D��}n #t$rtd��YdSwxYwt|d|dz��dS)N�z*** invalid number of argumentsc�,�g|]}t|����Sr)�int)�.0�is  r�
<listcomp>z)samplecmdclass.do_add.<locals>.<listcomp>�s��#�#�#�A��Q���#�#�#r
z*** arguments should be numbersr�)�split�lenr�
ValueError)r
r�ls   r�do_addzsamplecmdclass.do_add�s���
�G�G�I�I���q�6�6�Q�;�;��3�4�4�4��F�	�#�#��#�#�#�A�A���	�	�	��3�4�4�4��F�F�	����	�a��d�1�Q�4�i�����s�A�A$�#A$c�$�td��dS)Nzhelp text for addrr	s r�help_addzsamplecmdclass.help_add�s��
�!�"�"�"��r
c�$�td��dS)Nz�Try and be nice to people, avoid eating fat, read a good book every now and then, get some walking in, and try to live together in peace and harmony with people of all creeds and nations.rr	s r�help_meaningzsamplecmdclass.help_meaning�s ��
�2�	3�	3�	3�	�r
c�$�td��dS)Nz&Always look on the bright side of liferr	s r�	help_lifezsamplecmdclass.help_life�s��
�6�7�7�7��r
c��dS�NTr)r
�args  r�do_exitzsamplecmdclass.do_exit�s���tr
N)�__name__�
__module__�__qualname__�__doc__rrrrrr&r(r*r,r0rr
rrrs�������E�E�N$�$�$�%�%�%�4�4�4�"�"�"�
�
�
�
�
�
��������������r
rc�\�eZdZGd�dej��ZGd�de��Zd�Zd�ZdS)�TestAlternateInputc��eZdZd�Zd�ZdS)�TestAlternateInput.simplecmdc�2�t||j���dS)N��file�r�stdout�r
�argss  r�do_printz%TestAlternateInput.simplecmd.do_print�s���$�T�[�)�)�)�)�)�)r
c��dSr.rr>s  r�do_EOFz#TestAlternateInput.simplecmd.do_EOF�s���4r
N)r1r2r3r@rBrr
r�	simplecmdr8�s2������	*�	*�	*�	�	�	�	�	r
rCc��eZdZd�ZdS)�TestAlternateInput.simplecmd2c�2�td|j���dS)Nz*** Unknown syntax: EOFr:Tr<r>s  rrBz$TestAlternateInput.simplecmd2.do_EOF�s���+�$�+�>�>�>�>��4r
N)r1r2r3rBrr
r�
simplecmd2rE�s#������	�	�	�	�	r
rGc��tjd��}tj��}|�||���}d|_|j��|�|���d��dS)N�print test
print test2��stdinr=Fz(Cmd) test
(Cmd) test2
(Cmd) )�io�StringIOrC�use_rawinput�cmdloop�assertMultiLineEqual�getvalue�r
�input�output�cmds    r�test_file_with_missing_final_nlz2TestAlternateInput.test_file_with_missing_final_nl�sz����5�6�6��������n�n�5��n�8�8�� ������
�
�
��!�!�&�/�/�"3�"3��	�	�	�	�	r
c���tjd��}tj��}|�||���}d|_|j��|�|���d��tjd��}tj��}||_||_|j��|�|���d��dS)NrIrJFz5(Cmd) test
(Cmd) test2
(Cmd) *** Unknown syntax: EOF
zprint 

z,(Cmd) 
(Cmd) 
(Cmd) *** Unknown syntax: EOF
)	rLrMrGrNrOrPrQrKr=rRs    r�test_input_reset_at_EOFz*TestAlternateInput.test_input_reset_at_EOF�s�����5�6�6��������o�o�E�&�o�9�9�� ������
�
�
��!�!�&�/�/�"3�"3�/�	1�	1�	1���L�)�)���������	���
����
�
�
��!�!�&�/�/�"3�"3�/�	1�	1�	1�	1�	1r
N)	r1r2r3rU�CmdrCrGrVrXrr
rr6r6�s������������C�G���������Y����	�	�	�1�1�1�1�1r
r6c�R�|�tj����|Sr)�addTest�doctest�DocTestSuite)�loader�tests�patterns   r�
load_testsra�s"��	�M�M�'�&�(�(�)�)�)��Lr
c�*�tjd��}|�tjtjgdd���}|�d��|���}td��|�	dd|���dS)	N�tracerr!)�
ignoredirsrc�countz4import importlib; importlib.reload(cmd); test_main()zWriting coverage results...T)�show_missing�summary�coverdir)
r�
import_module�Trace�sys�base_prefix�base_exec_prefix�run�resultsr�
write_results)rhrc�tracer�rs    r�
test_coveragers�s����!�'�*�*�E��;�;�3�?�C�4H�"J��q��*�*�F�
�J�J�E�F�F�F��n�n���A�	�
'�(�(�(��O�O��t�h�O�G�G�G�G�Gr
�__main__z-cz/tmp/cmd.coverz-i)r4rUrkr\�unittestrL�testrrYr�TestCaser6rarsr1�argvrO�mainrr
r�<module>rzsK�����
�
�
�
�
�
�
���������	�	�	�	�������s�s�s�s�s�S�W�s�s�s�l01�01�01�01�01��*�01�01�01�f���H�H�H��z����s�x����
�&�'�'�'�'�'�	
���	�	����� � �"�"�"�"�"���
������
�r