Skip to content

Commit b496ff3

Browse files
authored
gh-105751: Reenable disable test_ctypes tests (#105818)
Reenable 3 tests: * test_overflow() * test_basic_wstrings() * test_toolong()
1 parent 0841ca7 commit b496ff3

File tree

2 files changed

+25
-31
lines changed

2 files changed

+25
-31
lines changed

Lib/test/test_ctypes/test_memfunctions.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99

1010

1111
class MemFunctionsTest(unittest.TestCase):
12-
@unittest.skip('test disabled')
1312
def test_overflow(self):
1413
# string_at and wstring_at must use the Python calling
1514
# convention (which acquires the GIL and checks the Python
1615
# error flag). Provoke an error and catch it; see also issue
17-
# #3554: <http://bugs.python.org/issue3554>
16+
# gh-47804.
1817
self.assertRaises((OverflowError, MemoryError, SystemError),
19-
lambda: wstring_at(u"foo", sys.maxint - 1))
18+
lambda: wstring_at(u"foo", sys.maxsize - 1))
2019
self.assertRaises((OverflowError, MemoryError, SystemError),
21-
lambda: string_at("foo", sys.maxint - 1))
20+
lambda: string_at("foo", sys.maxsize - 1))
2221

2322
def test_memmove(self):
2423
# large buffers apparently increase the chance that the memory

Lib/test/test_ctypes/test_strings.py

+22-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import unittest
2-
from ctypes import create_string_buffer, sizeof, byref, c_char, c_wchar
2+
from ctypes import (create_string_buffer, create_unicode_buffer,
3+
sizeof, byref, c_char, c_wchar)
34

45

56
class StringArrayTestCase(unittest.TestCase):
@@ -88,41 +89,35 @@ def test_wchar(self):
8889
repr(byref(c_wchar("x")))
8990
c_wchar("x")
9091

91-
@unittest.skip('test disabled')
9292
def test_basic_wstrings(self):
93-
cs = c_wstring("abcdef")
94-
95-
# XXX This behaviour is about to change:
96-
# len returns the size of the internal buffer in bytes.
97-
# This includes the terminating NUL character.
98-
self.assertEqual(sizeof(cs), 14)
99-
100-
# The value property is the string up to the first terminating NUL.
93+
cs = create_unicode_buffer("abcdef")
10194
self.assertEqual(cs.value, "abcdef")
102-
self.assertEqual(c_wstring("abc\000def").value, "abc")
10395

104-
self.assertEqual(c_wstring("abc\000def").value, "abc")
96+
# value can be changed
97+
cs.value = "abc"
98+
self.assertEqual(cs.value, "abc")
99+
100+
# string is truncated at NUL character
101+
cs.value = "def\0z"
102+
self.assertEqual(cs.value, "def")
105103

106-
# The raw property is the total buffer contents:
107-
self.assertEqual(cs.raw, "abcdef\000")
108-
self.assertEqual(c_wstring("abc\000def").raw, "abc\000def\000")
104+
self.assertEqual(create_unicode_buffer("abc\0def").value, "abc")
109105

110-
# We can change the value:
111-
cs.value = "ab"
112-
self.assertEqual(cs.value, "ab")
113-
self.assertEqual(cs.raw, "ab\000\000\000\000\000")
106+
# created with an empty string
107+
cs = create_unicode_buffer(3)
108+
self.assertEqual(cs.value, "")
114109

115-
self.assertRaises(TypeError, c_wstring, "123")
116-
self.assertRaises(ValueError, c_wstring, 0)
110+
cs.value = "abc"
111+
self.assertEqual(cs.value, "abc")
117112

118-
@unittest.skip('test disabled')
119113
def test_toolong(self):
120-
cs = c_wstring("abcdef")
121-
# Much too long string:
122-
self.assertRaises(ValueError, setattr, cs, "value", "123456789012345")
114+
cs = create_unicode_buffer("abc")
115+
with self.assertRaises(ValueError):
116+
cs.value = "abcdef"
123117

124-
# One char too long values:
125-
self.assertRaises(ValueError, setattr, cs, "value", "1234567")
118+
cs = create_unicode_buffer(4)
119+
with self.assertRaises(ValueError):
120+
cs.value = "abcdef"
126121

127122

128123
def run_test(rep, msg, func, arg):

0 commit comments

Comments
 (0)