Python _testcapi.INT_MAX Examples

The following are 30 code examples of _testcapi.INT_MAX(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module _testcapi , or try the search function .
Example #1
Source File: test_fcntl.py    From CTFCrackTools with GNU General Public License v3.0 6 votes vote down vote up
def test_fcntl_bad_file(self):
        class F:
            def __init__(self, fn):
                self.fn = fn
            def fileno(self):
                return self.fn
        self.assertRaises(ValueError, fcntl.fcntl, -1, fcntl.F_SETFL, os.O_NONBLOCK)
        self.assertRaises(ValueError, fcntl.fcntl, F(-1), fcntl.F_SETFL, os.O_NONBLOCK)
        self.assertRaises(TypeError, fcntl.fcntl, 'spam', fcntl.F_SETFL, os.O_NONBLOCK)
        self.assertRaises(TypeError, fcntl.fcntl, F('spam'), fcntl.F_SETFL, os.O_NONBLOCK)
        # Issue 15989
        self.assertRaises(ValueError, fcntl.fcntl, _testcapi.INT_MAX + 1,
                                                   fcntl.F_SETFL, os.O_NONBLOCK)
        self.assertRaises(ValueError, fcntl.fcntl, F(_testcapi.INT_MAX + 1),
                                                   fcntl.F_SETFL, os.O_NONBLOCK)
        self.assertRaises(ValueError, fcntl.fcntl, _testcapi.INT_MIN - 1,
                                                   fcntl.F_SETFL, os.O_NONBLOCK)
        self.assertRaises(ValueError, fcntl.fcntl, F(_testcapi.INT_MIN - 1),
                                                   fcntl.F_SETFL, os.O_NONBLOCK) 
Example #2
Source File: string_tests.py    From gcblue with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_formatting_c_limits(self):
        from _testcapi import PY_SSIZE_T_MAX, INT_MAX, UINT_MAX
        SIZE_MAX = (1 << (PY_SSIZE_T_MAX.bit_length() + 1)) - 1
        width = int(PY_SSIZE_T_MAX + 1)
        if width <= sys.maxint:
            self.checkraises(OverflowError, '%*s', '__mod__', (width, ''))
        prec = int(INT_MAX + 1)
        if prec <= sys.maxint:
            self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7))
        # Issue 15989
        width = int(SIZE_MAX + 1)
        if width <= sys.maxint:
            self.checkraises(OverflowError, '%*s', '__mod__', (width, ''))
        prec = int(UINT_MAX + 1)
        if prec <= sys.maxint:
            self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7)) 
Example #3
Source File: string_tests.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_formatting_c_limits(self):
        from _testcapi import PY_SSIZE_T_MAX, INT_MAX, UINT_MAX
        SIZE_MAX = (1 << (PY_SSIZE_T_MAX.bit_length() + 1)) - 1
        width = int(PY_SSIZE_T_MAX + 1)
        if width <= sys.maxint:
            self.checkraises(OverflowError, '%*s', '__mod__', (width, ''))
        prec = int(INT_MAX + 1)
        if prec <= sys.maxint:
            self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7))
        # Issue 15989
        width = int(SIZE_MAX + 1)
        if width <= sys.maxint:
            self.checkraises(OverflowError, '%*s', '__mod__', (width, ''))
        prec = int(UINT_MAX + 1)
        if prec <= sys.maxint:
            self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7)) 
Example #4
Source File: test_poll.py    From BinderFilter with MIT License 6 votes vote down vote up
def test_poll3(self):
        # test int overflow
        pollster = select.poll()
        pollster.register(1)

        self.assertRaises(OverflowError, pollster.poll, 1L << 64)

        x = 2 + 3
        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) 
