summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_builtin.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-02-26 16:59:55 (GMT)
committerGuido van Rossum <guido@python.org>2007-02-26 16:59:55 (GMT)
commita88a0331b7664db95858ba470a505c318d1066f9 (patch)
treec83917e821ac4616117b66cd998ba290321785a6 /Lib/test/test_builtin.py
parente8ef4e1190f7003380ddefbbc003b5693e11758a (diff)
downloadcpython-a88a0331b7664db95858ba470a505c318d1066f9.zip
cpython-a88a0331b7664db95858ba470a505c318d1066f9.tar.gz
cpython-a88a0331b7664db95858ba470a505c318d1066f9.tar.bz2
Add raw_input() back, named input(). Revive the old unittests too.
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r--Lib/test/test_builtin.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index e22e73a..d2f70ff 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -664,6 +664,8 @@ class BuiltinTest(unittest.TestCase):
id([0,1,2,3])
id({'spam': 1, 'eggs': 2, 'ham': 3})
+ # Test input() later, alphabetized as if it were raw_input
+
def test_int(self):
self.assertEqual(int(314), 314)
self.assertEqual(int(3.14), 3)
@@ -1256,6 +1258,7 @@ class BuiltinTest(unittest.TestCase):
self.assertRaises(TypeError, oct, ())
def write_testfile(self):
+ # NB the first 4 lines are also used to test input, below
fp = open(TESTFN, 'w')
try:
fp.write('1+1\n')
@@ -1417,6 +1420,43 @@ class BuiltinTest(unittest.TestCase):
self.assertRaises(OverflowError, range, -sys.maxint, sys.maxint)
self.assertRaises(OverflowError, range, 0, 2*sys.maxint)
+ def test_input(self):
+ self.write_testfile()
+ fp = open(TESTFN, 'r')
+ savestdin = sys.stdin
+ savestdout = sys.stdout # Eats the echo
+ try:
+ sys.stdin = fp
+ sys.stdout = BitBucket()
+ self.assertEqual(input(), "1+1")
+ self.assertEqual(input('testing\n'), "1+1")
+ self.assertEqual(input(), 'The quick brown fox jumps over the lazy dog.')
+ self.assertEqual(input('testing\n'), 'Dear John')
+
+ # SF 1535165: don't segfault on closed stdin
+ # sys.stdout must be a regular file for triggering
+ sys.stdout = savestdout
+ sys.stdin.close()
+ self.assertRaises(ValueError, input)
+
+ sys.stdout = BitBucket()
+ sys.stdin = cStringIO.StringIO("NULL\0")
+ self.assertRaises(TypeError, input, 42, 42)
+ sys.stdin = cStringIO.StringIO(" 'whitespace'")
+ self.assertEqual(input(), " 'whitespace'")
+ sys.stdin = cStringIO.StringIO()
+ self.assertRaises(EOFError, input)
+
+ del sys.stdout
+ self.assertRaises(RuntimeError, input, 'prompt')
+ del sys.stdin
+ self.assertRaises(RuntimeError, input, 'prompt')
+ finally:
+ sys.stdin = savestdin
+ sys.stdout = savestdout
+ fp.close()
+ unlink(TESTFN)
+
def test_reload(self):
import marshal
reload(marshal)