]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.2/Lib/test/test_cmd.py
3 Test script for the 'cmd' module
4 Original by Michael Schneider
10 from test
import test_support
15 class samplecmdclass(cmd
.Cmd
):
17 Instance the sampleclass:
18 >>> mycmd = samplecmdclass()
20 Test for the function parseline():
21 >>> mycmd.parseline("")
23 >>> mycmd.parseline("?")
25 >>> mycmd.parseline("?help")
26 ('help', 'help', 'help help')
27 >>> mycmd.parseline("!")
28 ('shell', '', 'shell ')
29 >>> mycmd.parseline("!command")
30 ('shell', 'command', 'shell command')
31 >>> mycmd.parseline("func")
33 >>> mycmd.parseline("func arg1")
34 ('func', 'arg1', 'func arg1')
37 Test for the function onecmd():
39 >>> mycmd.onecmd("add 4 5")
43 >>> mycmd.onecmd("test")
44 *** Unknown syntax: test
46 Test for the function emptyline():
48 *** Unknown syntax: test
50 Test for the function default():
51 >>> mycmd.default("default")
52 *** Unknown syntax: default
54 Test for the function completedefault():
55 >>> mycmd.completedefault()
56 This is the completedefault methode
57 >>> mycmd.completenames("a")
60 Test for the function completenames():
61 >>> mycmd.completenames("12")
63 >>> mycmd.completenames("help")
66 Test for the function complete_help():
67 >>> mycmd.complete_help("a")
69 >>> mycmd.complete_help("he")
71 >>> mycmd.complete_help("12")
73 >>> sorted(mycmd.complete_help(""))
74 ['add', 'exit', 'help', 'shell']
76 Test for the function do_help():
77 >>> mycmd.do_help("testet")
79 >>> mycmd.do_help("add")
81 >>> mycmd.onecmd("help add")
85 Documented commands (type help <topic>):
86 ========================================
89 Undocumented commands:
90 ======================
94 Test for the function print_topics():
95 >>> mycmd.print_topics("header", ["command1", "command2"], 2 ,10)
102 Test for the function columnize():
103 >>> mycmd.columnize([str(i) for i in xrange(20)])
104 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
105 >>> mycmd.columnize([str(i) for i in xrange(20)], 10)
114 This is a interactive test, put some commands in the cmdqueue attribute
116 This test includes the preloop(), postloop(), default(), emptyline(),
117 parseline(), do_help() functions
118 >>> mycmd.use_rawinput=0
119 >>> mycmd.cmdqueue=["", "add", "add 4 5", "help", "help add","exit"]
123 *** invalid number of arguments
126 Documented commands (type help <topic>):
127 ========================================
130 Undocumented commands:
131 ======================
139 print "Hello from preloop"
142 print "Hello from postloop"
144 def completedefault(self
, *ignored
):
145 print "This is the completedefault methode"
148 def complete_command(self
):
149 print "complete command"
152 def do_shell(self
, s
):
158 print "*** invalid number of arguments"
161 l
= [int(i
) for i
in l
]
163 print "*** arguments should be numbers"
168 print "help text for add"
171 def do_exit(self
, arg
):
175 class TestAlternateInput(unittest
.TestCase
):
177 class simplecmd(cmd
.Cmd
):
179 def do_print(self
, args
):
180 print >>self
.stdout
, args
182 def do_EOF(self
, args
):
185 def test_file_with_missing_final_nl(self
):
186 input = StringIO
.StringIO("print test\nprint test2")
187 output
= StringIO
.StringIO()
188 cmd
= self
.simplecmd(stdin
=input, stdout
=output
)
189 cmd
.use_rawinput
= False
191 self
.assertMultiLineEqual(output
.getvalue(),
197 def test_main(verbose
=None):
198 from test
import test_cmd
199 test_support
.run_doctest(test_cmd
, verbose
)
200 test_support
.run_unittest(TestAlternateInput
)
202 def test_coverage(coverdir
):
203 trace
= test_support
.import_module('trace')
204 tracer
=trace
.Trace(ignoredirs
=[sys
.prefix
, sys
.exec_prefix
,],
206 tracer
.run('reload(cmd);test_main()')
208 print "Writing coverage results..."
209 r
.write_results(show_missing
=True, summary
=True, coverdir
=coverdir
)
211 if __name__
== "__main__":
213 test_coverage('/tmp/cmd.cover')
214 elif "-i" in sys
.argv
:
215 samplecmdclass().cmdloop()