summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_builtin.py
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2008-01-19 19:12:01 (GMT)
committerFacundo Batista <facundobatista@gmail.com>2008-01-19 19:12:01 (GMT)
commit2336bddd5dba559db950e8b5fa73257fc62d1fc3 (patch)
tree15256a53494c4a5c75d748a26402906177b3d523 /Lib/test/test_builtin.py
parent587c2bfedee6f6c5ee16b4e7eb5392d270a0c1a6 (diff)
downloadcpython-2336bddd5dba559db950e8b5fa73257fc62d1fc3.zip
cpython-2336bddd5dba559db950e8b5fa73257fc62d1fc3.tar.gz
cpython-2336bddd5dba559db950e8b5fa73257fc62d1fc3.tar.bz2
Fix Issue #1769: Now int('- 1') or int('+ 1') is not allowed
any more. Thanks Juan Jose Conti. Also added tests.
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r--Lib/test/test_builtin.py38
1 files changed, 35 insertions, 3 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index b10caf5..4cf5916 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -49,7 +49,7 @@ class BitBucket:
def write(self, line):
pass
-L = [
+test_conv_no_sign = [
('0', 0),
('1', 1),
('9', 9),
@@ -71,6 +71,28 @@ L = [
(chr(0x200), ValueError),
]
+test_conv_sign = [
+ ('0', 0),
+ ('1', 1),
+ ('9', 9),
+ ('10', 10),
+ ('99', 99),
+ ('100', 100),
+ ('314', 314),
+ (' 314', ValueError),
+ ('314 ', 314),
+ (' \t\t 314 \t\t ', ValueError),
+ (repr(sys.maxsize), sys.maxsize),
+ (' 1x', ValueError),
+ (' 1 ', ValueError),
+ (' 1\02 ', ValueError),
+ ('', ValueError),
+ (' ', ValueError),
+ (' \t\t ', ValueError),
+ (str(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
+ (chr(0x200), ValueError),
+]
+
class TestFailingBool:
def __bool__(self):
raise RuntimeError
@@ -641,8 +663,18 @@ class BuiltinTest(unittest.TestCase):
# Different base:
self.assertEqual(int("10",16), 16)
# Test conversion from strings and various anomalies
- for s, v in L:
- for sign in "", "+", "-":
+ # Testing with no sign at front
+ for s, v in test_conv_no_sign:
+ for prefix in "", " ", "\t", " \t\t ":
+ ss = prefix + s
+ vv = v
+ try:
+ self.assertEqual(int(ss), vv)
+ except v:
+ pass
+ # No whitespaces allowed between + or - sign and the number
+ for s, v in test_conv_sign:
+ for sign in "+", "-":
for prefix in "", " ", "\t", " \t\t ":
ss = prefix + sign + s
vv = v