3 Test script for the 'cmd' module
4 Original by Michael Schneider
11 class samplecmdclass(cmd
.Cmd
):
13 Instance the sampleclass:
14 >>> mycmd = samplecmdclass()
16 Test for the function parseline():
17 >>> mycmd.parseline("")
19 >>> mycmd.parseline("?")
21 >>> mycmd.parseline("?help")
22 ('help', 'help', 'help help')
23 >>> mycmd.parseline("!")
24 ('shell', '', 'shell ')
25 >>> mycmd.parseline("!command")
26 ('shell', 'command', 'shell command')
27 >>> mycmd.parseline("func")
29 >>> mycmd.parseline("func arg1")
30 ('func', 'arg1', 'func arg1')
33 Test for the function onecmd():
35 >>> mycmd.onecmd("add 4 5")
39 >>> mycmd.onecmd("test")
40 *** Unknown syntax: test
42 Test for the function emptyline():
44 *** Unknown syntax: test
46 Test for the function default():
47 >>> mycmd.default("default")
48 *** Unknown syntax: default
50 Test for the function completedefault():
51 >>> mycmd.completedefault()
52 This is the completedefault methode
53 >>> mycmd.completenames("a")
56 Test for the function completenames():
57 >>> mycmd.completenames("12")
59 >>> mycmd.completenames("help")
62 Test for the function complete_help():
63 >>> mycmd.complete_help("a")
65 >>> mycmd.complete_help("he")
67 >>> mycmd.complete_help("12")
70 Test for the function do_help():
71 >>> mycmd.do_help("testet")
73 >>> mycmd.do_help("add")
75 >>> mycmd.onecmd("help add")
79 Documented commands (type help <topic>):
80 ========================================
83 Undocumented commands:
84 ======================
88 Test for the function print_topics():
89 >>> mycmd.print_topics("header", ["command1", "command2"], 2 ,10)
96 Test for the function columnize():
97 >>> mycmd.columnize([str(i) for i in xrange(20)])
98 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
99 >>> mycmd.columnize([str(i) for i in xrange(20)], 10)
108 This is a interactive test, put some commands in the cmdqueue attribute
110 This test includes the preloop(), postloop(), default(), emptyline(),
111 parseline(), do_help() functions
112 >>> mycmd.use_rawinput=0
113 >>> mycmd.cmdqueue=["", "add", "add 4 5", "help", "help add","exit"]
117 *** invalid number of arguments
120 Documented commands (type help <topic>):
121 ========================================
124 Undocumented commands:
125 ======================
133 print "Hello from preloop"
136 print "Hello from postloop"
138 def completedefault(self
, *ignored
):
139 print "This is the completedefault methode"
142 def complete_command(self
):
143 print "complete command"
152 print "*** invalid number of arguments"
155 l
= [int(i
) for i
in l
]
157 print "*** arguments should be numbers"
162 print "help text for add"
165 def do_exit(self
, arg
):
168 def test_main(verbose
=None):
169 from test
import test_support
, test_cmd
170 test_support
.run_doctest(test_cmd
, verbose
)
173 def test_coverage(coverdir
):
174 tracer
=trace
.Trace(ignoredirs
=[sys
.prefix
, sys
.exec_prefix
,],
176 tracer
.run('reload(cmd);test_main()')
178 print "Writing coverage results..."
179 r
.write_results(show_missing
=True, summary
=True, coverdir
=coverdir
)
181 if __name__
== "__main__":
183 test_coverage('/tmp/cmd.cover')