Commit 76249ea4 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #20532: Tests which use _testcapi now are marked as CPython only.

parent 6a036793
...@@ -5,7 +5,6 @@ Common tests shared by test_str, test_unicode, test_userstring and test_string. ...@@ -5,7 +5,6 @@ Common tests shared by test_str, test_unicode, test_userstring and test_string.
import unittest, string, sys, struct import unittest, string, sys, struct
from test import test_support from test import test_support
from UserList import UserList from UserList import UserList
import _testcapi
class Sequence: class Sequence:
def __init__(self, seq='wxyz'): self.seq = seq def __init__(self, seq='wxyz'): self.seq = seq
...@@ -1114,27 +1113,31 @@ class MixinStrUnicodeUserStringTest: ...@@ -1114,27 +1113,31 @@ class MixinStrUnicodeUserStringTest:
self.checkraises(TypeError, '%10.*f', '__mod__', ('foo', 42.)) self.checkraises(TypeError, '%10.*f', '__mod__', ('foo', 42.))
self.checkraises(ValueError, '%10', '__mod__', (42,)) self.checkraises(ValueError, '%10', '__mod__', (42,))
width = int(_testcapi.PY_SSIZE_T_MAX + 1) class X(object): pass
self.checkraises(TypeError, 'abc', '__mod__', X())
class X(Exception):
def __getitem__(self, k):
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: if width <= sys.maxint:
self.checkraises(OverflowError, '%*s', '__mod__', (width, '')) self.checkraises(OverflowError, '%*s', '__mod__', (width, ''))
prec = int(_testcapi.INT_MAX + 1) prec = int(INT_MAX + 1)
if prec <= sys.maxint: if prec <= sys.maxint:
self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7)) self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7))
# Issue 15989 # Issue 15989
width = int(1 << (_testcapi.PY_SSIZE_T_MAX.bit_length() + 1)) width = int(SIZE_MAX + 1)
if width <= sys.maxint: if width <= sys.maxint:
self.checkraises(OverflowError, '%*s', '__mod__', (width, '')) self.checkraises(OverflowError, '%*s', '__mod__', (width, ''))
prec = int(_testcapi.UINT_MAX + 1) prec = int(UINT_MAX + 1)
if prec <= sys.maxint: if prec <= sys.maxint:
self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7)) self.checkraises(OverflowError, '%.*f', '__mod__', (prec, 1. / 7))
class X(object): pass
self.checkraises(TypeError, 'abc', '__mod__', X())
class X(Exception):
def __getitem__(self, k):
return k
self.checkequal('melon apple', '%(melon)s %(apple)s', '__mod__', X())
def test_floatformatting(self): def test_floatformatting(self):
# float formatting # float formatting
for prec in xrange(100): for prec in xrange(100):
......
...@@ -13,7 +13,9 @@ try: ...@@ -13,7 +13,9 @@ try:
except ImportError: except ImportError:
thread = None thread = None
threading = 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.') @unittest.skipUnless(threading, 'Threading required for this test.')
class TestPendingCalls(unittest.TestCase): class TestPendingCalls(unittest.TestCase):
......
...@@ -82,7 +82,7 @@ consts: ("'doc string'", 'None') ...@@ -82,7 +82,7 @@ consts: ("'doc string'", 'None')
import unittest import unittest
import weakref import weakref
import _testcapi from test.test_support import run_doctest, run_unittest, cpython_only
def consts(t): def consts(t):
...@@ -104,7 +104,9 @@ def dump(co): ...@@ -104,7 +104,9 @@ def dump(co):
class CodeTest(unittest.TestCase): class CodeTest(unittest.TestCase):
@cpython_only
def test_newempty(self): def test_newempty(self):
import _testcapi
co = _testcapi.code_newempty("filename", "funcname", 15) co = _testcapi.code_newempty("filename", "funcname", 15)
self.assertEqual(co.co_filename, "filename") self.assertEqual(co.co_filename, "filename")
self.assertEqual(co.co_name, "funcname") self.assertEqual(co.co_name, "funcname")
...@@ -137,7 +139,6 @@ class CodeWeakRefTest(unittest.TestCase): ...@@ -137,7 +139,6 @@ class CodeWeakRefTest(unittest.TestCase):
def test_main(verbose=None): def test_main(verbose=None):
from test.test_support import run_doctest, run_unittest
from test import test_code from test import test_code
run_doctest(test_code, verbose) run_doctest(test_code, verbose)
run_unittest(CodeTest, CodeWeakRefTest) run_unittest(CodeTest, CodeWeakRefTest)
......
...@@ -2,7 +2,7 @@ from test import test_support ...@@ -2,7 +2,7 @@ from test import test_support
import unittest import unittest
import codecs import codecs
import locale import locale
import sys, StringIO, _testcapi import sys, StringIO
def coding_checker(self, coder): def coding_checker(self, coder):
def check(input, expect): def check(input, expect):
...@@ -1548,9 +1548,9 @@ class BasicUnicodeTest(unittest.TestCase): ...@@ -1548,9 +1548,9 @@ class BasicUnicodeTest(unittest.TestCase):
name = "latin_1" name = "latin_1"
self.assertEqual(encoding.replace("_", "-"), name.replace("_", "-")) self.assertEqual(encoding.replace("_", "-"), name.replace("_", "-"))
(bytes, size) = codecs.getencoder(encoding)(s) (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) (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: if encoding not in broken_unicode_with_streams:
# check stream reader/writer # check stream reader/writer
...@@ -1566,14 +1566,12 @@ class BasicUnicodeTest(unittest.TestCase): ...@@ -1566,14 +1566,12 @@ class BasicUnicodeTest(unittest.TestCase):
for c in encodedresult: for c in encodedresult:
q.write(c) q.write(c)
decodedresult += reader.read() 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: if encoding not in broken_incremental_coders:
# check incremental decoder/encoder (fetched via the Python # check incremental decoder/encoder and iterencode()/iterdecode()
# and C API) and iterencode()/iterdecode()
try: try:
encoder = codecs.getincrementalencoder(encoding)() encoder = codecs.getincrementalencoder(encoding)()
cencoder = _testcapi.codec_incrementalencoder(encoding)
except LookupError: # no IncrementalEncoder except LookupError: # no IncrementalEncoder
pass pass
else: else:
...@@ -1587,45 +1585,71 @@ class BasicUnicodeTest(unittest.TestCase): ...@@ -1587,45 +1585,71 @@ class BasicUnicodeTest(unittest.TestCase):
for c in encodedresult: for c in encodedresult:
decodedresult += decoder.decode(c) decodedresult += decoder.decode(c)
decodedresult += decoder.decode("", True) decodedresult += decoder.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, "encoding=%r" % encoding)
# check iterencode()/iterdecode() with empty string
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")
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,
"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 # check C API
encodedresult = "" encodedresult = ""
for c in s: for c in s:
encodedresult += cencoder.encode(c) encodedresult += cencoder.encode(c)
encodedresult += cencoder.encode(u"", True) encodedresult += cencoder.encode(u"", True)
cdecoder = _testcapi.codec_incrementaldecoder(encoding) cdecoder = codec_incrementaldecoder(encoding)
decodedresult = u"" decodedresult = u""
for c in encodedresult: for c in encodedresult:
decodedresult += cdecoder.decode(c) decodedresult += cdecoder.decode(c)
decodedresult += cdecoder.decode("", True) 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))
# check iterencode()/iterdecode() with empty string
result = u"".join(codecs.iterdecode(codecs.iterencode(u"", encoding), encoding))
self.assertEqual(result, u"")
if encoding not in only_strict_mode: if encoding not in only_strict_mode:
# check incremental decoder/encoder with errors argument # check incremental decoder/encoder with errors argument
try: try:
encoder = codecs.getincrementalencoder(encoding)("ignore") cencoder = codec_incrementalencoder(encoding, "ignore")
cencoder = _testcapi.codec_incrementalencoder(encoding, "ignore")
except LookupError: # no IncrementalEncoder except LookupError: # no IncrementalEncoder
pass pass
else: 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))
encodedresult = "".join(cencoder.encode(c) for c in s) encodedresult = "".join(cencoder.encode(c) for c in s)
cdecoder = _testcapi.codec_incrementaldecoder(encoding, "ignore") cdecoder = codec_incrementaldecoder(encoding, "ignore")
decodedresult = u"".join(cdecoder.decode(c) for c in encodedresult) decodedresult = u"".join(cdecoder.decode(c)
self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding)) for c in encodedresult)
self.assertEqual(decodedresult, s,
"encoding=%r" % encoding)
def test_seek(self): def test_seek(self):
# all codecs should be able to encode these # all codecs should be able to encode these
......
...@@ -2092,6 +2092,7 @@ order (MRO) for bases """ ...@@ -2092,6 +2092,7 @@ order (MRO) for bases """
prop2 = property(fset=setter) prop2 = property(fset=setter)
self.assertEqual(prop2.__doc__, None) self.assertEqual(prop2.__doc__, None)
@test_support.cpython_only
def test_testcapi_no_segfault(self): def test_testcapi_no_segfault(self):
# this segfaulted in 2.5b2 # this segfaulted in 2.5b2
try: try:
......
...@@ -6,10 +6,9 @@ OS/2+EMX doesn't support the file locking operations. ...@@ -6,10 +6,9 @@ OS/2+EMX doesn't support the file locking operations.
import os import os
import struct import struct
import sys import sys
import _testcapi
import unittest import unittest
from test.test_support import (verbose, TESTFN, unlink, run_unittest, from test.test_support import (verbose, TESTFN, unlink, run_unittest,
import_module) import_module, cpython_only)
# Skip test if no fcntl module. # Skip test if no fcntl module.
fcntl = import_module('fcntl') fcntl = import_module('fcntl')
...@@ -52,6 +51,12 @@ def get_lockdata(): ...@@ -52,6 +51,12 @@ def get_lockdata():
lockdata = get_lockdata() lockdata = get_lockdata()
class BadFile:
def __init__(self, fn):
self.fn = fn
def fileno(self):
return self.fn
class TestFcntl(unittest.TestCase): class TestFcntl(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -83,24 +88,27 @@ class TestFcntl(unittest.TestCase): ...@@ -83,24 +88,27 @@ class TestFcntl(unittest.TestCase):
self.f.close() self.f.close()
def test_fcntl_bad_file(self): def test_fcntl_bad_file(self):
class F: with self.assertRaises(ValueError):
def __init__(self, fn): fcntl.fcntl(-1, fcntl.F_SETFL, os.O_NONBLOCK)
self.fn = fn with self.assertRaises(ValueError):
def fileno(self): fcntl.fcntl(BadFile(-1), fcntl.F_SETFL, os.O_NONBLOCK)
return self.fn with self.assertRaises(TypeError):
self.assertRaises(ValueError, fcntl.fcntl, -1, fcntl.F_SETFL, os.O_NONBLOCK) fcntl.fcntl('spam', fcntl.F_SETFL, os.O_NONBLOCK)
self.assertRaises(ValueError, fcntl.fcntl, F(-1), fcntl.F_SETFL, os.O_NONBLOCK) with self.assertRaises(TypeError):
self.assertRaises(TypeError, fcntl.fcntl, 'spam', fcntl.F_SETFL, os.O_NONBLOCK) fcntl.fcntl(BadFile('spam'), fcntl.F_SETFL, os.O_NONBLOCK)
self.assertRaises(TypeError, fcntl.fcntl, F('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 # Issue 15989
self.assertRaises(ValueError, fcntl.fcntl, _testcapi.INT_MAX + 1, with self.assertRaises(ValueError):
fcntl.F_SETFL, os.O_NONBLOCK) fcntl.fcntl(INT_MAX + 1, fcntl.F_SETFL, os.O_NONBLOCK)
self.assertRaises(ValueError, fcntl.fcntl, F(_testcapi.INT_MAX + 1), with self.assertRaises(ValueError):
fcntl.F_SETFL, os.O_NONBLOCK) fcntl.fcntl(BadFile(INT_MAX + 1), fcntl.F_SETFL, os.O_NONBLOCK)
self.assertRaises(ValueError, fcntl.fcntl, _testcapi.INT_MIN - 1, with self.assertRaises(ValueError):
fcntl.F_SETFL, os.O_NONBLOCK) fcntl.fcntl(INT_MIN - 1, fcntl.F_SETFL, os.O_NONBLOCK)
self.assertRaises(ValueError, fcntl.fcntl, F(_testcapi.INT_MIN - 1), with self.assertRaises(ValueError):
fcntl.F_SETFL, os.O_NONBLOCK) fcntl.fcntl(BadFile(INT_MIN - 1), fcntl.F_SETFL, os.O_NONBLOCK)
def test_fcntl_64_bit(self): def test_fcntl_64_bit(self):
# Issue #1309352: fcntl shouldn't fail when the third arg fits in a # Issue #1309352: fcntl shouldn't fail when the third arg fits in a
......
...@@ -10,10 +10,9 @@ from array import array ...@@ -10,10 +10,9 @@ from array import array
from weakref import proxy from weakref import proxy
from functools import wraps from functools import wraps
from UserList import UserList from UserList import UserList
import _testcapi
from test.test_support import TESTFN, check_warnings, run_unittest, make_bad_fd 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 test.script_helper import run_python
from _io import FileIO as _FileIO from _io import FileIO as _FileIO
...@@ -359,7 +358,11 @@ class OtherFileTests(unittest.TestCase): ...@@ -359,7 +358,11 @@ class OtherFileTests(unittest.TestCase):
if sys.platform == 'win32': if sys.platform == 'win32':
import msvcrt import msvcrt
self.assertRaises(IOError, msvcrt.get_osfhandle, make_bad_fd()) self.assertRaises(IOError, msvcrt.get_osfhandle, make_bad_fd())
@cpython_only
def testInvalidFd_overflow(self):
# Issue 15989 # Issue 15989
import _testcapi
self.assertRaises(TypeError, _FileIO, _testcapi.INT_MAX + 1) self.assertRaises(TypeError, _FileIO, _testcapi.INT_MAX + 1)
self.assertRaises(TypeError, _FileIO, _testcapi.INT_MIN - 1) self.assertRaises(TypeError, _FileIO, _testcapi.INT_MIN - 1)
......
...@@ -303,22 +303,32 @@ def test_main(): ...@@ -303,22 +303,32 @@ def test_main():
test_support.run_unittest(FormatTest) test_support.run_unittest(FormatTest)
def test_precision(self): def test_precision(self):
INT_MAX = 2147483647
f = 1.2 f = 1.2
self.assertEqual(format(f, ".0f"), "1") self.assertEqual(format(f, ".0f"), "1")
self.assertEqual(format(f, ".3f"), "1.200") self.assertEqual(format(f, ".3f"), "1.200")
with self.assertRaises(ValueError) as cm: 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") self.assertEqual(str(cm.exception), "precision too big")
c = complex(f) c = complex(f)
self.assertEqual(format(f, ".0f"), "1") self.assertEqual(format(c, ".0f"), "1+0j")
self.assertEqual(format(f, ".3f"), "1.200") self.assertEqual(format(c, ".3f"), "1.200+0.000j")
with self.assertRaises(ValueError) as cm: with self.assertRaises(ValueError) as cm:
format(f, ".%sf" % (INT_MAX + 1)) format(c, ".%sf" % (sys.maxsize + 1))
self.assertEqual(str(cm.exception), "precision too big") 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))
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
import unittest import unittest
from test import test_support 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 from _testcapi import getargs_keywords
import warnings import warnings
......
...@@ -3,14 +3,13 @@ ...@@ -3,14 +3,13 @@
import os import os
import random import random
import select import select
from _testcapi import USHRT_MAX, INT_MAX, UINT_MAX
try: try:
import threading import threading
except ImportError: except ImportError:
threading = None threading = None
import time import time
import unittest 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: try:
select.poll select.poll
...@@ -161,8 +160,18 @@ class PollTests(unittest.TestCase): ...@@ -161,8 +160,18 @@ class PollTests(unittest.TestCase):
# Issues #15989, #17919 # Issues #15989, #17919
self.assertRaises(OverflowError, pollster.register, 0, -1) self.assertRaises(OverflowError, pollster.register, 0, -1)
self.assertRaises(OverflowError, pollster.register, 0, USHRT_MAX + 1) self.assertRaises(OverflowError, pollster.register, 0, 1 << 64)
self.assertRaises(OverflowError, pollster.modify, 1, -1) 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, 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, INT_MAX + 1)
self.assertRaises(OverflowError, pollster.poll, UINT_MAX + 1) self.assertRaises(OverflowError, pollster.poll, UINT_MAX + 1)
......
...@@ -4,7 +4,6 @@ from test import test_support ...@@ -4,7 +4,6 @@ from test import test_support
import errno import errno
import socket import socket
import select import select
import _testcapi
import time import time
import traceback import traceback
import Queue import Queue
...@@ -711,7 +710,10 @@ class GeneralModuleTests(unittest.TestCase): ...@@ -711,7 +710,10 @@ class GeneralModuleTests(unittest.TestCase):
srv.listen(backlog) srv.listen(backlog)
srv.close() srv.close()
@test_support.cpython_only
def test_listen_backlog_overflow(self):
# Issue 15989 # Issue 15989
import _testcapi
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv.bind((HOST, 0)) srv.bind((HOST, 0))
self.assertRaises(OverflowError, srv.listen, _testcapi.INT_MAX + 1) self.assertRaises(OverflowError, srv.listen, _testcapi.INT_MAX + 1)
...@@ -817,6 +819,14 @@ class BasicTCPTest(SocketConnectedTest): ...@@ -817,6 +819,14 @@ class BasicTCPTest(SocketConnectedTest):
self.done.wait() self.done.wait()
def _testShutdown(self): 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) self.serv_conn.send(MSG)
# Issue 15989 # Issue 15989
self.assertRaises(OverflowError, self.serv_conn.shutdown, self.assertRaises(OverflowError, self.serv_conn.shutdown,
...@@ -911,13 +921,22 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest): ...@@ -911,13 +921,22 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest):
pass pass
end = time.time() end = time.time()
self.assertTrue((end - start) < 1.0, "Error setting non-blocking mode.") self.assertTrue((end - start) < 1.0, "Error setting non-blocking mode.")
def _testSetBlocking(self):
pass
@test_support.cpython_only
def testSetBlocking_overflow(self):
# Issue 15989 # Issue 15989
if _testcapi.UINT_MAX < _testcapi.ULONG_MAX: 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.serv.setblocking(_testcapi.UINT_MAX + 1)
self.assertIsNone(self.serv.gettimeout()) self.assertIsNone(self.serv.gettimeout())
def _testSetBlocking(self): _testSetBlocking_overflow = test_support.cpython_only(_testSetBlocking)
pass
def testAccept(self): def testAccept(self):
# Testing non-blocking accept # Testing non-blocking accept
......
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, \ from _testcapi import _test_structmembersType, \
CHAR_MAX, CHAR_MIN, UCHAR_MAX, \ CHAR_MAX, CHAR_MIN, UCHAR_MAX, \
SHRT_MAX, SHRT_MIN, USHRT_MAX, \ SHRT_MAX, SHRT_MIN, USHRT_MAX, \
...@@ -5,9 +10,6 @@ from _testcapi import _test_structmembersType, \ ...@@ -5,9 +10,6 @@ from _testcapi import _test_structmembersType, \
LONG_MAX, LONG_MIN, ULONG_MAX, \ LONG_MAX, LONG_MIN, ULONG_MAX, \
LLONG_MAX, LLONG_MIN, ULLONG_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, ts=_test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8,
9.99999, 10.1010101010, "hi") 9.99999, 10.1010101010, "hi")
......
...@@ -19,7 +19,6 @@ import UserDict ...@@ -19,7 +19,6 @@ import UserDict
import re import re
import time import time
import struct import struct
import _testcapi
import sysconfig import sysconfig
try: try:
import thread import thread
...@@ -1002,6 +1001,7 @@ _TPFLAGS_HAVE_GC = 1<<14 ...@@ -1002,6 +1001,7 @@ _TPFLAGS_HAVE_GC = 1<<14
_TPFLAGS_HEAPTYPE = 1<<9 _TPFLAGS_HEAPTYPE = 1<<9
def check_sizeof(test, o, size): def check_sizeof(test, o, size):
import _testcapi
result = sys.getsizeof(o) result = sys.getsizeof(o)
# add GC header size # add GC header size
if ((type(o) == type) and (o.__flags__ & _TPFLAGS_HEAPTYPE) or\ if ((type(o) == type) and (o.__flags__ & _TPFLAGS_HEAPTYPE) or\
......
...@@ -489,6 +489,7 @@ class SysModuleTest(unittest.TestCase): ...@@ -489,6 +489,7 @@ class SysModuleTest(unittest.TestCase):
p.wait() p.wait()
self.assertIn(executable, ["''", repr(sys.executable)]) self.assertIn(executable, ["''", repr(sys.executable)])
@test.test_support.cpython_only
class SizeofTest(unittest.TestCase): class SizeofTest(unittest.TestCase):
def setUp(self): def setUp(self):
......
import unittest import unittest
import sys import sys
import os import os
import _testcapi
from test import test_support from test import test_support
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
...@@ -11,6 +10,11 @@ _tkinter = test_support.import_module('_tkinter') ...@@ -11,6 +10,11 @@ _tkinter = test_support.import_module('_tkinter')
from Tkinter import Tcl from Tkinter import Tcl
from _tkinter import TclError 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('.') tcl_version = _tkinter.TCL_VERSION.split('.')
try: try:
for i in range(len(tcl_version)): for i in range(len(tcl_version)):
...@@ -523,10 +527,9 @@ class BigmemTclTest(unittest.TestCase): ...@@ -523,10 +527,9 @@ class BigmemTclTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.interp = Tcl() self.interp = Tcl()
@unittest.skipUnless(_testcapi.INT_MAX < _testcapi.PY_SSIZE_T_MAX, @test_support.cpython_only
"needs UINT_MAX < SIZE_MAX") @unittest.skipUnless(INT_MAX < PY_SSIZE_T_MAX, "needs UINT_MAX < SIZE_MAX")
@test_support.precisionbigmemtest(size=_testcapi.INT_MAX + 1, memuse=5, @test_support.precisionbigmemtest(size=INT_MAX + 1, memuse=5, dry_run=False)
dry_run=False)
def test_huge_string(self, size): def test_huge_string(self, size):
value = ' ' * size value = ' ' * size
self.assertRaises(OverflowError, self.interp.call, 'set', '_', value) self.assertRaises(OverflowError, self.interp.call, 'set', '_', value)
......
# Very rudimentary test of threading module # Very rudimentary test of threading module
import test.test_support 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 from test.script_helper import assert_python_ok
import random import random
...@@ -724,6 +724,7 @@ class ThreadJoinOnShutdown(BaseTestCase): ...@@ -724,6 +724,7 @@ class ThreadJoinOnShutdown(BaseTestCase):
for t in threads: for t in threads:
t.join() t.join()
@cpython_only
@unittest.skipIf(_testcapi is None, "need _testcapi module") @unittest.skipIf(_testcapi is None, "need _testcapi module")
def test_frame_tstate_tracing(self): def test_frame_tstate_tracing(self):
# Issue #14432: Crash when a generator is created in a C thread that is # Issue #14432: Crash when a generator is created in a C thread that is
......
"""Test cases for traceback module""" """Test cases for traceback module"""
from _testcapi import traceback_print
from StringIO import StringIO from StringIO import StringIO
import sys import sys
import unittest import unittest
from imp import reload 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 import traceback
...@@ -181,7 +180,9 @@ def test(): ...@@ -181,7 +180,9 @@ def test():
class TracebackFormatTests(unittest.TestCase): class TracebackFormatTests(unittest.TestCase):
@cpython_only
def test_traceback_format(self): def test_traceback_format(self):
from _testcapi import traceback_print
try: try:
raise KeyError('blah') raise KeyError('blah')
except KeyError: except KeyError:
......
...@@ -9,10 +9,14 @@ Modified for Python 2.0 by Fredrik Lundh (fredrik@pythonware.com) ...@@ -9,10 +9,14 @@ Modified for Python 2.0 by Fredrik Lundh (fredrik@pythonware.com)
import unittest import unittest
import sys import sys
import _testcapi
from test import test_support 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): class UnicodeNamesTest(unittest.TestCase):
def checkletter(self, name, code): def checkletter(self, name, code):
...@@ -139,11 +143,10 @@ class UnicodeNamesTest(unittest.TestCase): ...@@ -139,11 +143,10 @@ class UnicodeNamesTest(unittest.TestCase):
unicode, "\\NSPACE", 'unicode-escape', 'strict' unicode, "\\NSPACE", 'unicode-escape', 'strict'
) )
@unittest.skipUnless(_testcapi.INT_MAX < _testcapi.PY_SSIZE_T_MAX, @test_support.cpython_only
"needs UINT_MAX < SIZE_MAX") @unittest.skipUnless(INT_MAX < PY_SSIZE_T_MAX, "needs UINT_MAX < SIZE_MAX")
@unittest.skipUnless(_testcapi.UINT_MAX < sys.maxint, @unittest.skipUnless(UINT_MAX < sys.maxint, "needs UINT_MAX < sys.maxint")
"needs UINT_MAX < sys.maxint") @test_support.bigmemtest(minsize=UINT_MAX + 1,
@test_support.bigmemtest(minsize=_testcapi.UINT_MAX + 1,
memuse=2 + 4 // len(u'\U00010000')) memuse=2 + 4 // len(u'\U00010000'))
def test_issue16335(self, size): def test_issue16335(self, size):
func = self.test_issue16335 func = self.test_issue16335
...@@ -151,9 +154,8 @@ class UnicodeNamesTest(unittest.TestCase): ...@@ -151,9 +154,8 @@ class UnicodeNamesTest(unittest.TestCase):
raise unittest.SkipTest("not enough memory: %.1fG minimum needed" % raise unittest.SkipTest("not enough memory: %.1fG minimum needed" %
(func.minsize * func.memuse / float(1024**3),)) (func.minsize * func.memuse / float(1024**3),))
# very very long bogus character name # very very long bogus character name
x = b'\\N{SPACE' + b'x' * int(_testcapi.UINT_MAX + 1) + b'}' x = b'\\N{SPACE' + b'x' * int(UINT_MAX + 1) + b'}'
self.assertEqual(len(x), len(b'\\N{SPACE}') + self.assertEqual(len(x), len(b'\\N{SPACE}') + (UINT_MAX + 1))
(_testcapi.UINT_MAX + 1))
self.assertRaisesRegexp(UnicodeError, self.assertRaisesRegexp(UnicodeError,
'unknown Unicode character name', 'unknown Unicode character name',
x.decode, 'unicode-escape' x.decode, 'unicode-escape'
......
...@@ -644,8 +644,13 @@ class UnicodeTest( ...@@ -644,8 +644,13 @@ class UnicodeTest(
return u'\u1234' return u'\u1234'
self.assertEqual('%s' % Wrapper(), u'\u1234') self.assertEqual('%s' % Wrapper(), u'\u1234')
@test_support.cpython_only
def test_formatting_huge_precision(self): 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_c_limits(self):
from _testcapi import INT_MAX from _testcapi import INT_MAX
format_string = u"%.{}f".format(INT_MAX + 1) format_string = u"%.{}f".format(INT_MAX + 1)
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
...@@ -1633,6 +1638,7 @@ class UnicodeTest( ...@@ -1633,6 +1638,7 @@ class UnicodeTest(
self.assertEqual("%s" % u, u'__unicode__ overridden') self.assertEqual("%s" % u, u'__unicode__ overridden')
self.assertEqual("{}".format(u), '__unicode__ overridden') self.assertEqual("{}".format(u), '__unicode__ overridden')
@test_support.cpython_only
def test_encode_decimal(self): def test_encode_decimal(self):
from _testcapi import unicode_encodedecimal from _testcapi import unicode_encodedecimal
self.assertEqual(unicode_encodedecimal(u'123'), self.assertEqual(unicode_encodedecimal(u'123'),
...@@ -1658,6 +1664,7 @@ class UnicodeTest( ...@@ -1658,6 +1664,7 @@ class UnicodeTest(
self.assertEqual(unicode_encodedecimal(u"123\u20ac\u0660", "replace"), self.assertEqual(unicode_encodedecimal(u"123\u20ac\u0660", "replace"),
b'123?0') b'123?0')
@test_support.cpython_only
def test_encode_decimal_with_surrogates(self): def test_encode_decimal_with_surrogates(self):
from _testcapi import unicode_encodedecimal from _testcapi import unicode_encodedecimal
tests = [(u'\U0001f49d', '&#128157;'), tests = [(u'\U0001f49d', '&#128157;'),
......
...@@ -224,6 +224,8 @@ IDLE ...@@ -224,6 +224,8 @@ IDLE
Tests Tests
----- -----
- Issue #20532: Tests which use _testcapi now are marked as CPython only.
- Issue #19920: Added tests for TarFile.list(). Based on patch by Vajrasky Kok. - Issue #19920: Added tests for TarFile.list(). Based on patch by Vajrasky Kok.
- Issue #19990: Added tests for the imghdr module. Based on patch by - Issue #19990: Added tests for the imghdr module. Based on patch by
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment