summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-03-11 10:28:16 (GMT)
committerGitHub <noreply@github.com>2024-03-11 10:28:16 (GMT)
commit1cc02ca063f50b8c527fbdde9957b03c145c1575 (patch)
tree84cd4d2d13c8ca869749827d8f91d592e8a01ca2 /Lib
parentd8712fa0c75ad5ea56543903fa45674ab47cc647 (diff)
downloadcpython-1cc02ca063f50b8c527fbdde9957b03c145c1575.zip
cpython-1cc02ca063f50b8c527fbdde9957b03c145c1575.tar.gz
cpython-1cc02ca063f50b8c527fbdde9957b03c145c1575.tar.bz2
gh-116417: Move 4 limited C API test files to _testlimitedcapi (#116571)
Move the following files from Modules/_testcapi/ to Modules/_testlimitedcapi/: * bytearray.c * bytes.c * pyos.c * sys.c Changes: * Replace PyBytes_AS_STRING() with PyBytes_AsString(). * Replace PyBytes_GET_SIZE() with PyBytes_Size(). * Update related test_capi tests. * Copy Modules/_testcapi/util.h to Modules/_testlimitedcapi/util.h.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_capi/test_bytearray.py18
-rw-r--r--Lib/test/test_capi/test_bytes.py28
-rw-r--r--Lib/test/test_capi/test_sys.py16
3 files changed, 31 insertions, 31 deletions
diff --git a/Lib/test/test_capi/test_bytearray.py b/Lib/test/test_capi/test_bytearray.py
index 833122c..39099f6 100644
--- a/Lib/test/test_capi/test_bytearray.py
+++ b/Lib/test/test_capi/test_bytearray.py
@@ -1,7 +1,7 @@
import unittest
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
@@ -19,7 +19,7 @@ class BytesLike:
class CAPITest(unittest.TestCase):
def test_check(self):
# Test PyByteArray_Check()
- check = _testcapi.bytearray_check
+ check = _testlimitedcapi.bytearray_check
self.assertTrue(check(bytearray(b'abc')))
self.assertFalse(check(b'abc'))
self.assertTrue(check(ByteArraySubclass(b'abc')))
@@ -32,7 +32,7 @@ class CAPITest(unittest.TestCase):
def test_checkexact(self):
# Test PyByteArray_CheckExact()
- check = _testcapi.bytearray_checkexact
+ check = _testlimitedcapi.bytearray_checkexact
self.assertTrue(check(bytearray(b'abc')))
self.assertFalse(check(b'abc'))
self.assertFalse(check(ByteArraySubclass(b'abc')))
@@ -45,7 +45,7 @@ class CAPITest(unittest.TestCase):
def test_fromstringandsize(self):
# Test PyByteArray_FromStringAndSize()
- fromstringandsize = _testcapi.bytearray_fromstringandsize
+ fromstringandsize = _testlimitedcapi.bytearray_fromstringandsize
self.assertEqual(fromstringandsize(b'abc'), bytearray(b'abc'))
self.assertEqual(fromstringandsize(b'abc', 2), bytearray(b'ab'))
@@ -62,7 +62,7 @@ class CAPITest(unittest.TestCase):
def test_fromobject(self):
# Test PyByteArray_FromObject()
- fromobject = _testcapi.bytearray_fromobject
+ fromobject = _testlimitedcapi.bytearray_fromobject
self.assertEqual(fromobject(b'abc'), bytearray(b'abc'))
self.assertEqual(fromobject(bytearray(b'abc')), bytearray(b'abc'))
@@ -77,7 +77,7 @@ class CAPITest(unittest.TestCase):
def test_size(self):
# Test PyByteArray_Size()
- size = _testcapi.bytearray_size
+ size = _testlimitedcapi.bytearray_size
self.assertEqual(size(bytearray(b'abc')), 3)
self.assertEqual(size(ByteArraySubclass(b'abc')), 3)
@@ -88,7 +88,7 @@ class CAPITest(unittest.TestCase):
def test_asstring(self):
"""Test PyByteArray_AsString()"""
- asstring = _testcapi.bytearray_asstring
+ asstring = _testlimitedcapi.bytearray_asstring
self.assertEqual(asstring(bytearray(b'abc'), 4), b'abc\0')
self.assertEqual(asstring(ByteArraySubclass(b'abc'), 4), b'abc\0')
@@ -100,7 +100,7 @@ class CAPITest(unittest.TestCase):
def test_concat(self):
"""Test PyByteArray_Concat()"""
- concat = _testcapi.bytearray_concat
+ concat = _testlimitedcapi.bytearray_concat
ba = bytearray(b'abc')
self.assertEqual(concat(ba, b'def'), bytearray(b'abcdef'))
@@ -133,7 +133,7 @@ class CAPITest(unittest.TestCase):
def test_resize(self):
"""Test PyByteArray_Resize()"""
- resize = _testcapi.bytearray_resize
+ resize = _testlimitedcapi.bytearray_resize
ba = bytearray(b'abcdef')
self.assertEqual(resize(ba, 3), 0)
diff --git a/Lib/test/test_capi/test_bytes.py b/Lib/test/test_capi/test_bytes.py
index bb5d724..a2ba770 100644
--- a/Lib/test/test_capi/test_bytes.py
+++ b/Lib/test/test_capi/test_bytes.py
@@ -1,7 +1,7 @@
import unittest
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
@@ -19,7 +19,7 @@ class BytesLike:
class CAPITest(unittest.TestCase):
def test_check(self):
# Test PyBytes_Check()
- check = _testcapi.bytes_check
+ check = _testlimitedcapi.bytes_check
self.assertTrue(check(b'abc'))
self.assertFalse(check('abc'))
self.assertFalse(check(bytearray(b'abc')))
@@ -33,7 +33,7 @@ class CAPITest(unittest.TestCase):
def test_checkexact(self):
# Test PyBytes_CheckExact()
- check = _testcapi.bytes_checkexact
+ check = _testlimitedcapi.bytes_checkexact
self.assertTrue(check(b'abc'))
self.assertFalse(check('abc'))
self.assertFalse(check(bytearray(b'abc')))
@@ -47,7 +47,7 @@ class CAPITest(unittest.TestCase):
def test_fromstringandsize(self):
# Test PyBytes_FromStringAndSize()
- fromstringandsize = _testcapi.bytes_fromstringandsize
+ fromstringandsize = _testlimitedcapi.bytes_fromstringandsize
self.assertEqual(fromstringandsize(b'abc'), b'abc')
self.assertEqual(fromstringandsize(b'abc', 2), b'ab')
@@ -65,7 +65,7 @@ class CAPITest(unittest.TestCase):
def test_fromstring(self):
# Test PyBytes_FromString()
- fromstring = _testcapi.bytes_fromstring
+ fromstring = _testlimitedcapi.bytes_fromstring
self.assertEqual(fromstring(b'abc\0def'), b'abc')
self.assertEqual(fromstring(b''), b'')
@@ -74,7 +74,7 @@ class CAPITest(unittest.TestCase):
def test_fromobject(self):
# Test PyBytes_FromObject()
- fromobject = _testcapi.bytes_fromobject
+ fromobject = _testlimitedcapi.bytes_fromobject
self.assertEqual(fromobject(b'abc'), b'abc')
self.assertEqual(fromobject(bytearray(b'abc')), b'abc')
@@ -88,7 +88,7 @@ class CAPITest(unittest.TestCase):
def test_size(self):
# Test PyBytes_Size()
- size = _testcapi.bytes_size
+ size = _testlimitedcapi.bytes_size
self.assertEqual(size(b'abc'), 3)
self.assertEqual(size(BytesSubclass(b'abc')), 3)
@@ -100,7 +100,7 @@ class CAPITest(unittest.TestCase):
def test_asstring(self):
"""Test PyBytes_AsString()"""
- asstring = _testcapi.bytes_asstring
+ asstring = _testlimitedcapi.bytes_asstring
self.assertEqual(asstring(b'abc', 4), b'abc\0')
self.assertEqual(asstring(b'abc\0def', 8), b'abc\0def\0')
@@ -111,8 +111,8 @@ class CAPITest(unittest.TestCase):
def test_asstringandsize(self):
"""Test PyBytes_AsStringAndSize()"""
- asstringandsize = _testcapi.bytes_asstringandsize
- asstringandsize_null = _testcapi.bytes_asstringandsize_null
+ asstringandsize = _testlimitedcapi.bytes_asstringandsize
+ asstringandsize_null = _testlimitedcapi.bytes_asstringandsize_null
self.assertEqual(asstringandsize(b'abc', 4), (b'abc\0', 3))
self.assertEqual(asstringandsize(b'abc\0def', 8), (b'abc\0def\0', 7))
@@ -128,7 +128,7 @@ class CAPITest(unittest.TestCase):
def test_repr(self):
# Test PyBytes_Repr()
- bytes_repr = _testcapi.bytes_repr
+ bytes_repr = _testlimitedcapi.bytes_repr
self.assertEqual(bytes_repr(b'''abc''', 0), r"""b'abc'""")
self.assertEqual(bytes_repr(b'''abc''', 1), r"""b'abc'""")
@@ -149,7 +149,7 @@ class CAPITest(unittest.TestCase):
def test_concat(self, concat=None):
"""Test PyBytes_Concat()"""
if concat is None:
- concat = _testcapi.bytes_concat
+ concat = _testlimitedcapi.bytes_concat
self.assertEqual(concat(b'abc', b'def'), b'abcdef')
self.assertEqual(concat(b'a\0b', b'c\0d'), b'a\0bc\0d')
@@ -182,11 +182,11 @@ class CAPITest(unittest.TestCase):
def test_concatanddel(self):
"""Test PyBytes_ConcatAndDel()"""
- self.test_concat(_testcapi.bytes_concatanddel)
+ self.test_concat(_testlimitedcapi.bytes_concatanddel)
def test_decodeescape(self):
"""Test PyBytes_DecodeEscape()"""
- decodeescape = _testcapi.bytes_decodeescape
+ decodeescape = _testlimitedcapi.bytes_decodeescape
self.assertEqual(decodeescape(b'abc'), b'abc')
self.assertEqual(decodeescape(br'\t\n\r\x0b\x0c\x00\\\'\"'),
diff --git a/Lib/test/test_capi/test_sys.py b/Lib/test/test_capi/test_sys.py
index 08bf037..54a8e02 100644
--- a/Lib/test/test_capi/test_sys.py
+++ b/Lib/test/test_capi/test_sys.py
@@ -5,9 +5,9 @@ from test import support
from test.support import import_helper
try:
- import _testcapi
+ import _testlimitedcapi
except ImportError:
- _testcapi = None
+ _testlimitedcapi = None
NULL = None
@@ -20,10 +20,10 @@ class CAPITest(unittest.TestCase):
maxDiff = None
@support.cpython_only
- @unittest.skipIf(_testcapi is None, 'need _testcapi module')
+ @unittest.skipIf(_testlimitedcapi is None, 'need _testlimitedcapi module')
def test_sys_getobject(self):
# Test PySys_GetObject()
- getobject = _testcapi.sys_getobject
+ getobject = _testlimitedcapi.sys_getobject
self.assertIs(getobject(b'stdout'), sys.stdout)
with support.swap_attr(sys, '\U0001f40d', 42):
@@ -38,10 +38,10 @@ class CAPITest(unittest.TestCase):
# CRASHES getobject(NULL)
@support.cpython_only
- @unittest.skipIf(_testcapi is None, 'need _testcapi module')
+ @unittest.skipIf(_testlimitedcapi is None, 'need _testlimitedcapi module')
def test_sys_setobject(self):
# Test PySys_SetObject()
- setobject = _testcapi.sys_setobject
+ setobject = _testlimitedcapi.sys_setobject
value = ['value']
value2 = ['value2']
@@ -70,10 +70,10 @@ class CAPITest(unittest.TestCase):
# CRASHES setobject(NULL, value)
@support.cpython_only
- @unittest.skipIf(_testcapi is None, 'need _testcapi module')
+ @unittest.skipIf(_testlimitedcapi is None, 'need _testlimitedcapi module')
def test_sys_getxoptions(self):
# Test PySys_GetXOptions()
- getxoptions = _testcapi.sys_getxoptions
+ getxoptions = _testlimitedcapi.sys_getxoptions
self.assertIs(getxoptions(), sys._xoptions)