Example #5
Source File: test_fcntl.py    From CTFCrackTools-V2 with GNU General Public License v3.0 6 votes vote down vote up
def test_fcntl_bad_file(self):
        class F:
            def __init__(self, fn):
                self.fn = fn
            def fileno(self):
                return self.fn
        self.assertRaises(ValueError, fcntl.fcntl, -1, fcntl.F_SETFL, os.O_NONBLOCK)
        self.assertRaises(ValueError, fcntl.fcntl, F(-1), fcntl.F_SETFL, os.O_NONBLOCK)
        self.assertRaises(TypeError, fcntl.fcntl, 'spam', fcntl.F_SETFL, os.O_NONBLOCK)
        self.assertRaises(TypeError, fcntl.fcntl, F('spam'), fcntl.F_SETFL, os.O_NONBLOCK)
        # Issue 15989
        self.assertRaises(ValueError, fcntl.fcntl, _testcapi.INT_MAX + 1,
                                                   fcntl.F_SETFL, os.O_NONBLOCK)
        self.assertRaises(ValueError, fcntl.fcntl, F(_testcapi.INT_MAX + 1),
                                                   fcntl.F_SETFL, os.O_NONBLOCK)
        self.assertRaises(ValueError, fcntl.fcntl, _testcapi.INT_MIN - 1,
                                                   fcntl.F_SETFL, os.O_NONBLOCK)
        self.assertRaises(ValueError, fcntl.fcntl, F(_testcapi.INT_MIN - 1),
                                                   fcntl.F_SETFL, os.O_NONBLOCK) 
Example #6
Source File: string_tests.py    From oss-ftp with MIT License 6 votes vote down vote up
def test_formatting_c_limits(self):
        from _testcapi import PY_SSIZE_T_MAX, INT_MAX, UINT_MAX
        SIZE_MAX = (1 << (PY_SSIZE_T_MAX.bit_length() + 1)) - 1
        width = int(PY_SSIZE_T_MAX + 1)
        if width <= sys.maxint:
            self.checkraises(OverflowError, '%*s', '__mod__', (width, ''))
        prec = int(INT_MAX + 1)
        if prec <= sys.maxint:
            self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7))
        # Issue 15989
        width = int(SIZE_MAX + 1)
        if width <= sys.maxint:
            self.checkraises(OverflowError, '%*s', '__mod__', (width, ''))
        prec = int(UINT_MAX + 1)
        if prec <= sys.maxint:
            self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7)) 
Example #7
Source File: test_str.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_formatting_huge_precision(self):
        from _testcapi import INT_MAX
        format_string = "%.{}f".format(INT_MAX + 1)
        with self.assertRaises(ValueError):
            result = format_string % 2.34 
Example #8
Source File: test_fcntl.py    From android_universal with MIT License 5 votes vote down vote up
def test_flock_overflow(self):
        import _testcapi
        self.assertRaises(OverflowError, fcntl.flock, _testcapi.INT_MAX+1,
                          fcntl.LOCK_SH) 
Example #9
Source File: test_structures.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_packed_c_limits(self):
        # Issue 15989
        import _testcapi
        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) 
Example #10
Source File: test_socket.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_listen_backlog_overflow(self):
        # Issue 15989
        import _testcapi
        srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        srv.bind((HOST, 0))
        self.assertRaises(OverflowError, srv.listen, _testcapi.INT_MAX + 1)
        srv.close() 
Example #11
Source File: test_socket.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def _testShutdown_overflow(self):
        import _testcapi
        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) 
Example #12
Source File: test_unicode.py    From android_universal with MIT License 5 votes vote down vote up
def test_formatting_huge_precision_c_limits(self):
        from _testcapi import INT_MAX
        format_string = "%.{}f".format(INT_MAX + 1)
        with self.assertRaises(ValueError):
            result = format_string % 2.34 
Example #13
Source File: test_structures.py    From android_universal with MIT License 5 votes vote down vote up
def test_packed_c_limits(self):
        # Issue 15989
        import _testcapi
        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) 
Example #14
Source File: test_io.py    From android_universal with MIT License 5 votes vote down vote up
def test_device_encoding(self):
        # Issue 15989
        import _testcapi
        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) 
