+
    Bio#                        R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RI	H
t
Ht ^ RIHt  ! R R]P                  4      t ! R R]P                   4      t ! R	 R
]P                  4      t ! R R]P                   4      t]P(                  ! 4        ! R R]P                  4      4       tR t]R8X  d<   R]P0                  9   d   ]! 4       P3                  4        R# ]P4                  ! 4        R# R# )z@
Test script for the 'cmd' module
Original by Michael Schneider
N)support)ensure_lazy_importsimport_module)run_ptyc                   D   a  ] tR t^t o ]P
                  R 4       tRtV tR# )LazyImportTestc                "    \        R RR04       R# )cmdinspectstringN)r   selfs   &$/usr/lib/python3.14/test/test_cmd.pytest_lazy_importLazyImportTest.test_lazy_import   s    EIx#89     N)	__name__
__module____qualname____firstlineno__r   cpython_onlyr   __static_attributes____classdictcell____classdict__s   @r   r   r      s     : :r   r   c                   `   a  ] tR t^t o RtR tR tR tR tR t	R t
R tR	 tR
 tR tRtV tR# )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                    \        R 4       R# )zHello from preloopNprintr   s   &r   preloopsamplecmdclass.preloop   s    "#r   c                    \        R 4       R# )zHello from postloopNr   r   s   &r   postloopsamplecmdclass.postloop   s    #$r   c                    \        R 4       R# )z"This is the completedefault methodNr   )r   ignoreds   &*r   completedefaultsamplecmdclass.completedefault   s    23r   c                    \        R 4       R# )zcomplete commandNr   r   s   &r   complete_commandsamplecmdclass.complete_command   s     !r   c                    R # Nr   )r   ss   &&r   do_shellsamplecmdclass.do_shell   s    r   c                   VP                  4       p\        V4      ^8w  d   \        R4       R#  V Uu. uF  p\        V4      NK  	  pp\        T^ ,          T^,          ,           4       R# u upi   \         d    \        R4        R# i ; i)   z*** invalid number of argumentsNz*** arguments should be numbers)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"   A0 A+A0 +A0 0B
	B
c                    \        R 4       R# )zhelp text for addNr   r   s   &r   help_addsamplecmdclass.help_add   s    !"r   c                    \        R 4       R# )zTry 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.Nr   r   s   &r   help_meaningsamplecmdclass.help_meaning   s     2 	3 	r   c                    \        R 4       R# )z&Always look on the bright side of lifeNr   r   s   &r   	help_lifesamplecmdclass.help_life   s    67r   c                    R # Tr   )r   args   &&r   do_exitsamplecmdclass.do_exit   s    r   r   N)r   r   r   r   __doc__r!   r$   r(   r+   r0   r:   r=   r@   rC   rH   r   r   r   s   @r   r   r      sC     EN$%4"
 r   r   c                   l   a  ] tR t^t o  ! R R]P
                  4      t ! R R]4      tR tR t	Rt
V tR# )	TestAlternateInputc                   ,   a  ] tR t^t o R tR tRtV tR# )TestAlternateInput.simplecmdc                2    \        WP                  R 7       R# )fileNr    stdoutr   argss   &&r   do_print%TestAlternateInput.simplecmd.do_print   s    $[[)r   c                    R # rF   r   rT   s   &&r   do_EOF#TestAlternateInput.simplecmd.do_EOF   s    r   r   N)r   r   r   r   rV   rY   r   r   r   s   @r   	simplecmdrN      s     	*	 	r   r[   c                   &   a  ] tR t^t o R tRtV tR# )TestAlternateInput.simplecmd2c                4    \        R V P                  R7       R# )z*** Unknown syntax: EOFrP   TrR   rT   s   &&r   rY   $TestAlternateInput.simplecmd2.do_EOF   s    +$++>r   r   N)r   r   r   r   rY   r   r   r   s   @r   
simplecmd2r]      s     	 	r   r`   c                    \         P                  ! R 4      p\         P                  ! 4       pV P                  WR7      pRVn        VP                  ! 4        V P                  VP                  4       R4       R# )print test
print test2stdinrS   Fz(Cmd) test
(Cmd) test2
(Cmd) N)ioStringIOr[   use_rawinputcmdloopassertMultiLineEqualgetvaluer   inputoutputr	   s   &   r   test_file_with_missing_final_nl2TestAlternateInput.test_file_with_missing_final_nl   sY    56nn5n8 !!&//"3	r   c                   \         P                  ! R 4      p\         P                  ! 4       pV P                  WR7      pRVn        VP                  ! 4        V P                  VP                  4       R4       \         P                  ! R4      p\         P                  ! 4       pWn        W#n        VP                  ! 4        V P                  VP                  4       R4       R# )rb   rc   Fz5(Cmd) test
(Cmd) test2
(Cmd) *** Unknown syntax: EOF
zprint 

z,(Cmd) 
(Cmd) 
(Cmd) *** Unknown syntax: EOF
N)	re   rf   r`   rg   rh   ri   rj   rd   rS   rk   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   r	   Cmdr[   r`   rn   rq   r   r   r   s   @r   rL   rL      s0     CGG Y 	1 1r   rL   c                   *   a  ] tR tRt o RtR tRtV tR# )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                P    \        \        P                  ! 4       R ,          4       R# ):Nr3   NN)r    sysexc_info)r   lines   &&r   defaultCmdPrintExceptionClass.default  s    cllnR !r   r   N)r   r   r   r   rJ   r{   r   r   r   s   @r   ru   ru      s     	" "r   ru   c                   2   a  ] tR tRt o R tR tR tRtV tR# )CmdTestReadlinei  c                     \        R 4      p R# )readlineN)r   )r   s    r   
setUpClassCmdTestReadline.setUpClass  s     !,r   c                    \         P                  ! R 4      pRp\        W4      pV P                  RV4       V P                  RV4       R# )z
            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_test   tab completion successN)textwrapdedentr   assertInr   scriptrl   rm   s   &   r   test_basic_completion%CmdTestReadline.test_basic_completion  sD     "  '+V4/8r   c                   \         P                  ! R 4      pR FU  pV P                  VR7      ;_uu_ 4        \        W4      pV P	                  RV4       V P	                  RV4       RRR4       KW  	  R#   + '       g   i     Kl  ; i)a  
            import cmd
            class simplecmd(cmd.Cmd):
                def completedefault(self, text, line, begidx, endidx):
                    return ["hello"]

                def default(self, line):
                    if line.replace(" ", "") == "!hello":
                        print('tab completion success')
                    else:
                        print('tab completion failure')
                    return True

            simplecmd().cmdloop()
        )rl   s   hellor   N)s   ! h	
s   !h	
)r   r   subTestr   r   r   s   &   r   %test_bang_completion_without_do_shell5CmdTestReadline.test_bang_completion_without_do_shell*  sk     " " -EE** /h/7@ +* -***s   0A44Br   N)	r   r   r   r   r   r   r   r   r   r   s   @r   r~   r~     s     -
9&A Ar   r~   c                 N    VP                  \        P                  ! 4       4       V# r.   )addTestdoctestDocTestSuite)loadertestspatterns   &&&r   
load_testsr   B  s    	MM'&&()Lr   __main__z-i)rJ   r	   rx   r   unittestre   r   testr   test.support.import_helperr   r   test.support.pty_helperr   TestCaser   rs   r   rL   ru   requires_subprocessr~   r   r   argvrh   mainr   r   r   <module>r      s     
   	   I +:X&& :sSWW sl01** 01f"SWW "  	/Ah'' /A /Ab
 zsxx  "	 r   