Changeset 391 for python/trunk/Lib/test/test_cmd.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_cmd.py
r2 r391 8 8 import cmd 9 9 import sys 10 from test import test_support 11 import re 12 import unittest 13 import StringIO 10 14 11 15 class samplecmdclass(cmd.Cmd): … … 58 62 [] 59 63 >>> mycmd.completenames("help") 60 ['help' , 'help']64 ['help'] 61 65 62 66 Test for the function complete_help(): … … 64 68 ['add'] 65 69 >>> mycmd.complete_help("he") 66 ['help' , 'help']70 ['help'] 67 71 >>> mycmd.complete_help("12") 68 72 [] 73 >>> sorted(mycmd.complete_help("")) 74 ['add', 'exit', 'help', 'shell'] 69 75 70 76 Test for the function do_help(): … … 79 85 Documented commands (type help <topic>): 80 86 ======================================== 81 add 87 add help 82 88 <BLANKLINE> 83 89 Undocumented commands: 84 90 ====================== 85 exit helpshell91 exit shell 86 92 <BLANKLINE> 87 93 … … 120 126 Documented commands (type help <topic>): 121 127 ======================================== 122 add 128 add help 123 129 <BLANKLINE> 124 130 Undocumented commands: 125 131 ====================== 126 exit helpshell132 exit shell 127 133 <BLANKLINE> 128 134 help text for add … … 144 150 return 145 151 146 def do_shell(self ):152 def do_shell(self, s): 147 153 pass 148 154 … … 166 172 return True 167 173 174 175 class TestAlternateInput(unittest.TestCase): 176 177 class simplecmd(cmd.Cmd): 178 179 def do_print(self, args): 180 print >>self.stdout, args 181 182 def do_EOF(self, args): 183 return True 184 185 186 class simplecmd2(simplecmd): 187 188 def do_EOF(self, args): 189 print >>self.stdout, '*** Unknown syntax: EOF' 190 return True 191 192 193 def test_file_with_missing_final_nl(self): 194 input = StringIO.StringIO("print test\nprint test2") 195 output = StringIO.StringIO() 196 cmd = self.simplecmd(stdin=input, stdout=output) 197 cmd.use_rawinput = False 198 cmd.cmdloop() 199 self.assertMultiLineEqual(output.getvalue(), 200 ("(Cmd) test\n" 201 "(Cmd) test2\n" 202 "(Cmd) ")) 203 204 205 def test_input_reset_at_EOF(self): 206 input = StringIO.StringIO("print test\nprint test2") 207 output = StringIO.StringIO() 208 cmd = self.simplecmd2(stdin=input, stdout=output) 209 cmd.use_rawinput = False 210 cmd.cmdloop() 211 self.assertMultiLineEqual(output.getvalue(), 212 ("(Cmd) test\n" 213 "(Cmd) test2\n" 214 "(Cmd) *** Unknown syntax: EOF\n")) 215 input = StringIO.StringIO("print \n\n") 216 output = StringIO.StringIO() 217 cmd.stdin = input 218 cmd.stdout = output 219 cmd.cmdloop() 220 self.assertMultiLineEqual(output.getvalue(), 221 ("(Cmd) \n" 222 "(Cmd) \n" 223 "(Cmd) *** Unknown syntax: EOF\n")) 224 225 168 226 def test_main(verbose=None): 169 from test import test_ support, test_cmd227 from test import test_cmd 170 228 test_support.run_doctest(test_cmd, verbose) 171 172 import trace, sys 229 test_support.run_unittest(TestAlternateInput) 230 173 231 def test_coverage(coverdir): 232 trace = test_support.import_module('trace') 174 233 tracer=trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,], 175 234 trace=0, count=1) … … 182 241 if "-c" in sys.argv: 183 242 test_coverage('/tmp/cmd.cover') 243 elif "-i" in sys.argv: 244 samplecmdclass().cmdloop() 184 245 else: 185 246 test_main()
Note:
See TracChangeset
for help on using the changeset viewer.