summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_capi/test_getargs.py
diff options
context:
space:
mode:
authorFurkan Onder <furkanonder@protonmail.com>2023-10-23 09:50:07 (GMT)
committerGitHub <noreply@github.com>2023-10-23 09:50:07 (GMT)
commitd4d947dd718c49e75f55e3b13bb7645b839d45b5 (patch)
tree82efecb813058390919d117f768b71fb681fbe9d /Lib/test/test_capi/test_getargs.py
parent4d781bce2704f32b2ff4ddb0f7d97701a565b3e6 (diff)
downloadcpython-d4d947dd718c49e75f55e3b13bb7645b839d45b5.zip
cpython-d4d947dd718c49e75f55e3b13bb7645b839d45b5.tar.gz
cpython-d4d947dd718c49e75f55e3b13bb7645b839d45b5.tar.bz2
[3.12] gh-67565: Add tests for C-contiguity checks (GH-110951) (GH-111198)
(cherry picked from commit 9376728ce45191fcc0b908c7487ad7985454537e)
Diffstat (limited to 'Lib/test/test_capi/test_getargs.py')
-rw-r--r--Lib/test/test_capi/test_getargs.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_capi/test_getargs.py b/Lib/test/test_capi/test_getargs.py
index 2546c6e..ea12ab1 100644
--- a/Lib/test/test_capi/test_getargs.py
+++ b/Lib/test/test_capi/test_getargs.py
@@ -153,6 +153,8 @@ class TupleSubclass(tuple):
class DictSubclass(dict):
pass
+NONCONTIG_WRITABLE = memoryview(bytearray(b'noncontig'))[::-2]
+NONCONTIG_READONLY = memoryview(b'noncontig')[::-2]
class Unsigned_TestCase(unittest.TestCase):
def test_b(self):
@@ -837,6 +839,8 @@ class Bytes_TestCase(unittest.TestCase):
self.assertEqual(getargs_y_star(bytearray(b'bytearray')), b'bytearray')
self.assertEqual(getargs_y_star(memoryview(b'memoryview')), b'memoryview')
self.assertRaises(TypeError, getargs_y_star, None)
+ self.assertRaises(BufferError, getargs_y_star, NONCONTIG_WRITABLE)
+ self.assertRaises(BufferError, getargs_y_star, NONCONTIG_READONLY)
def test_y_hash(self):
from _testcapi import getargs_y_hash
@@ -846,6 +850,9 @@ class Bytes_TestCase(unittest.TestCase):
self.assertRaises(TypeError, getargs_y_hash, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_y_hash, memoryview(b'memoryview'))
self.assertRaises(TypeError, getargs_y_hash, None)
+ # TypeError: must be read-only bytes-like object, not memoryview
+ self.assertRaises(TypeError, getargs_y_hash, NONCONTIG_WRITABLE)
+ self.assertRaises(TypeError, getargs_y_hash, NONCONTIG_READONLY)
def test_w_star(self):
# getargs_w_star() modifies first and last byte
@@ -861,6 +868,8 @@ class Bytes_TestCase(unittest.TestCase):
self.assertEqual(getargs_w_star(memoryview(buf)), b'[emoryvie]')
self.assertEqual(buf, bytearray(b'[emoryvie]'))
self.assertRaises(TypeError, getargs_w_star, None)
+ self.assertRaises(TypeError, getargs_w_star, NONCONTIG_WRITABLE)
+ self.assertRaises(TypeError, getargs_w_star, NONCONTIG_READONLY)
class String_TestCase(unittest.TestCase):
@@ -893,6 +902,8 @@ class String_TestCase(unittest.TestCase):
self.assertEqual(getargs_s_star(bytearray(b'bytearray')), b'bytearray')
self.assertEqual(getargs_s_star(memoryview(b'memoryview')), b'memoryview')
self.assertRaises(TypeError, getargs_s_star, None)
+ self.assertRaises(BufferError, getargs_s_star, NONCONTIG_WRITABLE)
+ self.assertRaises(BufferError, getargs_s_star, NONCONTIG_READONLY)
def test_s_hash(self):
from _testcapi import getargs_s_hash
@@ -902,6 +913,9 @@ class String_TestCase(unittest.TestCase):
self.assertRaises(TypeError, getargs_s_hash, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_s_hash, memoryview(b'memoryview'))
self.assertRaises(TypeError, getargs_s_hash, None)
+ # TypeError: must be read-only bytes-like object, not memoryview
+ self.assertRaises(TypeError, getargs_s_hash, NONCONTIG_WRITABLE)
+ self.assertRaises(TypeError, getargs_s_hash, NONCONTIG_READONLY)
def test_s_hash_int(self):
# "s#" without PY_SSIZE_T_CLEAN defined.
@@ -937,6 +951,8 @@ class String_TestCase(unittest.TestCase):
self.assertEqual(getargs_z_star(bytearray(b'bytearray')), b'bytearray')
self.assertEqual(getargs_z_star(memoryview(b'memoryview')), b'memoryview')
self.assertIsNone(getargs_z_star(None))
+ self.assertRaises(BufferError, getargs_z_star, NONCONTIG_WRITABLE)
+ self.assertRaises(BufferError, getargs_z_star, NONCONTIG_READONLY)
def test_z_hash(self):
from _testcapi import getargs_z_hash
@@ -946,6 +962,9 @@ class String_TestCase(unittest.TestCase):
self.assertRaises(TypeError, getargs_z_hash, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_z_hash, memoryview(b'memoryview'))
self.assertIsNone(getargs_z_hash(None))
+ # TypeError: must be read-only bytes-like object, not memoryview
+ self.assertRaises(TypeError, getargs_z_hash, NONCONTIG_WRITABLE)
+ self.assertRaises(TypeError, getargs_z_hash, NONCONTIG_READONLY)
def test_es(self):
from _testcapi import getargs_es