diff -r 2d53f92ed54c Lib/ctypes/test/test_structures.py --- a/Lib/ctypes/test/test_structures.py Fri Oct 19 20:40:57 2012 +0300 +++ b/Lib/ctypes/test/test_structures.py Sat Oct 20 14:26:28 2012 +0300 @@ -1,6 +1,7 @@ import unittest from ctypes import * from struct import calcsize +import _testcapi class SubclassesTest(unittest.TestCase): def test_subclass(self): @@ -199,6 +200,14 @@ "_pack_": -1} self.assertRaises(ValueError, type(Structure), "X", (Structure,), d) + # Issue 15989 + d = {"_fields_": [("a", c_byte)], + "_pack_": _testcapi.INT_MAX + 1} + self.assertRaises(ValueError, type(Structure), "X", (Structure,), d) + d = {"_fields_": [("a", c_byte)], + "_pack_": _testcapi.UINT_MAX + 2} + self.assertRaises(ValueError, type(Structure), "X", (Structure,), d) + def test_initializers(self): class Person(Structure): _fields_ = [("name", c_char*6), diff -r 2d53f92ed54c Lib/test/string_tests.py --- a/Lib/test/string_tests.py Fri Oct 19 20:40:57 2012 +0300 +++ b/Lib/test/string_tests.py Sat Oct 20 14:26:28 2012 +0300 @@ -5,6 +5,7 @@ import unittest, string, sys, struct from test import support from collections import UserList +import _testcapi class Sequence: def __init__(self, seq='wxyz'): self.seq = seq @@ -1206,6 +1207,16 @@ self.checkraises(ValueError, '%%%df' % (2**64), '__mod__', (3.2)) self.checkraises(ValueError, '%%.%df' % (2**64), '__mod__', (3.2)) + self.checkraises(OverflowError, '%*s', '__mod__', + (_testcapi.PY_SSIZE_T_MAX + 1, '')) + self.checkraises(OverflowError, '%.*f', '__mod__', + (_testcapi.INT_MAX + 1, 1. / 7)) + # Issue 15989 + self.checkraises(OverflowError, '%*s', '__mod__', + (1 << (_testcapi.PY_SSIZE_T_MAX.bit_length() + 1), '')) + self.checkraises(OverflowError, '%.*f', '__mod__', + (_testcapi.UINT_MAX + 1, 1. / 7)) + class X(object): pass self.checkraises(TypeError, 'abc', '__mod__', X()) diff -r 2d53f92ed54c Lib/test/test_fileio.py --- a/Lib/test/test_fileio.py Fri Oct 19 20:40:57 2012 +0300 +++ b/Lib/test/test_fileio.py Sat Oct 20 14:26:28 2012 +0300 @@ -8,6 +8,7 @@ from array import array from weakref import proxy from functools import wraps +import _testcapi from test.support import TESTFN, check_warnings, run_unittest, make_bad_fd from collections import UserList @@ -347,6 +348,8 @@ if sys.platform == 'win32': import msvcrt self.assertRaises(IOError, msvcrt.get_osfhandle, make_bad_fd()) + # Issue 15989 + self.assertRaises(TypeError, _FileIO, _testcapi.INT_MIN - 1) def testBadModeArgument(self): # verify that we get a sensible error message for bad mode argument diff -r 2d53f92ed54c Lib/test/test_grp.py --- a/Lib/test/test_grp.py Fri Oct 19 20:40:57 2012 +0300 +++ b/Lib/test/test_grp.py Sat Oct 20 14:26:28 2012 +0300 @@ -2,6 +2,7 @@ import unittest from test import support +import _testcapi grp = support.import_module('grp') @@ -89,6 +90,9 @@ fakegid = (fakegid * 3) % 0x10000 self.assertRaises(KeyError, grp.getgrgid, fakegid) + # Issue 15989 + self.assertRaises(OverflowError, grp.getgrgid, _testcapi.INT_MAX + 1) + self.assertRaises(OverflowError, grp.getgrgid, _testcapi.UINT_MAX + 1) def test_main(): support.run_unittest(GroupDatabaseTestCase) diff -r 2d53f92ed54c Lib/test/test_io.py --- a/Lib/test/test_io.py Fri Oct 19 20:40:57 2012 +0300 +++ b/Lib/test/test_io.py Sat Oct 20 14:26:28 2012 +0300 @@ -32,6 +32,7 @@ import unittest import warnings import weakref +import _testcapi from collections import deque, UserList from itertools import cycle, count from test import support @@ -1943,6 +1944,14 @@ os.environ.clear() os.environ.update(old_environ) + # Issue 15989 + def test_device_encoding(self): + b = self.BytesIO() + b.fileno = lambda: _testcapi.INT_MAX + 1 + self.assertRaises(OverflowError, self.TextIOWrapper, b) + b.fileno = lambda: _testcapi.UINT_MAX + 1 + self.assertRaises(OverflowError, self.TextIOWrapper, b) + def test_encoding(self): # Check the encoding attribute is always set, and valid b = self.BytesIO() diff -r 2d53f92ed54c Lib/test/test_os.py --- a/Lib/test/test_os.py Fri Oct 19 20:40:57 2012 +0300 +++ b/Lib/test/test_os.py Sat Oct 20 14:26:28 2012 +0300 @@ -24,6 +24,7 @@ import stat import locale import codecs +import _testcapi try: import threading except ImportError: @@ -1085,6 +1086,15 @@ else: self.fail("%r didn't raise a OSError with a bad file descriptor" % f) + # Issue 15989 + if f == getattr(os, "fdopen", None): + errtype = TypeError + else: + errtype = OverflowError + self.assertRaises(errtype, f, + _testcapi.INT_MAX + 1, *args) + self.assertRaises(errtype, f, + _testcapi.UINT_MAX + 1, *args) def test_isatty(self): if hasattr(os, "isatty"): diff -r 2d53f92ed54c Lib/test/test_poll.py --- a/Lib/test/test_poll.py Fri Oct 19 20:40:57 2012 +0300 +++ b/Lib/test/test_poll.py Sat Oct 20 14:26:28 2012 +0300 @@ -1,6 +1,7 @@ # Test case for the os.poll() function import os, select, random, unittest +import _testcapi from test.support import TESTFN, run_unittest try: @@ -150,6 +151,15 @@ if x != 5: self.fail('Overflow must have occurred') + pollster = select.poll() + # Issue 15989 + self.assertRaises(OverflowError, pollster.register, 0, + _testcapi.SHRT_MAX + 1) + self.assertRaises(OverflowError, pollster.register, 0, + _testcapi.USHRT_MAX + 1) + self.assertRaises(OverflowError, pollster.poll, _testcapi.INT_MAX + 1) + self.assertRaises(OverflowError, pollster.poll, _testcapi.UINT_MAX + 1) + def test_main(): run_unittest(PollTests) diff -r 2d53f92ed54c Lib/test/test_posix.py --- a/Lib/test/test_posix.py Fri Oct 19 20:40:57 2012 +0300 +++ b/Lib/test/test_posix.py Sat Oct 20 14:26:28 2012 +0300 @@ -17,6 +17,7 @@ import tempfile import unittest import warnings +import _testcapi _DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(), support.TESTFN + '-dummy-symlink') @@ -521,6 +522,10 @@ except OSError: pass + # Issue 15989 + self.assertRaises(OverflowError, os.pipe2, _testcapi.INT_MAX + 1) + self.assertRaises(OverflowError, os.pipe2, _testcapi.UINT_MAX + 1) + def test_utime(self): if hasattr(posix, 'utime'): now = time.time() diff -r 2d53f92ed54c Lib/test/test_socket.py --- a/Lib/test/test_socket.py Fri Oct 19 20:40:57 2012 +0300 +++ b/Lib/test/test_socket.py Sat Oct 20 14:26:28 2012 +0300 @@ -1262,11 +1262,17 @@ for protocol in range(pickle.HIGHEST_PROTOCOL + 1): self.assertRaises(TypeError, pickle.dumps, sock, protocol) - def test_listen_backlog0(self): + def test_listen_backlog(self): + for backlog in 0, -1: + srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + srv.bind((HOST, 0)) + srv.listen(backlog) + srv.close() + + # Issue 15989 srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) srv.bind((HOST, 0)) - # backlog = 0 - srv.listen(0) + self.assertRaises(OverflowError, srv.listen, _testcapi.INT_MAX + 1) srv.close() @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.') @@ -1582,6 +1588,11 @@ def _testShutdown(self): self.serv_conn.send(MSG) + # Issue 15989 + self.assertRaises(OverflowError, self.serv_conn.shutdown, + _testcapi.INT_MAX + 1) + self.assertRaises(OverflowError, self.serv_conn.shutdown, + 2 + (_testcapi.UINT_MAX + 1)) self.serv_conn.shutdown(2) def testDetach(self): @@ -3549,6 +3560,11 @@ pass end = time.time() self.assertTrue((end - start) < 1.0, "Error setting non-blocking mode.") + # Issue 15989 + self.assertRaises(OverflowError, self.serv.setblocking, + _testcapi.INT_MAX + 1) + self.assertRaises(OverflowError, self.serv.setblocking, + _testcapi.UINT_MAX + 1) def _testSetBlocking(self): pass