diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-18 09:58:55 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-18 09:58:55 +0300 |
commit | 02b4dbb333f1afeed3d08399327b34c757184409 (patch) | |
tree | 5c1304a4db837998310a6148d2ab5b14ad9f3de3 /Lib/ctypes | |
parent | 5fd63b35e842ed856460c2f66dbdd7225fa621f5 (diff) | |
parent | c69f005a552126f1ffff19eccc369201ddf67a58 (diff) | |
download | cpython-02b4dbb333f1afeed3d08399327b34c757184409.tar.gz |
Issue #27343: Fixed error message for conflicting initializers of ctypes.Structure.
Diffstat (limited to 'Lib/ctypes')
-rw-r--r-- | Lib/ctypes/test/test_bitfields.py | 1 | ||||
-rw-r--r-- | Lib/ctypes/test/test_objects.py | 2 | ||||
-rw-r--r-- | Lib/ctypes/test/test_parameters.py | 8 | ||||
-rw-r--r-- | Lib/ctypes/test/test_pep3118.py | 2 | ||||
-rw-r--r-- | Lib/ctypes/test/test_returnfuncptrs.py | 1 | ||||
-rw-r--r-- | Lib/ctypes/test/test_sizes.py | 1 | ||||
-rw-r--r-- | Lib/ctypes/test/test_structures.py | 13 | ||||
-rw-r--r-- | Lib/ctypes/test/test_values.py | 6 | ||||
-rw-r--r-- | Lib/ctypes/util.py | 4 |
9 files changed, 16 insertions, 22 deletions
diff --git a/Lib/ctypes/test/test_bitfields.py b/Lib/ctypes/test/test_bitfields.py index b39d82cc0b..0eb09fb4bf 100644 --- a/Lib/ctypes/test/test_bitfields.py +++ b/Lib/ctypes/test/test_bitfields.py @@ -3,7 +3,6 @@ from ctypes.test import need_symbol import unittest import os -import ctypes import _ctypes_test class BITS(Structure): diff --git a/Lib/ctypes/test/test_objects.py b/Lib/ctypes/test/test_objects.py index ef7b20b000..19e3dc1f2d 100644 --- a/Lib/ctypes/test/test_objects.py +++ b/Lib/ctypes/test/test_objects.py @@ -54,7 +54,7 @@ of 'x' ('_b_base_' is either None, or the root object owning the memory block): ''' -import unittest, doctest, sys +import unittest, doctest import ctypes.test.test_objects diff --git a/Lib/ctypes/test/test_parameters.py b/Lib/ctypes/test/test_parameters.py index e56bccf999..363f58612d 100644 --- a/Lib/ctypes/test/test_parameters.py +++ b/Lib/ctypes/test/test_parameters.py @@ -1,4 +1,4 @@ -import unittest, sys +import unittest from ctypes.test import need_symbol class SimpleTypesTestCase(unittest.TestCase): @@ -49,7 +49,7 @@ class SimpleTypesTestCase(unittest.TestCase): # XXX Replace by c_char_p tests def test_cstrings(self): - from ctypes import c_char_p, byref + from ctypes import c_char_p # c_char_p.from_param on a Python String packs the string # into a cparam object @@ -68,7 +68,7 @@ class SimpleTypesTestCase(unittest.TestCase): @need_symbol('c_wchar_p') def test_cw_strings(self): - from ctypes import byref, c_wchar_p + from ctypes import c_wchar_p c_wchar_p.from_param("123") @@ -98,7 +98,7 @@ class SimpleTypesTestCase(unittest.TestCase): def test_byref_pointer(self): # The from_param class method of POINTER(typ) classes accepts what is # returned by byref(obj), it type(obj) == typ - from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref + from ctypes import c_short, c_uint, c_int, c_long, POINTER, byref LPINT = POINTER(c_int) LPINT.from_param(byref(c_int(42))) diff --git a/Lib/ctypes/test/test_pep3118.py b/Lib/ctypes/test/test_pep3118.py index 32f802c861..d68397ea80 100644 --- a/Lib/ctypes/test/test_pep3118.py +++ b/Lib/ctypes/test/test_pep3118.py @@ -1,6 +1,6 @@ import unittest from ctypes import * -import re, struct, sys +import re, sys if sys.byteorder == "little": THIS_ENDIAN = "<" diff --git a/Lib/ctypes/test/test_returnfuncptrs.py b/Lib/ctypes/test/test_returnfuncptrs.py index 93eba6bb76..1974f40df6 100644 --- a/Lib/ctypes/test/test_returnfuncptrs.py +++ b/Lib/ctypes/test/test_returnfuncptrs.py @@ -1,6 +1,5 @@ import unittest from ctypes import * -import os import _ctypes_test diff --git a/Lib/ctypes/test/test_sizes.py b/Lib/ctypes/test/test_sizes.py index f9b5e97260..4ceacbc290 100644 --- a/Lib/ctypes/test/test_sizes.py +++ b/Lib/ctypes/test/test_sizes.py @@ -2,7 +2,6 @@ from ctypes import * -import sys import unittest diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py index d998c27488..94a86ea6dd 100644 --- a/Lib/ctypes/test/test_structures.py +++ b/Lib/ctypes/test/test_structures.py @@ -320,17 +320,14 @@ class StructureTestCase(unittest.TestCase): cls, msg = self.get_except(Person, b"Someone", (1, 2)) self.assertEqual(cls, RuntimeError) - self.assertEqual(msg, - "(Phone) <class 'TypeError'>: " - "expected bytes, int found") + self.assertRegex(msg, + r"\(Phone\) <class 'TypeError' at 0x.+>: " + r"expected bytes, int found") cls, msg = self.get_except(Person, b"Someone", (b"a", b"b", b"c")) self.assertEqual(cls, RuntimeError) - if issubclass(Exception, object): - self.assertEqual(msg, - "(Phone) <class 'TypeError'>: too many initializers") - else: - self.assertEqual(msg, "(Phone) TypeError: too many initializers") + self.assertRegex(msg, + r"\(Phone\) <class 'TypeError' at 0x.+>: too many initializers") def test_huge_field_name(self): # issue12881: segfault with large structure field names diff --git a/Lib/ctypes/test/test_values.py b/Lib/ctypes/test/test_values.py index 5a3a47f968..e71b48020f 100644 --- a/Lib/ctypes/test/test_values.py +++ b/Lib/ctypes/test/test_values.py @@ -79,9 +79,9 @@ class PythonValuesTestCase(unittest.TestCase): continue items.append((entry.name.decode("ascii"), entry.size)) - expected = [("__hello__", 161), - ("__phello__", -161), - ("__phello__.spam", 161), + expected = [("__hello__", 139), + ("__phello__", -139), + ("__phello__.spam", 139), ] self.assertEqual(items, expected, "PyImport_FrozenModules example " "in Doc/library/ctypes.rst may be out of date") diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py index 7684eab81d..e25a886a05 100644 --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -271,8 +271,8 @@ elif os.name == "posix": abi_type = mach_map.get(machine, 'libc6') # XXX assuming GLIBC's ldconfig (with option -p) - regex = os.fsencode( - '\s+(lib%s\.[^\s]+)\s+\(%s' % (re.escape(name), abi_type)) + regex = r'\s+(lib%s\.[^\s]+)\s+\(%s' + regex = os.fsencode(regex % (re.escape(name), abi_type)) try: with subprocess.Popen(['/sbin/ldconfig', '-p'], stdin=subprocess.DEVNULL, |