" XZISrSSKrSSKrSSKrSSKrSSKrSSKrSSKJr SSK J r SSK J r "SS\R5r"SS \R5r"S S \R5r\R$"5"S S \R55rSr\S:Xa8S\R,;a\"5R/5 g\R0"5 gg)z@ Test script for the 'cmd' module Original by Michael Schneider N)support import_module)run_ptycT\rSrSrSrSrSrSrSrSr Sr S r S r S r S rS rg)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("") Documented commands (type help ): ======================================== add help Miscellaneous help topics: ========================== life meaning Undocumented commands: ====================== exit shell Test for the function print_topics(): >>> mycmd.print_topics("header", ["command1", "command2"], 2 ,10) header ====== command1 command2 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 Documented commands (type help ): ======================================== add help Miscellaneous help topics: ========================== life meaning Undocumented commands: ====================== exit shell help text for add Hello from postloop c[S5 g)NzHello from preloopprintselfs 4/opt/alt/python313/lib64/python3.13/test/test_cmd.pypreloopsamplecmdclass.preloops  "#c[S5 g)NzHello from postloopr r s rpostloopsamplecmdclass.postloops  #$rc[S5 g)Nz"This is the completedefault methodr )rignoreds rcompletedefaultsamplecmdclass.completedefaults  23rc[S5 g)Nzcomplete commandr r s rcomplete_commandsamplecmdclass.complete_commands   !rcgN)rss rdo_shellsamplecmdclass.do_shells rcUR5n[U5S:wa [S5 gUVs/sHn[U5PM nn[USUS-5 gs snf![a [S5 gf=f)Nz*** invalid number of argumentsz*** arguments should be numbersr)splitlenr int ValueError)rr lis rdo_addsamplecmdclass.do_addsw GGI q6Q; 3 4  !"#AQA# ad1Q4i $  3 4  s"A"AA"A""A:9A:c[S5 g)Nzhelp text for addr r s rhelp_addsamplecmdclass.help_adds !"rc[S5 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_meaningsamplecmdclass.help_meanings 2 3 rc[S5 g)Nz&Always look on the bright side of lifer r s r help_lifesamplecmdclass.help_lifes 67rcgNTr)rargs rdo_exitsamplecmdclass.do_exitsrrN)__name__ __module__ __qualname____firstlineno____doc__rrrrr!r,r/r2r5r:__static_attributes__rrrrrs;EN$%4"  rrc`\rSrSr"SS\R 5r"SS\5rSrSr Sr g ) TestAlternateInputc \rSrSrSrSrSrg)TestAlternateInput.simplecmdc*[XRS9 g)Nfiler stdoutrargss rdo_print%TestAlternateInput.simplecmd.do_prints $[[ )rcgr8rrMs rdo_EOF#TestAlternateInput.simplecmd.do_EOFsrrN)r<r=r>r?rOrRrArrr simplecmdrFs  * rrTc\rSrSrSrSrg)TestAlternateInput.simplecmd2c,[SURS9 g)Nz*** Unknown syntax: EOFrITrKrMs rrR$TestAlternateInput.simplecmd2.do_EOFs +$++ >rrN)r<r=r>r?rRrArrr simplecmd2rVs rrZc[R"S5n[R"5nURXS9nSUlUR"5 UR UR 5S5 g)Nprint test print test2stdinrLFz(Cmd) test (Cmd) test2 (Cmd) )ioStringIOrT use_rawinputcmdloopassertMultiLineEqualgetvaluerinputoutputcmds rtest_file_with_missing_final_nl2TestAlternateInput.test_file_with_missing_final_nlsY 56nn5n8   !!&//"3 rc[R"S5n[R"5nURXS9nSUlUR"5 UR UR 5S5 [R"S5n[R"5nXlX#lUR"5 UR UR 5S5 g)Nr\r]Fz5(Cmd) test (Cmd) test2 (Cmd) *** Unknown syntax: EOF zprint z,(Cmd) (Cmd) (Cmd) *** Unknown syntax: EOF ) r_r`rZrarbrcrdr^rLres rtest_input_reset_at_EOF*TestAlternateInput.test_input_reset_at_EOFs 56ooEo9   !!&//"3/ 1 L)    !!&//"3/ 1rrN) r<r=r>r?rhCmdrTrZrirlrArrrrCrCs(CGGY 1rrCc\rSrSrSrSrSrg)CmdPrintExceptionClassz GH-80731 cmd.Cmd should print the correct exception in default() >>> mycmd = CmdPrintExceptionClass() >>> try: ... raise ValueError("test") ... except ValueError: ... mycmd.onecmd("not important") (, ValueError('test')) cF[[R"5SS5 g)Nr$)r sysexc_info)rlines rdefaultCmdPrintExceptionClass.defaults cllnRa !rrN)r<r=r>r?r@rvrArrrrprps  "rrpc \rSrSrSrSrSrg)CmdTestReadlinei c[S5ng)Nreadliner)r{s r setUpClassCmdTestReadline.setUpClass s!,rc[R"S5nSn[X5nURSU5 URSU5 g)Nz import cmd class simplecmd(cmd.Cmd): def do_tab_completion_test(self, args): print('tab completion success') return True simplecmd().cmdloop() st sab_completion_teststab completion success)textwrapdedentrassertIn)rscriptrfrgs rtest_basic_completion%CmdTestReadline.test_basic_completionsD"  ' +V4 /8rrN)r<r=r>r?r|rrArrrryry s - 9rrycNUR[R"55 U$r)addTestdoctest DocTestSuite)loadertestspatterns r load_testsr$s MM'&&() Lr__main__z-i)r@rhrsrunittestr_rtestrtest.support.import_helperrtest.support.pty_helperrrnrTestCaserCrprequires_subprocessryrr<argvrbmainrrrrs   4+sSWWsl01**01f "SWW "  9h''992  z sxx  "  r