Example #15
Source File: test_poll.py    From android_universal with MIT License 5 votes vote down vote up
def test_poll_c_limits(self):
        from _testcapi import USHRT_MAX, INT_MAX, UINT_MAX
        pollster = select.poll()
        pollster.register(1)

        # Issues #15989, #17919
        self.assertRaises(OverflowError, pollster.register, 0, USHRT_MAX + 1)
        self.assertRaises(OverflowError, pollster.modify, 1, USHRT_MAX + 1)
        self.assertRaises(OverflowError, pollster.poll, INT_MAX + 1)
        self.assertRaises(OverflowError, pollster.poll, UINT_MAX + 1) 
Example #16
Source File: test_format.py    From android_universal with MIT License 5 votes vote down vote up
def test_precision_c_limits(self):
        from _testcapi import INT_MAX

        f = 1.2
        with self.assertRaises(ValueError) as cm:
            format(f, ".%sf" % (INT_MAX + 1))

        c = complex(f)
        with self.assertRaises(ValueError) as cm:
            format(c, ".%sf" % (INT_MAX + 1)) 
Example #17
Source File: test_fcntl.py    From android_universal with MIT License 5 votes vote down vote up
def test_fcntl_bad_file_overflow(self):
        from _testcapi import INT_MAX, INT_MIN
        # Issue 15989
        with self.assertRaises(OverflowError):
            fcntl.fcntl(INT_MAX + 1, fcntl.F_SETFL, os.O_NONBLOCK)
        with self.assertRaises(OverflowError):
            fcntl.fcntl(BadFile(INT_MAX + 1), fcntl.F_SETFL, os.O_NONBLOCK)
        with self.assertRaises(OverflowError):
            fcntl.fcntl(INT_MIN - 1, fcntl.F_SETFL, os.O_NONBLOCK)
        with self.assertRaises(OverflowError):
            fcntl.fcntl(BadFile(INT_MIN - 1), fcntl.F_SETFL, os.O_NONBLOCK) 
Example #18
Source File: test_poll.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_poll_c_limits(self):
        from _testcapi import USHRT_MAX, INT_MAX, UINT_MAX
        pollster = select.poll()
        pollster.register(1)

        # Issues #15989, #17919
        self.assertRaises(OverflowError, pollster.register, 0, USHRT_MAX + 1)
        self.assertRaises(OverflowError, pollster.modify, 1, USHRT_MAX + 1)
        self.assertRaises(OverflowError, pollster.poll, INT_MAX + 1)
        self.assertRaises(OverflowError, pollster.poll, UINT_MAX + 1) 
Example #19
Source File: test_fileio.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testInvalidFd_overflow(self):
        # Issue 15989
        import _testcapi
        self.assertRaises(TypeError, _FileIO, _testcapi.INT_MAX + 1)
        self.assertRaises(TypeError, _FileIO, _testcapi.INT_MIN - 1) 
Example #20
Source File: test_unicode.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_formatting_huge_precision_c_limits(self):
        from _testcapi import INT_MAX
        format_string = u"%.{}f".format(INT_MAX + 1)
        with self.assertRaises(ValueError):
            result = format_string % 2.34 
Example #21
Source File: test_format.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_main():
    test_support.run_unittest(FormatTest)

    def test_precision(self):
        f = 1.2
        self.assertEqual(format(f, ".0f"), "1")
        self.assertEqual(format(f, ".3f"), "1.200")
        with self.assertRaises(ValueError) as cm:
            format(f, ".%sf" % (sys.maxsize + 1))
        self.assertEqual(str(cm.exception), "precision too big")

        c = complex(f)
        self.assertEqual(format(c, ".0f"), "1+0j")
        self.assertEqual(format(c, ".3f"), "1.200+0.000j")
        with self.assertRaises(ValueError) as cm:
            format(c, ".%sf" % (sys.maxsize + 1))
        self.assertEqual(str(cm.exception), "precision too big")

    @test_support.cpython_only
    def test_precision_c_limits(self):
        from _testcapi import INT_MAX

        f = 1.2
        with self.assertRaises(ValueError) as cm:
            format(f, ".%sf" % (INT_MAX + 1))

        c = complex(f)
        with self.assertRaises(ValueError) as cm:
            format(c, ".%sf" % (INT_MAX + 1)) 
Example #22
Source File: test_poll.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_poll_c_limits(self):
        from _testcapi import USHRT_MAX, INT_MAX, UINT_MAX
        pollster = select.poll()
        pollster.register(1)

        # Issues #15989, #17919
        self.assertRaises(OverflowError, pollster.register, 0, USHRT_MAX + 1)
        self.assertRaises(OverflowError, pollster.modify, 1, USHRT_MAX + 1)
        self.assertRaises(OverflowError, pollster.poll, INT_MAX + 1)
        self.assertRaises(OverflowError, pollster.poll, UINT_MAX + 1) 
Example #23
Source File: test_socket.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _testShutdown_overflow(self):
        import _testcapi
        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) 
Example #24
Source File: test_socket.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_listen_backlog_overflow(self):
        # Issue 15989
        import _testcapi
        srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        srv.bind((HOST, 0))
        self.assertRaises(OverflowError, srv.listen, _testcapi.INT_MAX + 1)
        srv.close() 
Example #25
Source File: string_tests.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_formatting_c_limits(self):
        from _testcapi import PY_SSIZE_T_MAX, INT_MAX, UINT_MAX
        SIZE_MAX = (1 << (PY_SSIZE_T_MAX.bit_length() + 1)) - 1
        self.checkraises(OverflowError, '%*s', '__mod__',
                         (PY_SSIZE_T_MAX + 1, ''))
        self.checkraises(OverflowError, '%.*f', '__mod__',
                         (INT_MAX + 1, 1. / 7))
        # Issue 15989
        self.checkraises(OverflowError, '%*s', '__mod__',
                         (SIZE_MAX + 1, ''))
        self.checkraises(OverflowError, '%.*f', '__mod__',
                         (UINT_MAX + 1, 1. / 7)) 
Example #26
Source File: test_posix.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_pipe2_c_limits(self):
        # Issue 15989
        import _testcapi
        self.assertRaises(OverflowError, os.pipe2, _testcapi.INT_MAX + 1)
        self.assertRaises(OverflowError, os.pipe2, _testcapi.UINT_MAX + 1) 
Example #27
Source File: test_fcntl.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_flock_overflow(self):
        import _testcapi
        self.assertRaises(OverflowError, fcntl.flock, _testcapi.INT_MAX+1,
                          fcntl.LOCK_SH) 
Example #28
Source File: test_fcntl.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_fcntl_bad_file_overflow(self):
        from _testcapi import INT_MAX, INT_MIN
        # Issue 15989
        with self.assertRaises(OverflowError):
            fcntl.fcntl(INT_MAX + 1, fcntl.F_SETFL, os.O_NONBLOCK)
        with self.assertRaises(OverflowError):
            fcntl.fcntl(BadFile(INT_MAX + 1), fcntl.F_SETFL, os.O_NONBLOCK)
        with self.assertRaises(OverflowError):
            fcntl.fcntl(INT_MIN - 1, fcntl.F_SETFL, os.O_NONBLOCK)
        with self.assertRaises(OverflowError):
            fcntl.fcntl(BadFile(INT_MIN - 1), fcntl.F_SETFL, os.O_NONBLOCK) 
Example #29
Source File: test_unicode.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_formatting_huge_precision_c_limits(self):
        from _testcapi import INT_MAX
        format_string = "%.{}f".format(INT_MAX + 1)
        with self.assertRaises(ValueError):
            result = format_string % 2.34 
Example #30
Source File: test_socket.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def _testShutdown_overflow(self):
        import _testcapi
        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)