8000 gh-99266: ctypes: Preserve a more detailed exception in _SimpleCData.from_param by kamilturek · Pull Request #99760 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-99266: ctypes: Preserve a more detailed exception in _SimpleCData.from_param #99760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more tests
  • Loading branch information
kamilturek committed Jan 20, 2023
commit 2096a88a18b7d4754e6fa4916b6877db849b0298
12 changes: 12 additions & 0 deletions Lib/test/test_ctypes/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ def test_wchar_parm(self):
self.assertEqual(result, 139)
self.assertEqual(type(result), int)

with self.assertRaises(ArgumentError) as cm:
f(1, 2, 3, 4, 5.0, 6.0)
self.assertEqual(str(cm.exception),
"argument 2: TypeError: unicode string expected "
"instead of int instance")

with self.assertRaises(ArgumentError) as cm:
f(1, "abc", 3, 4, 5.0, 6.0)
self.assertEqual(str(cm.exception),
"argument 2: TypeError: one character unicode string "
"expected")

@need_symbol('c_wchar')
def test_wchar_result(self):
f = dll._testfunc_i_bhilfd
Expand Down
16 changes: 15 additions & 1 deletion Lib/test/test_ctypes/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,24 @@ def test_c_char(self):

with self.assertRaises(TypeError) as cm:
c_char.from_param(b"abc")

self.assertEqual(str(cm.exception),
"one character bytes, bytearray or integer expected")

@need_symbol('c_wchar')
def test_c_wchar(self):
from ctypes import c_wchar

with self.assertRaises(TypeError) as cm:
c_wchar.from_param("abc")
self.assertEqual(str(cm.exception),
"one character unicode string expected")


with self.assertRaises(TypeError) as cm:
c_wchar.from_param(123)
self.assertEqual(str(cm.exception),
"unicode string expected instead of int instance")


def test_int_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
Expand Down
0