mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
raw_input() -> input(). old input behavior is history (and test_builtin passes again). It was failing due to future division.
This commit is contained in:
parent
ac3625fcb9
commit
cd65e3fc7d
2 changed files with 81 additions and 132 deletions
|
|
@ -658,8 +658,6 @@ class BuiltinTest(unittest.TestCase):
|
|||
id([0,1,2,3])
|
||||
id({'spam': 1, 'eggs': 2, 'ham': 3})
|
||||
|
||||
# Test input() later, together with raw_input
|
||||
|
||||
def test_int(self):
|
||||
self.assertEqual(int(314), 314)
|
||||
self.assertEqual(int(3.14), 3)
|
||||
|
|
@ -1108,7 +1106,7 @@ class BuiltinTest(unittest.TestCase):
|
|||
self.assertRaises(TypeError, oct, ())
|
||||
|
||||
def write_testfile(self):
|
||||
# NB the first 4 lines are also used to test input and raw_input, below
|
||||
# NB the first 4 lines are also used to test input, below
|
||||
fp = open(TESTFN, 'w')
|
||||
try:
|
||||
fp.write('1+1\n')
|
||||
|
|
@ -1267,7 +1265,7 @@ class BuiltinTest(unittest.TestCase):
|
|||
self.assertRaises(OverflowError, range, -sys.maxint, sys.maxint)
|
||||
self.assertRaises(OverflowError, range, 0, 2*sys.maxint)
|
||||
|
||||
def test_input_and_raw_input(self):
|
||||
def test_input(self):
|
||||
self.write_testfile()
|
||||
fp = open(TESTFN, 'r')
|
||||
savestdin = sys.stdin
|
||||
|
|
@ -1275,29 +1273,18 @@ class BuiltinTest(unittest.TestCase):
|
|||
try:
|
||||
sys.stdin = fp
|
||||
sys.stdout = BitBucket()
|
||||
self.assertEqual(input(), 2)
|
||||
self.assertEqual(input('testing\n'), 2)
|
||||
self.assertEqual(raw_input(), 'The quick brown fox jumps over the lazy dog.')
|
||||
self.assertEqual(raw_input('testing\n'), 'Dear John')
|
||||
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')
|
||||
sys.stdin = cStringIO.StringIO("NULL\0")
|
||||
self.assertRaises(TypeError, input, 42, 42)
|
||||
sys.stdin = cStringIO.StringIO(" 'whitespace'")
|
||||
self.assertEqual(input(), 'whitespace')
|
||||
whitespace = " 'whitespace'"
|
||||
sys.stdin = cStringIO.StringIO(whitespace)
|
||||
self.assertEqual(input(), whitespace)
|
||||
sys.stdin = cStringIO.StringIO()
|
||||
self.assertRaises(EOFError, input)
|
||||
|
||||
# SF 876178: make sure input() respect future options.
|
||||
sys.stdin = cStringIO.StringIO('1/2')
|
||||
sys.stdout = cStringIO.StringIO()
|
||||
exec compile('print input()', 'test_builtin_tmp', 'exec')
|
||||
sys.stdin.seek(0, 0)
|
||||
exec compile('from __future__ import division;print input()',
|
||||
'test_builtin_tmp', 'exec')
|
||||
sys.stdin.seek(0, 0)
|
||||
exec compile('print input()', 'test_builtin_tmp', 'exec')
|
||||
self.assertEqual(sys.stdout.getvalue().splitlines(),
|
||||
['0', '0.5', '0'])
|
||||
|
||||
del sys.stdout
|
||||
self.assertRaises(RuntimeError, input, 'prompt')
|
||||
del sys.stdin
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue