summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-06-15 09:36:41 (GMT)
committerGitHub <noreply@github.com>2023-06-15 09:36:41 (GMT)
commitb496ff31091d0b2530c804e64b9e84e4e154268c (patch)
treee67621a03f43149168faa9e1bc53a74a31b7a99b
parent0841ca7932987f30a2a23d39f3e6e141622d6fea (diff)
downloadcpython-b496ff31091d0b2530c804e64b9e84e4e154268c.zip
cpython-b496ff31091d0b2530c804e64b9e84e4e154268c.tar.gz
cpython-b496ff31091d0b2530c804e64b9e84e4e154268c.tar.bz2
gh-105751: Reenable disable test_ctypes tests (#105818)
Reenable 3 tests: * test_overflow() * test_basic_wstrings() * test_toolong()
-rw-r--r--Lib/test/test_ctypes/test_memfunctions.py7
-rw-r--r--Lib/test/test_ctypes/test_strings.py49
2 files changed, 25 insertions, 31 deletions
diff --git a/Lib/test/test_ctypes/test_memfunctions.py b/Lib/test/test_ctypes/test_memfunctions.py
index 2ff95f6..112b27b 100644
--- a/Lib/test/test_ctypes/test_memfunctions.py
+++ b/Lib/test/test_ctypes/test_memfunctions.py
@@ -9,16 +9,15 @@ from ctypes import (POINTER, sizeof, cast,
class MemFunctionsTest(unittest.TestCase):
- @unittest.skip('test disabled')
def test_overflow(self):
# string_at and wstring_at must use the Python calling
# convention (which acquires the GIL and checks the Python
# error flag). Provoke an error and catch it; see also issue
- # #3554: <http://bugs.python.org/issue3554>
+ # gh-47804.
self.assertRaises((OverflowError, MemoryError, SystemError),
- lambda: wstring_at(u"foo", sys.maxint - 1))
+ lambda: wstring_at(u"foo", sys.maxsize - 1))
self.assertRaises((OverflowError, MemoryError, SystemError),
- lambda: string_at("foo", sys.maxint - 1))
+ lambda: string_at("foo", sys.maxsize - 1))
def test_memmove(self):
# large buffers apparently increase the chance that the memory
diff --git a/Lib/test/test_ctypes/test_strings.py b/Lib/test/test_ctypes/test_strings.py
index 13d4000..3ecc6fe 100644
--- a/Lib/test/test_ctypes/test_strings.py
+++ b/Lib/test/test_ctypes/test_strings.py
@@ -1,5 +1,6 @@
import unittest
-from ctypes import create_string_buffer, sizeof, byref, c_char, c_wchar
+from ctypes import (create_string_buffer, create_unicode_buffer,
+ sizeof, byref, c_char, c_wchar)
class StringArrayTestCase(unittest.TestCase):
@@ -88,41 +89,35 @@ class WStringTestCase(unittest.TestCase):
repr(byref(c_wchar("x")))
c_wchar("x")
- @unittest.skip('test disabled')
def test_basic_wstrings(self):
- cs = c_wstring("abcdef")
-
- # XXX This behaviour is about to change:
- # len returns the size of the internal buffer in bytes.
- # This includes the terminating NUL character.
- self.assertEqual(sizeof(cs), 14)
-
- # The value property is the string up to the first terminating NUL.
+ cs = create_unicode_buffer("abcdef")
self.assertEqual(cs.value, "abcdef")
- self.assertEqual(c_wstring("abc\000def").value, "abc")
- self.assertEqual(c_wstring("abc\000def").value, "abc")
+ # value can be changed
+ cs.value = "abc"
+ self.assertEqual(cs.value, "abc")
+
+ # string is truncated at NUL character
+ cs.value = "def\0z"
+ self.assertEqual(cs.value, "def")
- # The raw property is the total buffer contents:
- self.assertEqual(cs.raw, "abcdef\000")
- self.assertEqual(c_wstring("abc\000def").raw, "abc\000def\000")
+ self.assertEqual(create_unicode_buffer("abc\0def").value, "abc")
- # We can change the value:
- cs.value = "ab"
- self.assertEqual(cs.value, "ab")
- self.assertEqual(cs.raw, "ab\000\000\000\000\000")
+ # created with an empty string
+ cs = create_unicode_buffer(3)
+ self.assertEqual(cs.value, "")
- self.assertRaises(TypeError, c_wstring, "123")
- self.assertRaises(ValueError, c_wstring, 0)
+ cs.value = "abc"
+ self.assertEqual(cs.value, "abc")
- @unittest.skip('test disabled')
def test_toolong(self):
- cs = c_wstring("abcdef")
- # Much too long string:
- self.assertRaises(ValueError, setattr, cs, "value", "123456789012345")
+ cs = create_unicode_buffer("abc")
+ with self.assertRaises(ValueError):
+ cs.value = "abcdef"
- # One char too long values:
- self.assertRaises(ValueError, setattr, cs, "value", "1234567")
+ cs = create_unicode_buffer(4)
+ with self.assertRaises(ValueError):
+ cs.value = "abcdef"
def run_test(rep, msg, func, arg):