mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
gh-105751: Reenable disable test_ctypes tests (#105818)
Reenable 3 tests: * test_overflow() * test_basic_wstrings() * test_toolong()
This commit is contained in:
parent
0841ca7932
commit
b496ff3109
2 changed files with 25 additions and 31 deletions
|
@ -9,16 +9,15 @@ from ctypes import (POINTER, sizeof, cast,
|
||||||
|
|
||||||
|
|
||||||
class MemFunctionsTest(unittest.TestCase):
|
class MemFunctionsTest(unittest.TestCase):
|
||||||
@unittest.skip('test disabled')
|
|
||||||
def test_overflow(self):
|
def test_overflow(self):
|
||||||
# string_at and wstring_at must use the Python calling
|
# string_at and wstring_at must use the Python calling
|
||||||
# convention (which acquires the GIL and checks the Python
|
# convention (which acquires the GIL and checks the Python
|
||||||
# error flag). Provoke an error and catch it; see also issue
|
# error flag). Provoke an error and catch it; see also issue
|
||||||
# #3554: <http://bugs.python.org/issue3554>
|
# gh-47804.
|
||||||
self.assertRaises((OverflowError, MemoryError, SystemError),
|
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),
|
self.assertRaises((OverflowError, MemoryError, SystemError),
|
||||||
lambda: string_at("foo", sys.maxint - 1))
|
lambda: string_at("foo", sys.maxsize - 1))
|
||||||
|
|
||||||
def test_memmove(self):
|
def test_memmove(self):
|
||||||
# large buffers apparently increase the chance that the memory
|
# large buffers apparently increase the chance that the memory
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import unittest
|
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):
|
class StringArrayTestCase(unittest.TestCase):
|
||||||
|
@ -88,41 +89,35 @@ class WStringTestCase(unittest.TestCase):
|
||||||
repr(byref(c_wchar("x")))
|
repr(byref(c_wchar("x")))
|
||||||
c_wchar("x")
|
c_wchar("x")
|
||||||
|
|
||||||
@unittest.skip('test disabled')
|
|
||||||
def test_basic_wstrings(self):
|
def test_basic_wstrings(self):
|
||||||
cs = c_wstring("abcdef")
|
cs = create_unicode_buffer("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.
|
|
||||||
self.assertEqual(cs.value, "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")
|
||||||
|
|
||||||
# The raw property is the total buffer contents:
|
# string is truncated at NUL character
|
||||||
self.assertEqual(cs.raw, "abcdef\000")
|
cs.value = "def\0z"
|
||||||
self.assertEqual(c_wstring("abc\000def").raw, "abc\000def\000")
|
self.assertEqual(cs.value, "def")
|
||||||
|
|
||||||
# We can change the value:
|
self.assertEqual(create_unicode_buffer("abc\0def").value, "abc")
|
||||||
cs.value = "ab"
|
|
||||||
self.assertEqual(cs.value, "ab")
|
|
||||||
self.assertEqual(cs.raw, "ab\000\000\000\000\000")
|
|
||||||
|
|
||||||
self.assertRaises(TypeError, c_wstring, "123")
|
# created with an empty string
|
||||||
self.assertRaises(ValueError, c_wstring, 0)
|
cs = create_unicode_buffer(3)
|
||||||
|
self.assertEqual(cs.value, "")
|
||||||
|
|
||||||
|
cs.value = "abc"
|
||||||
|
self.assertEqual(cs.value, "abc")
|
||||||
|
|
||||||
@unittest.skip('test disabled')
|
|
||||||
def test_toolong(self):
|
def test_toolong(self):
|
||||||
cs = c_wstring("abcdef")
|
cs = create_unicode_buffer("abc")
|
||||||
# Much too long string:
|
with self.assertRaises(ValueError):
|
||||||
self.assertRaises(ValueError, setattr, cs, "value", "123456789012345")
|
cs.value = "abcdef"
|
||||||
|
|
||||||
# One char too long values:
|
cs = create_unicode_buffer(4)
|
||||||
self.assertRaises(ValueError, setattr, cs, "value", "1234567")
|
with self.assertRaises(ValueError):
|
||||||
|
cs.value = "abcdef"
|
||||||
|
|
||||||
|
|
||||||
def run_test(rep, msg, func, arg):
|
def run_test(rep, msg, func, arg):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue