
    /hhF                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJr   " S S\R                  5      r " S S	\R                  5      r " S
 S\R                  5      r\R$                  " 5        " S S\R                  5      5       rS r\S:X  a8  S\R,                  ;   a  \" 5       R/                  5         g\R0                  " 5         gg)z@
Test script for the 'cmd' module
Original by Michael Schneider
    N)supportimport_module)run_ptyc                   T    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rSrg)samplecmdclass   a;  
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                     [        S5        g )NzHello from preloopprintselfs    6/opt/python-3.13.8/usr/lib/python3.13/test/test_cmd.pypreloopsamplecmdclass.preloop   s    "#    c                     [        S5        g )NzHello from postloopr   r   s    r   postloopsamplecmdclass.postloop   s    #$r   c                     [        S5        g )Nz"This is the completedefault methodr   )r   ignoreds     r   completedefaultsamplecmdclass.completedefault   s    23r   c                     [        S5        g )Nzcomplete commandr   r   s    r   complete_commandsamplecmdclass.complete_command   s     !r   c                     g N )r   ss     r   do_shellsamplecmdclass.do_shell   s    r   c                     UR                  5       n[        U5      S:w  a  [        S5        g  U Vs/ s H  n[        U5      PM     nn[        US   US   -   5        g s  snf ! [         a    [        S5         g f = f)N   z*** invalid number of argumentsz*** arguments should be numbersr      )splitlenr   int
ValueError)r   r    lis       r   do_addsamplecmdclass.do_add   sw    GGIq6Q;34	!"#AQA# 	ad1Q4i	 $ 	34	s"   A" AA" A" "A:9A:c                     [        S5        g )Nzhelp text for addr   r   s    r   help_addsamplecmdclass.help_add   s    !"r   c                     [        S5        g )NzTry 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.r   r   s    r   help_meaningsamplecmdclass.help_meaning   s     2 	3 	r   c                     [        S5        g )Nz&Always look on the bright side of lifer   r   s    r   	help_lifesamplecmdclass.help_life   s    67r   c                     gNTr   )r   args     r   do_exitsamplecmdclass.do_exit   s    r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r   r!   r,   r/   r2   r5   r:   __static_attributes__r   r   r   r   r      s;    EN$%4"
r   r   c                   `    \ rS rSr " S S\R
                  5      r " S S\5      rS rS r	Sr
g	)
TestAlternateInput   c                        \ rS rSrS rS rSrg)TestAlternateInput.simplecmd   c                 *    [        XR                  S9  g )Nfiler   stdoutr   argss     r   do_print%TestAlternateInput.simplecmd.do_print   s    $[[)r   c                     gr8   r   rM   s     r   do_EOF#TestAlternateInput.simplecmd.do_EOF   s    r   r   N)r<   r=   r>   r?   rO   rR   rA   r   r   r   	simplecmdrF      s    	*	r   rT   c                       \ rS rSrS rSrg)TestAlternateInput.simplecmd2   c                 ,    [        SU R                  S9  g)Nz*** Unknown syntax: EOFrI   TrK   rM   s     r   rR   $TestAlternateInput.simplecmd2.do_EOF   s    +$++>r   r   N)r<   r=   r>   r?   rR   rA   r   r   r   
simplecmd2rV      s    	r   rZ   c                     [         R                  " S5      n[         R                  " 5       nU R                  XS9nSUl        UR                  " 5         U R                  UR                  5       S5        g )Nprint test
print test2stdinrL   Fz(Cmd) test
(Cmd) test2
(Cmd) )ioStringIOrT   use_rawinputcmdloopassertMultiLineEqualgetvaluer   inputoutputcmds       r   test_file_with_missing_final_nl2TestAlternateInput.test_file_with_missing_final_nl   sY    56nn5n8 !!&//"3	r   c                    [         R                  " S5      n[         R                  " 5       nU R                  XS9nSUl        UR                  " 5         U R                  UR                  5       S5        [         R                  " S5      n[         R                  " 5       nXl        X#l        UR                  " 5         U R                  UR                  5       S5        g )Nr\   r]   Fz5(Cmd) test
(Cmd) test2
(Cmd) *** Unknown syntax: EOF
zprint 

z,(Cmd) 
(Cmd) 
(Cmd) *** Unknown syntax: EOF
)	r_   r`   rZ   ra   rb   rc   rd   r^   rL   re   s       r   test_input_reset_at_EOF*TestAlternateInput.test_input_reset_at_EOF   s    56ooEo9 !!&//"3/	1 L)	
!!&//"3/	1r   r   N)r<   r=   r>   r?   rh   CmdrT   rZ   ri   rl   rA   r   r   r   rC   rC      s(    CGG Y 	1r   rC   c                       \ rS rSrSrS rSrg)CmdPrintExceptionClass   z
GH-80731
cmd.Cmd should print the correct exception in default()
>>> mycmd = CmdPrintExceptionClass()
>>> try:
...     raise ValueError("test")
... except ValueError:
...     mycmd.onecmd("not important")
(<class 'ValueError'>, ValueError('test'))
c                 F    [        [        R                  " 5       S S 5        g )Nr$   )r   sysexc_info)r   lines     r   defaultCmdPrintExceptionClass.default  s    cllnRa !r   r   N)r<   r=   r>   r?   r@   rv   rA   r   r   r   rp   rp      s    	"r   rp   c                        \ rS rSrS rS rSrg)CmdTestReadlinei
  c                      [        S5      n g )Nreadliner   )r{   s    r   
setUpClassCmdTestReadline.setUpClass  s     !,r   c                     [         R                  " S5      nSn[        X5      nU R                  SU5        U R                  SU5        g )Nz
            import cmd
            class simplecmd(cmd.Cmd):
                def do_tab_completion_test(self, args):
                    print('tab completion success')
                    return True

            simplecmd().cmdloop()
        s   t	
s   ab_completion_tests   tab completion success)textwrapdedentr   assertIn)r   scriptrf   rg   s       r   test_basic_completion%CmdTestReadline.test_basic_completion  sD     "  '+V4/8r   r   N)r<   r=   r>   r?   r|   r   rA   r   r   r   ry   ry   
  s    -
9r   ry   c                 N    UR                  [        R                  " 5       5        U$ r   )addTestdoctestDocTestSuite)loadertestspatterns      r   
load_testsr   $  s    	MM'&&()Lr   __main__z-i)r@   rh   rs   r   unittestr_   r   testr   test.support.import_helperr   test.support.pty_helperr   rn   r   TestCaserC   rp   requires_subprocessry   r   r<   argvrb   mainr   r   r   <module>r      s     
   	   4 +sSWW sl01** 01f"SWW "  	9h'' 9 92
 zsxx  "	 r   