Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_cmd.py

    r2 r391  
    88import cmd
    99import sys
     10from test import test_support
     11import re
     12import unittest
     13import StringIO
    1014
    1115class samplecmdclass(cmd.Cmd):
     
    5862    []
    5963    >>> mycmd.completenames("help")
    60     ['help', 'help']
     64    ['help']
    6165
    6266    Test for the function complete_help():
     
    6468    ['add']
    6569    >>> mycmd.complete_help("he")
    66     ['help', 'help']
     70    ['help']
    6771    >>> mycmd.complete_help("12")
    6872    []
     73    >>> sorted(mycmd.complete_help(""))
     74    ['add', 'exit', 'help', 'shell']
    6975
    7076    Test for the function do_help():
     
    7985    Documented commands (type help <topic>):
    8086    ========================================
    81     add
     87    add  help
    8288    <BLANKLINE>
    8389    Undocumented commands:
    8490    ======================
    85     exit  help  shell
     91    exit  shell
    8692    <BLANKLINE>
    8793
     
    120126    Documented commands (type help <topic>):
    121127    ========================================
    122     add
     128    add  help
    123129    <BLANKLINE>
    124130    Undocumented commands:
    125131    ======================
    126     exit  help  shell
     132    exit  shell
    127133    <BLANKLINE>
    128134    help text for add
     
    144150        return
    145151
    146     def do_shell(self):
     152    def do_shell(self, s):
    147153        pass
    148154
     
    166172        return True
    167173
     174
     175class 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
    168226def test_main(verbose=None):
    169     from test import test_support, test_cmd
     227    from test import test_cmd
    170228    test_support.run_doctest(test_cmd, verbose)
    171 
    172 import trace, sys
     229    test_support.run_unittest(TestAlternateInput)
     230
    173231def test_coverage(coverdir):
     232    trace = test_support.import_module('trace')
    174233    tracer=trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,],
    175234                        trace=0, count=1)
     
    182241    if "-c" in sys.argv:
    183242        test_coverage('/tmp/cmd.cover')
     243    elif "-i" in sys.argv:
     244        samplecmdclass().cmdloop()
    184245    else:
    185246        test_main()
Note: See TracChangeset for help on using the changeset viewer.