Skip to content

Commit

Permalink
pythongh-116417: Move limited C API abstract.c tests to _testlimitedc…
Browse files Browse the repository at this point in the history
…api (python#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.
  • Loading branch information
vstinner authored and adorilson committed Mar 25, 2024
1 parent 90b0219 commit d924301
Show file tree
Hide file tree
Showing 13 changed files with 774 additions and 722 deletions.
16 changes: 8 additions & 8 deletions Lib/test/test_bytes.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit d924301

Please sign in to comment.