summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cmd.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-08-01 04:04:03 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2010-08-01 04:04:03 (GMT)
commit58f15b66ffb03bfe2c9fbc111e1cc28f4cd3ddd4 (patch)
treea07c23457737d73c7a195df8871bb83c42377a50 /Lib/test/test_cmd.py
parenta491727ded210994812ae1191253c0305dfc6885 (diff)
downloadcpython-58f15b66ffb03bfe2c9fbc111e1cc28f4cd3ddd4.zip
cpython-58f15b66ffb03bfe2c9fbc111e1cc28f4cd3ddd4.tar.gz
cpython-58f15b66ffb03bfe2c9fbc111e1cc28f4cd3ddd4.tar.bz2
Merged revisions 83380 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83380 | r.david.murray | 2010-07-31 23:31:09 -0400 (Sat, 31 Jul 2010) | 17 lines #8620: Cmd no longer truncates last character if stdin ends without newline Cmd used to blindly chop off the last character of every input line. If the input reached EOF and there was no final new line, it would truncate the last character of the last command. This fix instead strips trailing \r\n from the input lines. While this is a small behavior change, it should not break any working code, since feeding a '\r\n' terminated file to Cmd would previously leave the \r's on the lines, resulting in failed command execution. I wrote the unit test in preparation for a PyOhio TeachMe session run by Catherine Devlin, and we can thank Catherine and the PyOhio session attendees for the fix. I've added Catherine to the Acks file for organizing and leading the TeachMe session, out of which we will hopefully get some new contributors. ........
Diffstat (limited to 'Lib/test/test_cmd.py')
-rw-r--r--Lib/test/test_cmd.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_cmd.py b/Lib/test/test_cmd.py
index 19ee52e..c46fec8 100644
--- a/Lib/test/test_cmd.py
+++ b/Lib/test/test_cmd.py
@@ -8,6 +8,9 @@ Original by Michael Schneider
import cmd
import sys
from test import test_support
+import re
+import unittest
+import StringIO
class samplecmdclass(cmd.Cmd):
"""
@@ -168,9 +171,33 @@ class samplecmdclass(cmd.Cmd):
def do_exit(self, arg):
return True
+
+class TestAlternateInput(unittest.TestCase):
+
+ class simplecmd(cmd.Cmd):
+
+ def do_print(self, args):
+ print >>self.stdout, args
+
+ def do_EOF(self, args):
+ return True
+
+ def test_file_with_missing_final_nl(self):
+ input = StringIO.StringIO("print test\nprint test2")
+ output = StringIO.StringIO()
+ cmd = self.simplecmd(stdin=input, stdout=output)
+ cmd.use_rawinput = False
+ cmd.cmdloop()
+ self.assertMultiLineEqual(output.getvalue(),
+ ("(Cmd) test\n"
+ "(Cmd) test2\n"
+ "(Cmd) "))
+
+
def test_main(verbose=None):
from test import test_cmd
test_support.run_doctest(test_cmd, verbose)
+ test_support.run_unittest(TestAlternateInput)
def test_coverage(coverdir):
trace = test_support.import_module('trace')