mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-116417: Move limited C API abstract.c tests to _testlimitedcapi (#116986)
Split abstract.c and float.c tests of _testcapi into two parts: limited C API tests in _testlimitedcapi and non-limited C API tests in _testcapi. Update test_bytes and test_class.
This commit is contained in:
parent
b1bc37597f
commit
039d20ae54
13 changed files with 780 additions and 728 deletions
|
|
@ -991,13 +991,13 @@ def test_translate(self):
|
|||
self.assertEqual(c, b'hllo')
|
||||
|
||||
def test_sq_item(self):
|
||||
_testcapi = import_helper.import_module('_testcapi')
|
||||
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
|
||||
obj = self.type2test((42,))
|
||||
with self.assertRaises(IndexError):
|
||||
_testcapi.sequence_getitem(obj, -2)
|
||||
_testlimitedcapi.sequence_getitem(obj, -2)
|
||||
with self.assertRaises(IndexError):
|
||||
_testcapi.sequence_getitem(obj, 1)
|
||||
self.assertEqual(_testcapi.sequence_getitem(obj, 0), 42)
|
||||
_testlimitedcapi.sequence_getitem(obj, 1)
|
||||
self.assertEqual(_testlimitedcapi.sequence_getitem(obj, 0), 42)
|
||||
|
||||
|
||||
class BytesTest(BaseBytesTest, unittest.TestCase):
|
||||
|
|
@ -1256,7 +1256,7 @@ class SubBytes(bytes):
|
|||
class ByteArrayTest(BaseBytesTest, unittest.TestCase):
|
||||
type2test = bytearray
|
||||
|
||||
_testcapi = import_helper.import_module('_testcapi')
|
||||
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
|
||||
|
||||
def test_getitem_error(self):
|
||||
b = bytearray(b'python')
|
||||
|
|
@ -1354,7 +1354,7 @@ def setitem_as_mapping(b, i, val):
|
|||
b[i] = val
|
||||
|
||||
def setitem_as_sequence(b, i, val):
|
||||
self._testcapi.sequence_setitem(b, i, val)
|
||||
self._testlimitedcapi.sequence_setitem(b, i, val)
|
||||
|
||||
def do_tests(setitem):
|
||||
b = bytearray([1, 2, 3])
|
||||
|
|
@ -1401,7 +1401,7 @@ def del_as_mapping(b, i):
|
|||
del b[i]
|
||||
|
||||
def del_as_sequence(b, i):
|
||||
self._testcapi.sequence_delitem(b, i)
|
||||
self._testlimitedcapi.sequence_delitem(b, i)
|
||||
|
||||
def do_tests(delete):
|
||||
b = bytearray(range(10))
|
||||
|
|
@ -1810,7 +1810,7 @@ def __index__(self):
|
|||
with self.subTest("tp_as_sequence"):
|
||||
b = bytearray(b'Now you see me...')
|
||||
with self.assertRaises(IndexError):
|
||||
self._testcapi.sequence_setitem(b, 0, Boom())
|
||||
self._testlimitedcapi.sequence_setitem(b, 0, Boom())
|
||||
|
||||
|
||||
class AssortedBytesTest(unittest.TestCase):
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
from test.support import import_helper
|
||||
|
||||
_testcapi = import_helper.import_module('_testcapi')
|
||||
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
|
||||
from _testcapi import PY_SSIZE_T_MIN, PY_SSIZE_T_MAX
|
||||
|
||||
NULL = None
|
||||
|
|
@ -74,7 +75,7 @@ def assertTypedEqual(self, actual, expected):
|
|||
|
||||
def test_object_str(self):
|
||||
# Test PyObject_Str()
|
||||
object_str = _testcapi.object_str
|
||||
object_str = _testlimitedcapi.object_str
|
||||
self.assertTypedEqual(object_str(''), '')
|
||||
self.assertTypedEqual(object_str('abc'), 'abc')
|
||||
self.assertTypedEqual(object_str('\U0001f40d'), '\U0001f40d')
|
||||
|
|
@ -87,7 +88,7 @@ def test_object_str(self):
|
|||
|
||||
def test_object_repr(self):
|
||||
# Test PyObject_Repr()
|
||||
object_repr = _testcapi.object_repr
|
||||
object_repr = _testlimitedcapi.object_repr
|
||||
self.assertTypedEqual(object_repr(''), "''")
|
||||
self.assertTypedEqual(object_repr('abc'), "'abc'")
|
||||
self.assertTypedEqual(object_repr('\U0001f40d'), "'\U0001f40d'")
|
||||
|
|
@ -100,7 +101,7 @@ def test_object_repr(self):
|
|||
|
||||
def test_object_ascii(self):
|
||||
# Test PyObject_ASCII()
|
||||
object_ascii = _testcapi.object_ascii
|
||||
object_ascii = _testlimitedcapi.object_ascii
|
||||
self.assertTypedEqual(object_ascii(''), "''")
|
||||
self.assertTypedEqual(object_ascii('abc'), "'abc'")
|
||||
self.assertTypedEqual(object_ascii('\U0001f40d'), r"'\U0001f40d'")
|
||||
|
|
@ -113,7 +114,7 @@ def test_object_ascii(self):
|
|||
|
||||
def test_object_bytes(self):
|
||||
# Test PyObject_Bytes()
|
||||
object_bytes = _testcapi.object_bytes
|
||||
object_bytes = _testlimitedcapi.object_bytes
|
||||
self.assertTypedEqual(object_bytes(b''), b'')
|
||||
self.assertTypedEqual(object_bytes(b'abc'), b'abc')
|
||||
self.assertTypedEqual(object_bytes(BytesSubclass(b'abc')), b'abc')
|
||||
|
|
@ -132,7 +133,7 @@ def test_object_bytes(self):
|
|||
self.assertTypedEqual(object_bytes(NULL), b'<NULL>')
|
||||
|
||||
def test_object_getattr(self):
|
||||
xgetattr = _testcapi.object_getattr
|
||||
xgetattr = _testlimitedcapi.object_getattr
|
||||
obj = TestObject()
|
||||
obj.a = 11
|
||||
setattr(obj, '\U0001f40d', 22)
|
||||
|
|
@ -146,7 +147,7 @@ def test_object_getattr(self):
|
|||
# CRASHES xgetattr(NULL, 'a')
|
||||
|
||||
def test_object_getattrstring(self):
|
||||
getattrstring = _testcapi.object_getattrstring
|
||||
getattrstring = _testlimitedcapi.object_getattrstring
|
||||
obj = TestObject()
|
||||
obj.a = 11
|
||||
setattr(obj, '\U0001f40d', 22)
|
||||
|
|
@ -188,7 +189,7 @@ def test_object_getoptionalattrstring(self):
|
|||
# CRASHES getoptionalattrstring(NULL, b'a')
|
||||
|
||||
def test_object_hasattr(self):
|
||||
xhasattr = _testcapi.object_hasattr
|
||||
xhasattr = _testlimitedcapi.object_hasattr
|
||||
obj = TestObject()
|
||||
obj.a = 1
|
||||
setattr(obj, '\U0001f40d', 2)
|
||||
|
|
@ -212,7 +213,7 @@ def test_object_hasattr(self):
|
|||
# CRASHES xhasattr(NULL, 'a')
|
||||
|
||||
def test_object_hasattrstring(self):
|
||||
hasattrstring = _testcapi.object_hasattrstring
|
||||
hasattrstring = _testlimitedcapi.object_hasattrstring
|
||||
obj = TestObject()
|
||||
obj.a = 1
|
||||
setattr(obj, '\U0001f40d', 2)
|
||||
|
|
@ -264,7 +265,7 @@ def test_object_hasattrstringwitherror(self):
|
|||
# CRASHES hasattrstring(NULL, b'a')
|
||||
|
||||
def test_object_setattr(self):
|
||||
xsetattr = _testcapi.object_setattr
|
||||
xsetattr = _testlimitedcapi.object_setattr
|
||||
obj = TestObject()
|
||||
xsetattr(obj, 'a', 5)
|
||||
self.assertEqual(obj.a, 5)
|
||||
|
|
@ -284,7 +285,7 @@ def test_object_setattr(self):
|
|||
# CRASHES xsetattr(NULL, 'a', 5)
|
||||
|
||||
def test_object_setattrstring(self):
|
||||
setattrstring = _testcapi.object_setattrstring
|
||||
setattrstring = _testlimitedcapi.object_setattrstring
|
||||
obj = TestObject()
|
||||
setattrstring(obj, b'a', 5)
|
||||
self.assertEqual(obj.a, 5)
|
||||
|
|
@ -305,7 +306,7 @@ def test_object_setattrstring(self):
|
|||
# CRASHES setattrstring(NULL, b'a', 5)
|
||||
|
||||
def test_object_delattr(self):
|
||||
xdelattr = _testcapi.object_delattr
|
||||
xdelattr = _testlimitedcapi.object_delattr
|
||||
obj = TestObject()
|
||||
obj.a = 1
|
||||
setattr(obj, '\U0001f40d', 2)
|
||||
|
|
@ -322,7 +323,7 @@ def test_object_delattr(self):
|
|||
# CRASHES xdelattr(NULL, 'a')
|
||||
|
||||
def test_object_delattrstring(self):
|
||||
delattrstring = _testcapi.object_delattrstring
|
||||
delattrstring = _testlimitedcapi.object_delattrstring
|
||||
obj = TestObject()
|
||||
obj.a = 1
|
||||
setattr(obj, '\U0001f40d', 2)
|
||||
|
|
@ -340,7 +341,7 @@ def test_object_delattrstring(self):
|
|||
|
||||
|
||||
def test_mapping_check(self):
|
||||
check = _testcapi.mapping_check
|
||||
check = _testlimitedcapi.mapping_check
|
||||
self.assertTrue(check({1: 2}))
|
||||
self.assertTrue(check([1, 2]))
|
||||
self.assertTrue(check((1, 2)))
|
||||
|
|
@ -351,7 +352,7 @@ def test_mapping_check(self):
|
|||
self.assertFalse(check(NULL))
|
||||
|
||||
def test_mapping_size(self):
|
||||
for size in _testcapi.mapping_size, _testcapi.mapping_length:
|
||||
for size in _testlimitedcapi.mapping_size, _testlimitedcapi.mapping_length:
|
||||
self.assertEqual(size({1: 2}), 1)
|
||||
self.assertEqual(size([1, 2]), 2)
|
||||
self.assertEqual(size((1, 2)), 2)
|
||||
|
|
@ -363,7 +364,7 @@ def test_mapping_size(self):
|
|||
self.assertRaises(SystemError, size, NULL)
|
||||
|
||||
def test_object_getitem(self):
|
||||
getitem = _testcapi.object_getitem
|
||||
getitem = _testlimitedcapi.object_getitem
|
||||
dct = {'a': 1, '\U0001f40d': 2}
|
||||
self.assertEqual(getitem(dct, 'a'), 1)
|
||||
self.assertRaises(KeyError, getitem, dct, 'b')
|
||||
|
|
@ -383,7 +384,7 @@ def test_object_getitem(self):
|
|||
self.assertRaises(SystemError, getitem, NULL, 'a')
|
||||
|
||||
def test_mapping_getitemstring(self):
|
||||
getitemstring = _testcapi.mapping_getitemstring
|
||||
getitemstring = _testlimitedcapi.mapping_getitemstring
|
||||
dct = {'a': 1, '\U0001f40d': 2}
|
||||
self.assertEqual(getitemstring(dct, b'a'), 1)
|
||||
self.assertRaises(KeyError, getitemstring, dct, b'b')
|
||||
|
|
@ -437,7 +438,7 @@ def test_mapping_getoptionalitemstring(self):
|
|||
# CRASHES getitemstring(NULL, b'a')
|
||||
|
||||
def test_mapping_haskey(self):
|
||||
haskey = _testcapi.mapping_haskey
|
||||
haskey = _testlimitedcapi.mapping_haskey
|
||||
dct = {'a': 1, '\U0001f40d': 2}
|
||||
self.assertTrue(haskey(dct, 'a'))
|
||||
self.assertFalse(haskey(dct, 'b'))
|
||||
|
|
@ -486,7 +487,7 @@ def test_mapping_haskey(self):
|
|||
'null argument to internal routine')
|
||||
|
||||
def test_mapping_haskeystring(self):
|
||||
haskeystring = _testcapi.mapping_haskeystring
|
||||
haskeystring = _testlimitedcapi.mapping_haskeystring
|
||||
dct = {'a': 1, '\U0001f40d': 2}
|
||||
self.assertTrue(haskeystring(dct, b'a'))
|
||||
self.assertFalse(haskeystring(dct, b'b'))
|
||||
|
|
@ -527,7 +528,7 @@ def test_mapping_haskeystring(self):
|
|||
"null argument to internal routine")
|
||||
|
||||
def test_mapping_haskeywitherror(self):
|
||||
haskey = _testcapi.mapping_haskeywitherror
|
||||
haskey = _testlimitedcapi.mapping_haskeywitherror
|
||||
dct = {'a': 1, '\U0001f40d': 2}
|
||||
self.assertTrue(haskey(dct, 'a'))
|
||||
self.assertFalse(haskey(dct, 'b'))
|
||||
|
|
@ -548,7 +549,7 @@ def test_mapping_haskeywitherror(self):
|
|||
# CRASHES haskey(NULL, 'a'))
|
||||
|
||||
def test_mapping_haskeystringwitherror(self):
|
||||
haskeystring = _testcapi.mapping_haskeystringwitherror
|
||||
haskeystring = _testlimitedcapi.mapping_haskeystringwitherror
|
||||
dct = {'a': 1, '\U0001f40d': 2}
|
||||
self.assertTrue(haskeystring(dct, b'a'))
|
||||
self.assertFalse(haskeystring(dct, b'b'))
|
||||
|
|
@ -565,7 +566,7 @@ def test_mapping_haskeystringwitherror(self):
|
|||
# CRASHES haskeystring(NULL, b'a')
|
||||
|
||||
def test_object_setitem(self):
|
||||
setitem = _testcapi.object_setitem
|
||||
setitem = _testlimitedcapi.object_setitem
|
||||
dct = {}
|
||||
setitem(dct, 'a', 5)
|
||||
self.assertEqual(dct, {'a': 5})
|
||||
|
|
@ -591,7 +592,7 @@ def test_object_setitem(self):
|
|||
self.assertRaises(SystemError, setitem, NULL, 'a', 5)
|
||||
|
||||
def test_mapping_setitemstring(self):
|
||||
setitemstring = _testcapi.mapping_setitemstring
|
||||
setitemstring = _testlimitedcapi.mapping_setitemstring
|
||||
dct = {}
|
||||
setitemstring(dct, b'a', 5)
|
||||
self.assertEqual(dct, {'a': 5})
|
||||
|
|
@ -611,7 +612,7 @@ def test_mapping_setitemstring(self):
|
|||
self.assertRaises(SystemError, setitemstring, NULL, b'a', 5)
|
||||
|
||||
def test_object_delitem(self):
|
||||
for delitem in _testcapi.object_delitem, _testcapi.mapping_delitem:
|
||||
for delitem in _testlimitedcapi.object_delitem, _testlimitedcapi.mapping_delitem:
|
||||
dct = {'a': 1, 'c': 2, '\U0001f40d': 3}
|
||||
delitem(dct, 'a')
|
||||
self.assertEqual(dct, {'c': 2, '\U0001f40d': 3})
|
||||
|
|
@ -637,7 +638,7 @@ def test_object_delitem(self):
|
|||
self.assertRaises(SystemError, delitem, NULL, 'a')
|
||||
|
||||
def test_mapping_delitemstring(self):
|
||||
delitemstring = _testcapi.mapping_delitemstring
|
||||
delitemstring = _testlimitedcapi.mapping_delitemstring
|
||||
dct = {'a': 1, 'c': 2, '\U0001f40d': 3}
|
||||
delitemstring(dct, b'a')
|
||||
self.assertEqual(dct, {'c': 2, '\U0001f40d': 3})
|
||||
|
|
@ -677,23 +678,23 @@ def items(self):
|
|||
for mapping in [{}, OrderedDict(), Mapping1(), Mapping2(),
|
||||
dict_obj, OrderedDict(dict_obj),
|
||||
Mapping1(dict_obj), Mapping2(dict_obj)]:
|
||||
self.assertListEqual(_testcapi.mapping_keys(mapping),
|
||||
self.assertListEqual(_testlimitedcapi.mapping_keys(mapping),
|
||||
list(mapping.keys()))
|
||||
self.assertListEqual(_testcapi.mapping_values(mapping),
|
||||
self.assertListEqual(_testlimitedcapi.mapping_values(mapping),
|
||||
list(mapping.values()))
|
||||
self.assertListEqual(_testcapi.mapping_items(mapping),
|
||||
self.assertListEqual(_testlimitedcapi.mapping_items(mapping),
|
||||
list(mapping.items()))
|
||||
|
||||
def test_mapping_keys_valuesitems_bad_arg(self):
|
||||
self.assertRaises(AttributeError, _testcapi.mapping_keys, object())
|
||||
self.assertRaises(AttributeError, _testcapi.mapping_values, object())
|
||||
self.assertRaises(AttributeError, _testcapi.mapping_items, object())
|
||||
self.assertRaises(AttributeError, _testcapi.mapping_keys, [])
|
||||
self.assertRaises(AttributeError, _testcapi.mapping_values, [])
|
||||
self.assertRaises(AttributeError, _testcapi.mapping_items, [])
|
||||
self.assertRaises(SystemError, _testcapi.mapping_keys, NULL)
|
||||
self.assertRaises(SystemError, _testcapi.mapping_values, NULL)
|
||||
self.assertRaises(SystemError, _testcapi.mapping_items, NULL)
|
||||
self.assertRaises(AttributeError, _testlimitedcapi.mapping_keys, object())
|
||||
self.assertRaises(AttributeError, _testlimitedcapi.mapping_values, object())
|
||||
self.assertRaises(AttributeError, _testlimitedcapi.mapping_items, object())
|
||||
self.assertRaises(AttributeError, _testlimitedcapi.mapping_keys, [])
|
||||
self.assertRaises(AttributeError, _testlimitedcapi.mapping_values, [])
|
||||
self.assertRaises(AttributeError, _testlimitedcapi.mapping_items, [])
|
||||
self.assertRaises(SystemError, _testlimitedcapi.mapping_keys, NULL)
|
||||
self.assertRaises(SystemError, _testlimitedcapi.mapping_values, NULL)
|
||||
self.assertRaises(SystemError, _testlimitedcapi.mapping_items, NULL)
|
||||
|
||||
class BadMapping:
|
||||
def keys(self):
|
||||
|
|
@ -703,12 +704,12 @@ def values(self):
|
|||
def items(self):
|
||||
return None
|
||||
bad_mapping = BadMapping()
|
||||
self.assertRaises(TypeError, _testcapi.mapping_keys, bad_mapping)
|
||||
self.assertRaises(TypeError, _testcapi.mapping_values, bad_mapping)
|
||||
self.assertRaises(TypeError, _testcapi.mapping_items, bad_mapping)
|
||||
self.assertRaises(TypeError, _testlimitedcapi.mapping_keys, bad_mapping)
|
||||
self.assertRaises(TypeError, _testlimitedcapi.mapping_values, bad_mapping)
|
||||
self.assertRaises(TypeError, _testlimitedcapi.mapping_items, bad_mapping)
|
||||
|
||||
def test_sequence_check(self):
|
||||
check = _testcapi.sequence_check
|
||||
check = _testlimitedcapi.sequence_check
|
||||
self.assertFalse(check({1: 2}))
|
||||
self.assertTrue(check([1, 2]))
|
||||
self.assertTrue(check((1, 2)))
|
||||
|
|
@ -719,7 +720,7 @@ def test_sequence_check(self):
|
|||
# CRASHES check(NULL)
|
||||
|
||||
def test_sequence_size(self):
|
||||
for size in _testcapi.sequence_size, _testcapi.sequence_length:
|
||||
for size in _testlimitedcapi.sequence_size, _testlimitedcapi.sequence_length:
|
||||
self.assertEqual(size([1, 2]), 2)
|
||||
self.assertEqual(size((1, 2)), 2)
|
||||
self.assertEqual(size('abc'), 3)
|
||||
|
|
@ -731,7 +732,7 @@ def test_sequence_size(self):
|
|||
self.assertRaises(SystemError, size, NULL)
|
||||
|
||||
def test_sequence_getitem(self):
|
||||
getitem = _testcapi.sequence_getitem
|
||||
getitem = _testlimitedcapi.sequence_getitem
|
||||
lst = ['a', 'b', 'c']
|
||||
self.assertEqual(getitem(lst, 1), 'b')
|
||||
self.assertEqual(getitem(lst, -1), 'c')
|
||||
|
|
@ -744,7 +745,7 @@ def test_sequence_getitem(self):
|
|||
self.assertRaises(SystemError, getitem, NULL, 1)
|
||||
|
||||
def test_sequence_concat(self):
|
||||
concat = _testcapi.sequence_concat
|
||||
concat = _testlimitedcapi.sequence_concat
|
||||
self.assertEqual(concat(['a', 'b'], [1, 2]), ['a', 'b', 1, 2])
|
||||
self.assertEqual(concat(('a', 'b'), (1, 2)), ('a', 'b', 1, 2))
|
||||
|
||||
|
|
@ -757,7 +758,7 @@ def test_sequence_concat(self):
|
|||
self.assertRaises(SystemError, concat, NULL, [])
|
||||
|
||||
def test_sequence_repeat(self):
|
||||
repeat = _testcapi.sequence_repeat
|
||||
repeat = _testlimitedcapi.sequence_repeat
|
||||
self.assertEqual(repeat(['a', 'b'], 2), ['a', 'b', 'a', 'b'])
|
||||
self.assertEqual(repeat(('a', 'b'), 2), ('a', 'b', 'a', 'b'))
|
||||
self.assertEqual(repeat(['a', 'b'], 0), [])
|
||||
|
|
@ -771,7 +772,7 @@ def test_sequence_repeat(self):
|
|||
self.assertRaises(SystemError, repeat, NULL, 2)
|
||||
|
||||
def test_sequence_inplaceconcat(self):
|
||||
inplaceconcat = _testcapi.sequence_inplaceconcat
|
||||
inplaceconcat = _testlimitedcapi.sequence_inplaceconcat
|
||||
lst = ['a', 'b']
|
||||
res = inplaceconcat(lst, [1, 2])
|
||||
self.assertEqual(res, ['a', 'b', 1, 2])
|
||||
|
|
@ -790,7 +791,7 @@ def test_sequence_inplaceconcat(self):
|
|||
self.assertRaises(SystemError, inplaceconcat, NULL, [])
|
||||
|
||||
def test_sequence_inplacerepeat(self):
|
||||
inplacerepeat = _testcapi.sequence_inplacerepeat
|
||||
inplacerepeat = _testlimitedcapi.sequence_inplacerepeat
|
||||
lst = ['a', 'b']
|
||||
res = inplacerepeat(lst, 2)
|
||||
self.assertEqual(res, ['a', 'b', 'a', 'b'])
|
||||
|
|
@ -807,7 +808,7 @@ def test_sequence_inplacerepeat(self):
|
|||
self.assertRaises(SystemError, inplacerepeat, NULL, 2)
|
||||
|
||||
def test_sequence_setitem(self):
|
||||
setitem = _testcapi.sequence_setitem
|
||||
setitem = _testlimitedcapi.sequence_setitem
|
||||
lst = ['a', 'b', 'c']
|
||||
setitem(lst, 1, 'x')
|
||||
self.assertEqual(lst, ['a', 'x', 'c'])
|
||||
|
|
@ -825,7 +826,7 @@ def test_sequence_setitem(self):
|
|||
self.assertRaises(SystemError, setitem, NULL, 1, 'x')
|
||||
|
||||
def test_sequence_delitem(self):
|
||||
delitem = _testcapi.sequence_delitem
|
||||
delitem = _testlimitedcapi.sequence_delitem
|
||||
lst = ['a', 'b', 'c']
|
||||
delitem(lst, 1)
|
||||
self.assertEqual(lst, ['a', 'c'])
|
||||
|
|
@ -840,7 +841,7 @@ def test_sequence_delitem(self):
|
|||
self.assertRaises(SystemError, delitem, NULL, 1)
|
||||
|
||||
def test_sequence_setslice(self):
|
||||
setslice = _testcapi.sequence_setslice
|
||||
setslice = _testlimitedcapi.sequence_setslice
|
||||
|
||||
# Correct case:
|
||||
for start in [*range(-6, 7), PY_SSIZE_T_MIN, PY_SSIZE_T_MAX]:
|
||||
|
|
@ -882,7 +883,7 @@ def __setitem__(self, index, value):
|
|||
self.assertRaises(SystemError, setslice, NULL, 1, 3, 'xy')
|
||||
|
||||
def test_sequence_delslice(self):
|
||||
delslice = _testcapi.sequence_delslice
|
||||
delslice = _testlimitedcapi.sequence_delslice
|
||||
|
||||
# Correct case:
|
||||
for start in [*range(-6, 7), PY_SSIZE_T_MIN, PY_SSIZE_T_MAX]:
|
||||
|
|
@ -920,7 +921,7 @@ def __delitem__(self, index):
|
|||
self.assertEqual(mapping, {1: 'a', 2: 'b', 3: 'c'})
|
||||
|
||||
def test_sequence_count(self):
|
||||
count = _testcapi.sequence_count
|
||||
count = _testlimitedcapi.sequence_count
|
||||
|
||||
lst = ['a', 'b', 'a']
|
||||
self.assertEqual(count(lst, 'a'), 2)
|
||||
|
|
@ -935,7 +936,7 @@ def test_sequence_count(self):
|
|||
self.assertRaises(SystemError, count, NULL, 'a')
|
||||
|
||||
def test_sequence_contains(self):
|
||||
contains = _testcapi.sequence_contains
|
||||
contains = _testlimitedcapi.sequence_contains
|
||||
|
||||
lst = ['a', 'b', 'a']
|
||||
self.assertEqual(contains(lst, 'a'), 1)
|
||||
|
|
@ -954,7 +955,7 @@ def test_sequence_contains(self):
|
|||
# CRASHES contains(NULL, 'a')
|
||||
|
||||
def test_sequence_index(self):
|
||||
index = _testcapi.sequence_index
|
||||
index = _testlimitedcapi.sequence_index
|
||||
|
||||
lst = ['a', 'b', 'a']
|
||||
self.assertEqual(index(lst, 'a'), 0)
|
||||
|
|
@ -974,7 +975,7 @@ def test_sequence_index(self):
|
|||
self.assertRaises(SystemError, index, NULL, 'a')
|
||||
|
||||
def test_sequence_list(self):
|
||||
xlist = _testcapi.sequence_list
|
||||
xlist = _testlimitedcapi.sequence_list
|
||||
self.assertEqual(xlist(['a', 'b', 'c']), ['a', 'b', 'c'])
|
||||
self.assertEqual(xlist(('a', 'b', 'c')), ['a', 'b', 'c'])
|
||||
self.assertEqual(xlist(iter(['a', 'b', 'c'])), ['a', 'b', 'c'])
|
||||
|
|
@ -984,7 +985,7 @@ def test_sequence_list(self):
|
|||
self.assertRaises(SystemError, xlist, NULL)
|
||||
|
||||
def test_sequence_tuple(self):
|
||||
xtuple = _testcapi.sequence_tuple
|
||||
xtuple = _testlimitedcapi.sequence_tuple
|
||||
self.assertEqual(xtuple(['a', 'b', 'c']), ('a', 'b', 'c'))
|
||||
self.assertEqual(xtuple(('a', 'b', 'c')), ('a', 'b', 'c'))
|
||||
self.assertEqual(xtuple(iter(['a', 'b', 'c'])), ('a', 'b', 'c'))
|
||||
|
|
@ -994,7 +995,7 @@ def test_sequence_tuple(self):
|
|||
self.assertRaises(SystemError, xtuple, NULL)
|
||||
|
||||
def test_number_check(self):
|
||||
number_check = _testcapi.number_check
|
||||
number_check = _testlimitedcapi.number_check
|
||||
self.assertTrue(number_check(1 + 1j))
|
||||
self.assertTrue(number_check(1))
|
||||
self.assertTrue(number_check(0.5))
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
from test.support import import_helper
|
||||
|
||||
_testcapi = import_helper.import_module('_testcapi')
|
||||
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
|
||||
|
||||
NULL = None
|
||||
|
||||
|
|
@ -29,7 +30,7 @@
|
|||
class CAPIFloatTest(unittest.TestCase):
|
||||
def test_check(self):
|
||||
# Test PyFloat_Check()
|
||||
check = _testcapi.float_check
|
||||
check = _testlimitedcapi.float_check
|
||||
|
||||
self.assertTrue(check(4.25))
|
||||
self.assertTrue(check(FloatSubclass(4.25)))
|
||||
|
|
@ -41,7 +42,7 @@ def test_check(self):
|
|||
|
||||
def test_checkexact(self):
|
||||
# Test PyFloat_CheckExact()
|
||||
checkexact = _testcapi.float_checkexact
|
||||
checkexact = _testlimitedcapi.float_checkexact
|
||||
|
||||
self.assertTrue(checkexact(4.25))
|
||||
self.assertFalse(checkexact(FloatSubclass(4.25)))
|
||||
|
|
@ -53,7 +54,7 @@ def test_checkexact(self):
|
|||
|
||||
def test_fromstring(self):
|
||||
# Test PyFloat_FromString()
|
||||
fromstring = _testcapi.float_fromstring
|
||||
fromstring = _testlimitedcapi.float_fromstring
|
||||
|
||||
self.assertEqual(fromstring("4.25"), 4.25)
|
||||
self.assertEqual(fromstring(b"4.25"), 4.25)
|
||||
|
|
@ -72,13 +73,13 @@ def test_fromstring(self):
|
|||
|
||||
def test_fromdouble(self):
|
||||
# Test PyFloat_FromDouble()
|
||||
fromdouble = _testcapi.float_fromdouble
|
||||
fromdouble = _testlimitedcapi.float_fromdouble
|
||||
|
||||
self.assertEqual(fromdouble(4.25), 4.25)
|
||||
|
||||
def test_asdouble(self):
|
||||
# Test PyFloat_AsDouble()
|
||||
asdouble = _testcapi.float_asdouble
|
||||
asdouble = _testlimitedcapi.float_asdouble
|
||||
|
||||
class BadFloat3:
|
||||
def __float__(self):
|
||||
|
|
@ -109,19 +110,19 @@ def __float__(self):
|
|||
|
||||
def test_getinfo(self):
|
||||
# Test PyFloat_GetInfo()
|
||||
getinfo = _testcapi.float_getinfo
|
||||
getinfo = _testlimitedcapi.float_getinfo
|
||||
|
||||
self.assertEqual(getinfo(), sys.float_info)
|
||||
|
||||
def test_getmax(self):
|
||||
# Test PyFloat_GetMax()
|
||||
getmax = _testcapi.float_getmax
|
||||
getmax = _testlimitedcapi.float_getmax
|
||||
|
||||
self.assertEqual(getmax(), sys.float_info.max)
|
||||
|
||||
def test_getmin(self):
|
||||
# Test PyFloat_GetMax()
|
||||
getmin = _testcapi.float_getmin
|
||||
getmin = _testlimitedcapi.float_getmin
|
||||
|
||||
self.assertEqual(getmin(), sys.float_info.min)
|
||||
|
||||
|
|
|
|||
|
|
@ -448,15 +448,15 @@ def __delattr__(self, *args):
|
|||
def testHasAttrString(self):
|
||||
import sys
|
||||
from test.support import import_helper
|
||||
_testcapi = import_helper.import_module('_testcapi')
|
||||
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
|
||||
|
||||
class A:
|
||||
def __init__(self):
|
||||
self.attr = 1
|
||||
|
||||
a = A()
|
||||
self.assertEqual(_testcapi.object_hasattrstring(a, b"attr"), 1)
|
||||
self.assertEqual(_testcapi.object_hasattrstring(a, b"noattr"), 0)
|
||||
self.assertEqual(_testlimitedcapi.object_hasattrstring(a, b"attr"), 1)
|
||||
self.assertEqual(_testlimitedcapi.object_hasattrstring(a, b"noattr"), 0)
|
||||
self.assertIsNone(sys.exception())
|
||||
|
||||
def testDel(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue