Mercurial > cpython
changeset 89007:75c75d90f3a4 2.7
Issue #20532: Tests which use _testcapi now are marked as CPython only. [#20532]
author | Serhiy Storchaka <storchaka@gmail.com> |
---|---|
date | Fri, 07 Feb 2014 10:06:05 +0200 |
parents | 305b6a5da852 |
children | 16af3de2240f |
files | Lib/test/string_tests.py Lib/test/test_capi.py Lib/test/test_code.py Lib/test/test_codecs.py Lib/test/test_descr.py Lib/test/test_fcntl.py Lib/test/test_fileio.py Lib/test/test_format.py Lib/test/test_getargs2.py Lib/test/test_poll.py Lib/test/test_socket.py Lib/test/test_structmembers.py Lib/test/test_support.py Lib/test/test_sys.py Lib/test/test_tcl.py Lib/test/test_threading.py Lib/test/test_traceback.py Lib/test/test_ucn.py Lib/test/test_unicode.py Misc/NEWS |
diffstat | 20 files changed, 208 insertions(+), 107 deletions(-) [+] |
line wrap: on
line diff
--- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -5,7 +5,6 @@ Common tests shared by test_str, test_un import unittest, string, sys, struct from test import test_support from UserList import UserList -import _testcapi class Sequence: def __init__(self, seq='wxyz'): self.seq = seq @@ -1114,20 +1113,6 @@ class MixinStrUnicodeUserStringTest: self.checkraises(TypeError, '%10.*f', '__mod__', ('foo', 42.)) self.checkraises(ValueError, '%10', '__mod__', (42,)) - width = int(_testcapi.PY_SSIZE_T_MAX + 1) - if width <= sys.maxint: - self.checkraises(OverflowError, '%*s', '__mod__', (width, '')) - prec = int(_testcapi.INT_MAX + 1) - if prec <= sys.maxint: - self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7)) - # Issue 15989 - width = int(1 << (_testcapi.PY_SSIZE_T_MAX.bit_length() + 1)) - if width <= sys.maxint: - self.checkraises(OverflowError, '%*s', '__mod__', (width, '')) - prec = int(_testcapi.UINT_MAX + 1) - if prec <= sys.maxint: - self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7)) - class X(object): pass self.checkraises(TypeError, 'abc', '__mod__', X()) class X(Exception): @@ -1135,6 +1120,24 @@ class MixinStrUnicodeUserStringTest: return k self.checkequal('melon apple', '%(melon)s %(apple)s', '__mod__', X()) + @test_support.cpython_only + 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)) + def test_floatformatting(self): # float formatting for prec in xrange(100):
--- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -13,7 +13,9 @@ try: except ImportError: thread = None threading = None -import _testcapi +# Skip this test if the _testcapi module isn't available. +_testcapi = test_support.import_module('_testcapi') + @unittest.skipUnless(threading, 'Threading required for this test.') class TestPendingCalls(unittest.TestCase):
--- a/Lib/test/test_code.py +++ b/Lib/test/test_code.py @@ -82,7 +82,7 @@ consts: ("'doc string'", 'None') import unittest import weakref -import _testcapi +from test.test_support import run_doctest, run_unittest, cpython_only def consts(t): @@ -104,7 +104,9 @@ def dump(co): class CodeTest(unittest.TestCase): + @cpython_only def test_newempty(self): + import _testcapi co = _testcapi.code_newempty("filename", "funcname", 15) self.assertEqual(co.co_filename, "filename") self.assertEqual(co.co_name, "funcname") @@ -137,7 +139,6 @@ class CodeWeakRefTest(unittest.TestCase) def test_main(verbose=None): - from test.test_support import run_doctest, run_unittest from test import test_code run_doctest(test_code, verbose) run_unittest(CodeTest, CodeWeakRefTest)
--- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -2,7 +2,7 @@ from test import test_support import unittest import codecs import locale -import sys, StringIO, _testcapi +import sys, StringIO def coding_checker(self, coder): def check(input, expect): @@ -1539,7 +1539,7 @@ else: class BasicUnicodeTest(unittest.TestCase): def test_basics(self): - s = u"abc123" # all codecs should be able to encode these + s = u"abc123" # all codecs should be able to encode these for encoding in all_unicode_encodings: name = codecs.lookup(encoding).name if encoding.endswith("_codec"): @@ -1548,9 +1548,9 @@ class BasicUnicodeTest(unittest.TestCase name = "latin_1" self.assertEqual(encoding.replace("_", "-"), name.replace("_", "-")) (bytes, size) = codecs.getencoder(encoding)(s) - self.assertEqual(size, len(s), "%r != %r (encoding=%r)" % (size, len(s), encoding)) + self.assertEqual(size, len(s), "encoding=%r" % encoding) (chars, size) = codecs.getdecoder(encoding)(bytes) - self.assertEqual(chars, s, "%r != %r (encoding=%r)" % (chars, s, encoding)) + self.assertEqual(chars, s, "encoding=%r" % encoding) if encoding not in broken_unicode_with_streams: # check stream reader/writer @@ -1566,15 +1566,13 @@ class BasicUnicodeTest(unittest.TestCase for c in encodedresult: q.write(c) decodedresult += reader.read() - self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding)) + self.assertEqual(decodedresult, s, "encoding=%r" % encoding) if encoding not in broken_incremental_coders: - # check incremental decoder/encoder (fetched via the Python - # and C API) and iterencode()/iterdecode() + # check incremental decoder/encoder and iterencode()/iterdecode() try: encoder = codecs.getincrementalencoder(encoding)() - cencoder = _testcapi.codec_incrementalencoder(encoding) - except LookupError: # no IncrementalEncoder + except LookupError: # no IncrementalEncoder pass else: # check incremental decoder/encoder @@ -1587,45 +1585,71 @@ class BasicUnicodeTest(unittest.TestCase for c in encodedresult: decodedresult += decoder.decode(c) decodedresult += decoder.decode("", True) - self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding)) - - # check C API - encodedresult = "" - for c in s: - encodedresult += cencoder.encode(c) - encodedresult += cencoder.encode(u"", True) - cdecoder = _testcapi.codec_incrementaldecoder(encoding) - decodedresult = u"" - for c in encodedresult: - decodedresult += cdecoder.decode(c) - decodedresult += cdecoder.decode("", True) - self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding)) + self.assertEqual(decodedresult, s, + "encoding=%r" % encoding) # check iterencode()/iterdecode() - result = u"".join(codecs.iterdecode(codecs.iterencode(s, encoding), encoding)) - self.assertEqual(result, s, "%r != %r (encoding=%r)" % (result, s, encoding)) + result = u"".join(codecs.iterdecode( + codecs.iterencode(s, encoding), encoding)) + self.assertEqual(result, s, "encoding=%r" % encoding) # check iterencode()/iterdecode() with empty string - result = u"".join(codecs.iterdecode(codecs.iterencode(u"", encoding), encoding)) + result = u"".join(codecs.iterdecode( + codecs.iterencode(u"", encoding), encoding)) self.assertEqual(result, u"") if encoding not in only_strict_mode: # check incremental decoder/encoder with errors argument try: encoder = codecs.getincrementalencoder(encoding)("ignore") - cencoder = _testcapi.codec_incrementalencoder(encoding, "ignore") - except LookupError: # no IncrementalEncoder + except LookupError: # no IncrementalEncoder pass else: encodedresult = "".join(encoder.encode(c) for c in s) decoder = codecs.getincrementaldecoder(encoding)("ignore") - decodedresult = u"".join(decoder.decode(c) for c in encodedresult) - self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding)) + decodedresult = u"".join(decoder.decode(c) + for c in encodedresult) + self.assertEqual(decodedresult, s, + "encoding=%r" % encoding) + @test_support.cpython_only + def test_basics_capi(self): + from _testcapi import codec_incrementalencoder, codec_incrementaldecoder + s = u"abc123" # all codecs should be able to encode these + for encoding in all_unicode_encodings: + if encoding not in broken_incremental_coders: + # check incremental decoder/encoder and iterencode()/iterdecode() + try: + cencoder = codec_incrementalencoder(encoding) + except LookupError: # no IncrementalEncoder + pass + else: + # check C API + encodedresult = "" + for c in s: + encodedresult += cencoder.encode(c) + encodedresult += cencoder.encode(u"", True) + cdecoder = codec_incrementaldecoder(encoding) + decodedresult = u"" + for c in encodedresult: + decodedresult += cdecoder.decode(c) + decodedresult += cdecoder.decode("", True) + self.assertEqual(decodedresult, s, + "encoding=%r" % encoding) + + if encoding not in only_strict_mode: + # check incremental decoder/encoder with errors argument + try: + cencoder = codec_incrementalencoder(encoding, "ignore") + except LookupError: # no IncrementalEncoder + pass + else: encodedresult = "".join(cencoder.encode(c) for c in s) - cdecoder = _testcapi.codec_incrementaldecoder(encoding, "ignore") - decodedresult = u"".join(cdecoder.decode(c) for c in encodedresult) - self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding)) + cdecoder = codec_incrementaldecoder(encoding, "ignore") + decodedresult = u"".join(cdecoder.decode(c) + for c in encodedresult) + self.assertEqual(decodedresult, s, + "encoding=%r" % encoding) def test_seek(self): # all codecs should be able to encode these
--- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -2092,6 +2092,7 @@ order (MRO) for bases """ prop2 = property(fset=setter) self.assertEqual(prop2.__doc__, None) + @test_support.cpython_only def test_testcapi_no_segfault(self): # this segfaulted in 2.5b2 try:
--- a/Lib/test/test_fcntl.py +++ b/Lib/test/test_fcntl.py @@ -6,10 +6,9 @@ OS/2+EMX doesn't support the file lockin import os import struct import sys -import _testcapi import unittest from test.test_support import (verbose, TESTFN, unlink, run_unittest, - import_module) + import_module, cpython_only) # Skip test if no fcntl module. fcntl = import_module('fcntl') @@ -52,6 +51,12 @@ def get_lockdata(): lockdata = get_lockdata() +class BadFile: + def __init__(self, fn): + self.fn = fn + def fileno(self): + return self.fn + class TestFcntl(unittest.TestCase): def setUp(self): @@ -83,24 +88,27 @@ class TestFcntl(unittest.TestCase): self.f.close() 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) + with self.assertRaises(ValueError): + fcntl.fcntl(-1, fcntl.F_SETFL, os.O_NONBLOCK) + with self.assertRaises(ValueError): + fcntl.fcntl(BadFile(-1), fcntl.F_SETFL, os.O_NONBLOCK) + with self.assertRaises(TypeError): + fcntl.fcntl('spam', fcntl.F_SETFL, os.O_NONBLOCK) + with self.assertRaises(TypeError): + fcntl.fcntl(BadFile('spam'), fcntl.F_SETFL, os.O_NONBLOCK) + + @cpython_only + def test_fcntl_bad_file_overflow(self): + from _testcapi import INT_MAX, INT_MIN # 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) + with self.assertRaises(ValueError): + fcntl.fcntl(INT_MAX + 1, fcntl.F_SETFL, os.O_NONBLOCK) + with self.assertRaises(ValueError): + fcntl.fcntl(BadFile(INT_MAX + 1), fcntl.F_SETFL, os.O_NONBLOCK) + with self.assertRaises(ValueError): + fcntl.fcntl(INT_MIN - 1, fcntl.F_SETFL, os.O_NONBLOCK) + with self.assertRaises(ValueError): + fcntl.fcntl(BadFile(INT_MIN - 1), fcntl.F_SETFL, os.O_NONBLOCK) def test_fcntl_64_bit(self): # Issue #1309352: fcntl shouldn't fail when the third arg fits in a
--- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -10,10 +10,9 @@ from array import array from weakref import proxy from functools import wraps from UserList import UserList -import _testcapi from test.test_support import TESTFN, check_warnings, run_unittest, make_bad_fd -from test.test_support import py3k_bytes as bytes +from test.test_support import py3k_bytes as bytes, cpython_only from test.script_helper import run_python from _io import FileIO as _FileIO @@ -359,7 +358,11 @@ class OtherFileTests(unittest.TestCase): if sys.platform == 'win32': import msvcrt self.assertRaises(IOError, msvcrt.get_osfhandle, make_bad_fd()) + + @cpython_only + def testInvalidFd_overflow(self): # Issue 15989 + import _testcapi self.assertRaises(TypeError, _FileIO, _testcapi.INT_MAX + 1) self.assertRaises(TypeError, _FileIO, _testcapi.INT_MIN - 1)
--- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -303,21 +303,31 @@ def test_main(): test_support.run_unittest(FormatTest) def test_precision(self): - INT_MAX = 2147483647 - 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" % (INT_MAX + 1)) + format(f, ".%sf" % (sys.maxsize + 1)) self.assertEqual(str(cm.exception), "precision too big") c = complex(f) - self.assertEqual(format(f, ".0f"), "1") - self.assertEqual(format(f, ".3f"), "1.200") + 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)) - self.assertEqual(str(cm.exception), "precision too big") + + c = complex(f) + with self.assertRaises(ValueError) as cm: + format(c, ".%sf" % (INT_MAX + 1)) if __name__ == "__main__":
--- a/Lib/test/test_getargs2.py +++ b/Lib/test/test_getargs2.py @@ -1,5 +1,7 @@ import unittest from test import test_support +# Skip this test if the _testcapi module isn't available. +test_support.import_module('_testcapi') from _testcapi import getargs_keywords import warnings
--- a/Lib/test/test_poll.py +++ b/Lib/test/test_poll.py @@ -3,14 +3,13 @@ import os import random import select -from _testcapi import USHRT_MAX, INT_MAX, UINT_MAX try: import threading except ImportError: threading = None import time import unittest -from test.test_support import TESTFN, run_unittest, reap_threads +from test.test_support import TESTFN, run_unittest, reap_threads, cpython_only try: select.poll @@ -161,8 +160,18 @@ class PollTests(unittest.TestCase): # Issues #15989, #17919 self.assertRaises(OverflowError, pollster.register, 0, -1) + self.assertRaises(OverflowError, pollster.register, 0, 1 << 64) + self.assertRaises(OverflowError, pollster.modify, 1, -1) + self.assertRaises(OverflowError, pollster.modify, 1, 1 << 64) + + @cpython_only + 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, -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)
--- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -4,7 +4,6 @@ from test import test_support import errno import socket import select -import _testcapi import time import traceback import Queue @@ -711,7 +710,10 @@ class GeneralModuleTests(unittest.TestCa srv.listen(backlog) srv.close() + @test_support.cpython_only + 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) @@ -818,6 +820,14 @@ class BasicTCPTest(SocketConnectedTest): def _testShutdown(self): self.serv_conn.send(MSG) + self.serv_conn.shutdown(2) + + testShutdown_overflow = test_support.cpython_only(testShutdown) + + @test_support.cpython_only + def _testShutdown_overflow(self): + import _testcapi + self.serv_conn.send(MSG) # Issue 15989 self.assertRaises(OverflowError, self.serv_conn.shutdown, _testcapi.INT_MAX + 1) @@ -911,14 +921,23 @@ class NonBlockingTCPTests(ThreadedTCPSoc pass end = time.time() self.assertTrue((end - start) < 1.0, "Error setting non-blocking mode.") - # Issue 15989 - if _testcapi.UINT_MAX < _testcapi.ULONG_MAX: - self.serv.setblocking(_testcapi.UINT_MAX + 1) - self.assertIsNone(self.serv.gettimeout()) def _testSetBlocking(self): pass + @test_support.cpython_only + def testSetBlocking_overflow(self): + # Issue 15989 + import _testcapi + if _testcapi.UINT_MAX >= _testcapi.ULONG_MAX: + self.skipTest('needs UINT_MAX < ULONG_MAX') + self.serv.setblocking(False) + self.assertEqual(self.serv.gettimeout(), 0.0) + self.serv.setblocking(_testcapi.UINT_MAX + 1) + self.assertIsNone(self.serv.gettimeout()) + + _testSetBlocking_overflow = test_support.cpython_only(_testSetBlocking) + def testAccept(self): # Testing non-blocking accept self.serv.setblocking(0)
--- a/Lib/test/test_structmembers.py +++ b/Lib/test/test_structmembers.py @@ -1,3 +1,8 @@ +import unittest +from test import test_support + +# Skip this test if the _testcapi module isn't available. +test_support.import_module('_testcapi') from _testcapi import _test_structmembersType, \ CHAR_MAX, CHAR_MIN, UCHAR_MAX, \ SHRT_MAX, SHRT_MIN, USHRT_MAX, \ @@ -5,9 +10,6 @@ from _testcapi import _test_structmember LONG_MAX, LONG_MIN, ULONG_MAX, \ LLONG_MAX, LLONG_MIN, ULLONG_MAX -import unittest -from test import test_support - ts=_test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8, 9.99999, 10.1010101010, "hi")
--- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -19,7 +19,6 @@ import UserDict import re import time import struct -import _testcapi import sysconfig try: import thread @@ -1002,6 +1001,7 @@ def calcvobjsize(fmt): _TPFLAGS_HEAPTYPE = 1<<9 def check_sizeof(test, o, size): + import _testcapi result = sys.getsizeof(o) # add GC header size if ((type(o) == type) and (o.__flags__ & _TPFLAGS_HEAPTYPE) or\
--- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -489,6 +489,7 @@ class SysModuleTest(unittest.TestCase): p.wait() self.assertIn(executable, ["''", repr(sys.executable)]) +@test.test_support.cpython_only class SizeofTest(unittest.TestCase): def setUp(self):
--- a/Lib/test/test_tcl.py +++ b/Lib/test/test_tcl.py @@ -1,7 +1,6 @@ import unittest import sys import os -import _testcapi from test import test_support from subprocess import Popen, PIPE @@ -11,6 +10,11 @@ from subprocess import Popen, PIPE from Tkinter import Tcl from _tkinter import TclError +try: + from _testcapi import INT_MAX, PY_SSIZE_T_MAX +except ImportError: + INT_MAX = PY_SSIZE_T_MAX = sys.maxsize + tcl_version = _tkinter.TCL_VERSION.split('.') try: for i in range(len(tcl_version)): @@ -523,10 +527,9 @@ class BigmemTclTest(unittest.TestCase): def setUp(self): self.interp = Tcl() - @unittest.skipUnless(_testcapi.INT_MAX < _testcapi.PY_SSIZE_T_MAX, - "needs UINT_MAX < SIZE_MAX") - @test_support.precisionbigmemtest(size=_testcapi.INT_MAX + 1, memuse=5, - dry_run=False) + @test_support.cpython_only + @unittest.skipUnless(INT_MAX < PY_SSIZE_T_MAX, "needs UINT_MAX < SIZE_MAX") + @test_support.precisionbigmemtest(size=INT_MAX + 1, memuse=5, dry_run=False) def test_huge_string(self, size): value = ' ' * size self.assertRaises(OverflowError, self.interp.call, 'set', '_', value)
--- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -1,7 +1,7 @@ # Very rudimentary test of threading module import test.test_support -from test.test_support import verbose +from test.test_support import verbose, cpython_only from test.script_helper import assert_python_ok import random @@ -724,6 +724,7 @@ class ThreadJoinOnShutdown(BaseTestCase) for t in threads: t.join() + @cpython_only @unittest.skipIf(_testcapi is None, "need _testcapi module") def test_frame_tstate_tracing(self): # Issue #14432: Crash when a generator is created in a C thread that is
--- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -1,11 +1,10 @@ """Test cases for traceback module""" -from _testcapi import traceback_print from StringIO import StringIO import sys import unittest from imp import reload -from test.test_support import run_unittest, is_jython, Error +from test.test_support import run_unittest, is_jython, Error, cpython_only import traceback @@ -181,7 +180,9 @@ def test(): class TracebackFormatTests(unittest.TestCase): + @cpython_only def test_traceback_format(self): + from _testcapi import traceback_print try: raise KeyError('blah') except KeyError:
--- a/Lib/test/test_ucn.py +++ b/Lib/test/test_ucn.py @@ -9,10 +9,14 @@ Modified for Python 2.0 by Fredrik Lundh import unittest import sys -import _testcapi from test import test_support +try: + from _testcapi import INT_MAX, PY_SSIZE_T_MAX, UINT_MAX +except ImportError: + INT_MAX = PY_SSIZE_T_MAX = UINT_MAX = 2**64 - 1 + class UnicodeNamesTest(unittest.TestCase): def checkletter(self, name, code): @@ -139,11 +143,10 @@ class UnicodeNamesTest(unittest.TestCase unicode, "\\NSPACE", 'unicode-escape', 'strict' ) - @unittest.skipUnless(_testcapi.INT_MAX < _testcapi.PY_SSIZE_T_MAX, - "needs UINT_MAX < SIZE_MAX") - @unittest.skipUnless(_testcapi.UINT_MAX < sys.maxint, - "needs UINT_MAX < sys.maxint") - @test_support.bigmemtest(minsize=_testcapi.UINT_MAX + 1, + @test_support.cpython_only + @unittest.skipUnless(INT_MAX < PY_SSIZE_T_MAX, "needs UINT_MAX < SIZE_MAX") + @unittest.skipUnless(UINT_MAX < sys.maxint, "needs UINT_MAX < sys.maxint") + @test_support.bigmemtest(minsize=UINT_MAX + 1, memuse=2 + 4 // len(u'\U00010000')) def test_issue16335(self, size): func = self.test_issue16335 @@ -151,9 +154,8 @@ class UnicodeNamesTest(unittest.TestCase raise unittest.SkipTest("not enough memory: %.1fG minimum needed" % (func.minsize * func.memuse / float(1024**3),)) # very very long bogus character name - x = b'\\N{SPACE' + b'x' * int(_testcapi.UINT_MAX + 1) + b'}' - self.assertEqual(len(x), len(b'\\N{SPACE}') + - (_testcapi.UINT_MAX + 1)) + x = b'\\N{SPACE' + b'x' * int(UINT_MAX + 1) + b'}' + self.assertEqual(len(x), len(b'\\N{SPACE}') + (UINT_MAX + 1)) self.assertRaisesRegexp(UnicodeError, 'unknown Unicode character name', x.decode, 'unicode-escape'
--- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -644,8 +644,13 @@ class UnicodeTest( return u'\u1234' self.assertEqual('%s' % Wrapper(), u'\u1234') + def test_formatting_huge_precision(self): + format_string = u"%.{}f".format(sys.maxsize + 1) + with self.assertRaises(ValueError): + result = format_string % 2.34 + @test_support.cpython_only - def test_formatting_huge_precision(self): + 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): @@ -1633,6 +1638,7 @@ class UnicodeTest( self.assertEqual("%s" % u, u'__unicode__ overridden') self.assertEqual("{}".format(u), '__unicode__ overridden') + @test_support.cpython_only def test_encode_decimal(self): from _testcapi import unicode_encodedecimal self.assertEqual(unicode_encodedecimal(u'123'), @@ -1658,6 +1664,7 @@ class UnicodeTest( self.assertEqual(unicode_encodedecimal(u"123\u20ac\u0660", "replace"), b'123?0') + @test_support.cpython_only def test_encode_decimal_with_surrogates(self): from _testcapi import unicode_encodedecimal tests = [(u'\U0001f49d', '💝'),