diff options
48 files changed, 179 insertions, 83 deletions
diff --git a/Lib/ctypes/_endian.py b/Lib/ctypes/_endian.py index b5446c0..3febb31 100644 --- a/Lib/ctypes/_endian.py +++ b/Lib/ctypes/_endian.py @@ -1,5 +1,5 @@ import sys -from ctypes import * +from ctypes import Array, Structure, Union _array_type = type(Array) diff --git a/Lib/test/test_ctypes/test_anon.py b/Lib/test/test_ctypes/test_anon.py index d378392..704f7a3 100644 --- a/Lib/test/test_ctypes/test_anon.py +++ b/Lib/test/test_ctypes/test_anon.py @@ -1,6 +1,6 @@ import unittest import test.support -from ctypes import * +from ctypes import c_int, Union, Structure, sizeof class AnonTest(unittest.TestCase): diff --git a/Lib/test/test_ctypes/test_array_in_pointer.py b/Lib/test/test_ctypes/test_array_in_pointer.py index ca1edcf..a149aa9 100644 --- a/Lib/test/test_ctypes/test_array_in_pointer.py +++ b/Lib/test/test_ctypes/test_array_in_pointer.py @@ -1,5 +1,5 @@ import unittest -from ctypes import * +from ctypes import c_byte, Structure, POINTER, cast from binascii import hexlify import re diff --git a/Lib/test/test_ctypes/test_arrays.py b/Lib/test/test_ctypes/test_arrays.py index 4730838..4f8747d 100644 --- a/Lib/test/test_ctypes/test_arrays.py +++ b/Lib/test/test_ctypes/test_arrays.py @@ -2,7 +2,10 @@ import ctypes import sys import unittest import warnings -from ctypes import * +from ctypes import (Structure, Array, sizeof, addressof, + create_string_buffer, create_unicode_buffer, + c_char, c_wchar, c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, + c_long, c_ulonglong, c_float, c_double, c_longdouble) from test.support import bigmemtest, _2G from test.test_ctypes import need_symbol diff --git a/Lib/test/test_ctypes/test_as_parameter.py b/Lib/test/test_ctypes/test_as_parameter.py index fcf99ff..1048c50 100644 --- a/Lib/test/test_ctypes/test_as_parameter.py +++ b/Lib/test/test_ctypes/test_as_parameter.py @@ -1,8 +1,12 @@ -import unittest +import _ctypes_test import ctypes -from ctypes import * +import unittest +from ctypes import (Structure, CDLL, CFUNCTYPE, + POINTER, pointer, byref, + c_short, c_int, c_long, c_longlong, + c_byte, c_wchar, c_float, c_double, + ArgumentError) from test.test_ctypes import need_symbol -import _ctypes_test dll = CDLL(_ctypes_test.__file__) diff --git a/Lib/test/test_ctypes/test_bitfields.py b/Lib/test/test_ctypes/test_bitfields.py index dad71a0..e7b06dd 100644 --- a/Lib/test/test_ctypes/test_bitfields.py +++ b/Lib/test/test_ctypes/test_bitfields.py @@ -1,4 +1,8 @@ -from ctypes import * +from ctypes import (CDLL, Structure, sizeof, POINTER, byref, alignment, + LittleEndianStructure, BigEndianStructure, + c_byte, c_ubyte, c_char, c_char_p, c_void_p, c_wchar, + c_uint32, c_uint64, + c_short, c_ushort, c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong) from test.test_ctypes import need_symbol from test import support import unittest diff --git a/Lib/test/test_ctypes/test_buffers.py b/Lib/test/test_ctypes/test_buffers.py index a9be202..c6c59b9 100644 --- a/Lib/test/test_ctypes/test_buffers.py +++ b/Lib/test/test_ctypes/test_buffers.py @@ -1,4 +1,5 @@ -from ctypes import * +from ctypes import (create_string_buffer, create_unicode_buffer, sizeof, + c_char, c_wchar) from test.test_ctypes import need_symbol import unittest diff --git a/Lib/test/test_ctypes/test_bytes.py b/Lib/test/test_ctypes/test_bytes.py index 092ec5a..3538ed7 100644 --- a/Lib/test/test_ctypes/test_bytes.py +++ b/Lib/test/test_ctypes/test_bytes.py @@ -1,7 +1,7 @@ """Test where byte objects are accepted""" -import unittest import sys -from ctypes import * +import unittest +from ctypes import Structure, c_char, c_char_p, c_wchar, c_wchar_p class BytesTest(unittest.TestCase): def test_c_char(self): diff --git a/Lib/test/test_ctypes/test_byteswap.py b/Lib/test/test_ctypes/test_byteswap.py index 7e98559..7507c07 100644 --- a/Lib/test/test_ctypes/test_byteswap.py +++ b/Lib/test/test_ctypes/test_byteswap.py @@ -1,7 +1,13 @@ import sys, unittest, struct, math, ctypes from binascii import hexlify -from ctypes import * +from ctypes import (Structure, Union, LittleEndianUnion, BigEndianUnion, + BigEndianStructure, LittleEndianStructure, + POINTER, sizeof, cast, + c_byte, c_ubyte, c_char, c_wchar, c_void_p, + c_short, c_ushort, c_int, c_uint, + c_long, c_ulong, c_longlong, c_ulonglong, + c_uint32, c_float, c_double) def bin(s): return hexlify(memoryview(s)).decode().upper() diff --git a/Lib/test/test_ctypes/test_callbacks.py b/Lib/test/test_ctypes/test_callbacks.py index a5c2e43..7ce9775 100644 --- a/Lib/test/test_ctypes/test_callbacks.py +++ b/Lib/test/test_ctypes/test_callbacks.py @@ -3,7 +3,12 @@ import unittest from test import support import ctypes -from ctypes import * +from ctypes import (CDLL, cdll, Structure, CFUNCTYPE, + ArgumentError, POINTER, sizeof, + c_byte, c_ubyte, c_char, c_char_p, + c_short, c_ushort, c_int, c_uint, + c_long, c_longlong, c_ulonglong, c_ulong, + c_float, c_double, c_longdouble, py_object) from test.test_ctypes import need_symbol from _ctypes import CTYPES_MAX_ARGCOUNT import _ctypes_test diff --git a/Lib/test/test_ctypes/test_cast.py b/Lib/test/test_ctypes/test_cast.py index 7ee23b1..641b078 100644 --- a/Lib/test/test_ctypes/test_cast.py +++ b/Lib/test/test_ctypes/test_cast.py @@ -1,7 +1,9 @@ -from ctypes import * -from test.test_ctypes import need_symbol -import unittest import sys +import unittest +from ctypes import (Structure, Union, POINTER, cast, sizeof, addressof, + c_void_p, c_char_p, c_wchar_p, + c_byte, c_short, c_int) +from test.test_ctypes import need_symbol class Test(unittest.TestCase): @@ -12,7 +14,7 @@ class Test(unittest.TestCase): ptr = cast(array, POINTER(c_int)) self.assertEqual([ptr[i] for i in range(3)], [42, 17, 2]) - if 2*sizeof(c_short) == sizeof(c_int): + if 2 * sizeof(c_short) == sizeof(c_int): ptr = cast(array, POINTER(c_short)) if sys.byteorder == "little": self.assertEqual([ptr[i] for i in range(6)], diff --git a/Lib/test/test_ctypes/test_cfuncs.py b/Lib/test/test_ctypes/test_cfuncs.py index d66e679..9cbde8a 100644 --- a/Lib/test/test_ctypes/test_cfuncs.py +++ b/Lib/test/test_ctypes/test_cfuncs.py @@ -1,13 +1,14 @@ -# A lot of failures in these tests on Mac OS X. -# Byte order related? - import unittest import ctypes -from ctypes import * +from ctypes import (CDLL, + c_byte, c_ubyte, c_char, + c_short, c_ushort, c_int, c_uint, + c_long, c_ulong, c_longlong, c_ulonglong, + c_float, c_double, c_longdouble) from test.test_ctypes import need_symbol - import _ctypes_test + class CFunctions(unittest.TestCase): _dll = CDLL(_ctypes_test.__file__) @@ -210,5 +211,6 @@ if hasattr(ctypes, 'WinDLL'): class stdcallCFunctions(CFunctions): _dll = stdcall_dll(_ctypes_test.__file__) + if __name__ == '__main__': unittest.main() diff --git a/Lib/test/test_ctypes/test_checkretval.py b/Lib/test/test_ctypes/test_checkretval.py index b483432..fe5f244 100644 --- a/Lib/test/test_ctypes/test_checkretval.py +++ b/Lib/test/test_ctypes/test_checkretval.py @@ -1,15 +1,16 @@ -import unittest - import ctypes -from ctypes import * +import unittest +from ctypes import CDLL, c_int from test.test_ctypes import need_symbol + class CHECKED(c_int): def _check_retval_(value): # Receives a CHECKED instance. return str(value.value) _check_retval_ = staticmethod(_check_retval_) + class Test(unittest.TestCase): def test_checkretval(self): @@ -32,5 +33,7 @@ class Test(unittest.TestCase): oleaut32 = ctypes.oledll.oleaut32 self.assertRaises(OSError, oleaut32.CreateTypeLib2, 0, None, None) + + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_ctypes/test_delattr.py b/Lib/test/test_ctypes/test_delattr.py index 0f4d586..10d2fe0 100644 --- a/Lib/test/test_ctypes/test_delattr.py +++ b/Lib/test/test_ctypes/test_delattr.py @@ -1,9 +1,11 @@ import unittest -from ctypes import * +from ctypes import Structure, c_char, c_int + class X(Structure): _fields_ = [("foo", c_int)] + class TestCase(unittest.TestCase): def test_simple(self): self.assertRaises(TypeError, @@ -17,5 +19,6 @@ class TestCase(unittest.TestCase): self.assertRaises(TypeError, delattr, X(), "foo") + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_ctypes/test_errno.py b/Lib/test/test_ctypes/test_errno.py index bfc20bd..3376322 100644 --- a/Lib/test/test_ctypes/test_errno.py +++ b/Lib/test/test_ctypes/test_errno.py @@ -2,14 +2,15 @@ import unittest, os, errno import threading import ctypes -from ctypes import * +from ctypes import CDLL, c_int, c_char_p, c_wchar_p, get_errno, set_errno from ctypes.util import find_library class Test(unittest.TestCase): def test_open(self): libc_name = find_library("c") if libc_name is None: - raise unittest.SkipTest("Unable to find C library") + self.skipTest("Unable to find C library") + libc = CDLL(libc_name, use_errno=True) if os.name == "nt": libc_open = libc._open @@ -73,5 +74,6 @@ class Test(unittest.TestCase): ctypes.set_last_error(0) + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_ctypes/test_find.py b/Lib/test/test_ctypes/test_find.py index 1ff9d01..7a1658b 100644 --- a/Lib/test/test_ctypes/test_find.py +++ b/Lib/test/test_ctypes/test_find.py @@ -1,11 +1,12 @@ -import unittest -import unittest.mock import os.path import sys import test.support -from test.support import os_helper -from ctypes import * +import unittest +import unittest.mock +from ctypes import CDLL, RTLD_GLOBAL from ctypes.util import find_library +from test.support import os_helper + # On some systems, loading the OpenGL libraries needs the RTLD_GLOBAL mode. class Test_OpenGL_libs(unittest.TestCase): @@ -36,11 +37,13 @@ class Test_OpenGL_libs(unittest.TestCase): cls.gl = CDLL(lib_gl, mode=RTLD_GLOBAL) except OSError: pass + if lib_glu: try: cls.glu = CDLL(lib_glu, RTLD_GLOBAL) except OSError: pass + if lib_gle: try: cls.gle = CDLL(lib_gle) diff --git a/Lib/test/test_ctypes/test_frombuffer.py b/Lib/test/test_ctypes/test_frombuffer.py index 55c2443..e3e1267 100644 --- a/Lib/test/test_ctypes/test_frombuffer.py +++ b/Lib/test/test_ctypes/test_frombuffer.py @@ -1,7 +1,7 @@ -from ctypes import * import array import gc import unittest +from ctypes import Structure, Union, Array, sizeof, c_char, c_int class X(Structure): _fields_ = [("c_int", c_int)] diff --git a/Lib/test/test_ctypes/test_funcptr.py b/Lib/test/test_ctypes/test_funcptr.py index ef6772c..72684d6 100644 --- a/Lib/test/test_ctypes/test_funcptr.py +++ b/Lib/test/test_ctypes/test_funcptr.py @@ -1,6 +1,8 @@ -import unittest +import _ctypes_test import ctypes -from ctypes import * +import unittest +from ctypes import (CDLL, Structure, CFUNCTYPE, sizeof, + c_void_p, c_char_p, c_char, c_int, c_uint, c_long) try: WINFUNCTYPE = ctypes.WINFUNCTYPE @@ -8,9 +10,9 @@ except AttributeError: # fake to enable this test on Linux WINFUNCTYPE = CFUNCTYPE -import _ctypes_test lib = CDLL(_ctypes_test.__file__) + class CFuncPtrTestCase(unittest.TestCase): def test_basic(self): X = WINFUNCTYPE(c_int, c_int, c_int) @@ -21,8 +23,8 @@ class CFuncPtrTestCase(unittest.TestCase): x = X(func) self.assertEqual(x.restype, c_int) self.assertEqual(x.argtypes, (c_int, c_int)) - self.assertEqual(sizeof(x), sizeof(c_voidp)) - self.assertEqual(sizeof(X), sizeof(c_voidp)) + self.assertEqual(sizeof(x), sizeof(c_void_p)) + self.assertEqual(sizeof(X), sizeof(c_void_p)) def test_first(self): StdCallback = WINFUNCTYPE(c_int, c_int, c_int) @@ -129,5 +131,6 @@ class CFuncPtrTestCase(unittest.TestCase): self.assertRaises(TypeError, _CFuncPtr, 13, "name", 42, "iid") + if __name__ == '__main__': unittest.main() diff --git a/Lib/test/test_ctypes/test_functions.py b/Lib/test/test_ctypes/test_functions.py index 3f33170..a14924a 100644 --- a/Lib/test/test_ctypes/test_functions.py +++ b/Lib/test/test_ctypes/test_functions.py @@ -6,7 +6,11 @@ Later... """ import ctypes -from ctypes import * +from ctypes import (CDLL, Structure, Array, CFUNCTYPE, + byref, POINTER, pointer, ArgumentError, + c_char, c_wchar, c_byte, c_char_p, + c_short, c_int, c_long, c_longlong, + c_float, c_double, c_longdouble) from test.test_ctypes import need_symbol import sys, unittest diff --git a/Lib/test/test_ctypes/test_incomplete.py b/Lib/test/test_ctypes/test_incomplete.py index 0b53c15..552effa 100644 --- a/Lib/test/test_ctypes/test_incomplete.py +++ b/Lib/test/test_ctypes/test_incomplete.py @@ -1,7 +1,7 @@ import ctypes import unittest import warnings -from ctypes import * +from ctypes import Structure, POINTER, pointer, c_char_p ################################################################ # diff --git a/Lib/test/test_ctypes/test_init.py b/Lib/test/test_ctypes/test_init.py index 75fad11..113425e 100644 --- a/Lib/test/test_ctypes/test_init.py +++ b/Lib/test/test_ctypes/test_init.py @@ -1,5 +1,6 @@ -from ctypes import * import unittest +from ctypes import Structure, c_int + class X(Structure): _fields_ = [("a", c_int), @@ -15,6 +16,7 @@ class X(Structure): self.a = 9 self.b = 12 + class Y(Structure): _fields_ = [("x", X)] @@ -36,5 +38,6 @@ class InitTest(unittest.TestCase): self.assertEqual((y.x.a, y.x.b), (9, 12)) self.assertEqual(y.x.new_was_called, False) + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_ctypes/test_internals.py b/Lib/test/test_ctypes/test_internals.py index 271e3f5..1290f80 100644 --- a/Lib/test/test_ctypes/test_internals.py +++ b/Lib/test/test_ctypes/test_internals.py @@ -1,6 +1,6 @@ # This tests the internal _objects attribute import unittest -from ctypes import * +from ctypes import Structure, POINTER, c_char_p, c_int from sys import getrefcount as grc # XXX This test must be reviewed for correctness!!! diff --git a/Lib/test/test_ctypes/test_keeprefs.py b/Lib/test/test_ctypes/test_keeprefs.py index 94c0257..ecfcda1 100644 --- a/Lib/test/test_ctypes/test_keeprefs.py +++ b/Lib/test/test_ctypes/test_keeprefs.py @@ -1,4 +1,4 @@ -from ctypes import * +from ctypes import Structure, POINTER, pointer, c_char_p, c_int import unittest class SimpleTestCase(unittest.TestCase): diff --git a/Lib/test/test_ctypes/test_libc.py b/Lib/test/test_ctypes/test_libc.py index 56285b5..8664529 100644 --- a/Lib/test/test_ctypes/test_libc.py +++ b/Lib/test/test_ctypes/test_libc.py @@ -1,10 +1,13 @@ import unittest -from ctypes import * -import _ctypes_test +from ctypes import (CDLL, CFUNCTYPE, POINTER, create_string_buffer, sizeof, + c_void_p, c_char, c_int, c_double, c_size_t) + +import _ctypes_test lib = CDLL(_ctypes_test.__file__) + def three_way_cmp(x, y): """Return -1 if x < y, 0 if x == y and 1 if x > y""" return (x > y) - (x < y) diff --git a/Lib/test/test_ctypes/test_loading.py b/Lib/test/test_ctypes/test_loading.py index fec26aa..0cbfcf0 100644 --- a/Lib/test/test_ctypes/test_loading.py +++ b/Lib/test/test_ctypes/test_loading.py @@ -1,15 +1,15 @@ -from ctypes import * import ctypes import os import shutil import subprocess import sys -import unittest import test.support -from test.support import import_helper -from test.support import os_helper +import unittest +from test.support import import_helper, os_helper +from ctypes import CDLL, cdll, addressof, c_void_p, c_char_p from ctypes.util import find_library + libc_name = None def setUpModule(): @@ -126,6 +126,7 @@ class LoaderTest(unittest.TestCase): kernel32.GetProcAddress.restype = c_void_p proc = kernel32.GetProcAddress(advapi32._handle, b"CloseEventLog") self.assertTrue(proc) + # This is the real test: call the function via 'call_function' self.assertEqual(0, call_function(proc, (None,))) @@ -196,6 +197,5 @@ class LoaderTest(unittest.TestCase): "WinDLL('_sqlite3.dll'); p.close()") - if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_ctypes/test_memfunctions.py b/Lib/test/test_ctypes/test_memfunctions.py index d5c9735..3f3b631 100644 --- a/Lib/test/test_ctypes/test_memfunctions.py +++ b/Lib/test/test_ctypes/test_memfunctions.py @@ -1,7 +1,11 @@ import sys from test import support import unittest -from ctypes import * +from ctypes import (POINTER, sizeof, cast, + create_string_buffer, string_at, + create_unicode_buffer, wstring_at, + memmove, memset, + c_char_p, c_byte, c_ubyte, c_wchar) from test.test_ctypes import need_symbol class MemFunctionsTest(unittest.TestCase): diff --git a/Lib/test/test_ctypes/test_numbers.py b/Lib/test/test_ctypes/test_numbers.py index aad6af4..061876f 100644 --- a/Lib/test/test_ctypes/test_numbers.py +++ b/Lib/test/test_ctypes/test_numbers.py @@ -3,8 +3,10 @@ import sys import unittest from array import array from operator import truth -from ctypes import * -from ctypes import _SimpleCData +from ctypes import (byref, sizeof, alignment, _SimpleCData, + c_char, c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, + c_long, c_ulong, c_longlong, c_ulonglong, + c_float, c_double, c_longdouble, c_bool) def valid_ranges(*types): # given a sequence of numeric types, collect their _type_ diff --git a/Lib/test/test_ctypes/test_objects.py b/Lib/test/test_ctypes/test_objects.py index 44a3c61..78b1634 100644 --- a/Lib/test/test_ctypes/test_objects.py +++ b/Lib/test/test_ctypes/test_objects.py @@ -11,7 +11,7 @@ is None. Here is an array of string pointers: ->>> from ctypes import * +>>> from ctypes import Structure, c_int, c_char_p >>> array = (c_char_p * 5)() >>> print(array._objects) None diff --git a/Lib/test/test_ctypes/test_pep3118.py b/Lib/test/test_ctypes/test_pep3118.py index 0381617..c8eb584 100644 --- a/Lib/test/test_ctypes/test_pep3118.py +++ b/Lib/test/test_ctypes/test_pep3118.py @@ -1,5 +1,10 @@ import unittest -from ctypes import * +from ctypes import (CFUNCTYPE, POINTER, sizeof, Union, + Structure, LittleEndianStructure, BigEndianStructure, + c_char, c_byte, c_ubyte, + c_short, c_ushort, c_int, c_uint, + c_long, c_ulong, c_longlong, c_ulonglong, c_uint64, + c_bool, c_float, c_double, c_longdouble, py_object) import re, sys if sys.byteorder == "little": diff --git a/Lib/test/test_ctypes/test_pickling.py b/Lib/test/test_ctypes/test_pickling.py index c4a79b9..1df79be 100644 --- a/Lib/test/test_ctypes/test_pickling.py +++ b/Lib/test/test_ctypes/test_pickling.py @@ -1,9 +1,13 @@ import unittest import pickle -from ctypes import * +from ctypes import (CDLL, Structure, CFUNCTYPE, pointer, + c_void_p, c_char_p, c_wchar_p, c_char, c_wchar, c_int, c_double) + + import _ctypes_test dll = CDLL(_ctypes_test.__file__) + class X(Structure): _fields_ = [("a", c_int), ("b", c_double)] init_called = 0 diff --git a/Lib/test/test_ctypes/test_pointers.py b/Lib/test/test_ctypes/test_pointers.py index 7b6c3f5..7d13aeb 100644 --- a/Lib/test/test_ctypes/test_pointers.py +++ b/Lib/test/test_ctypes/test_pointers.py @@ -1,8 +1,11 @@ -import unittest, sys - -import ctypes -from ctypes import * import _ctypes_test +import ctypes +import sys +import unittest +from ctypes import (CDLL, CFUNCTYPE, Structure, POINTER, pointer, byref, sizeof, + c_void_p, c_char_p, + c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, + c_long, c_ulong, c_longlong, c_ulonglong, c_float, c_double) ctype_types = [c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong, c_double, c_float] diff --git a/Lib/test/test_ctypes/test_prototypes.py b/Lib/test/test_ctypes/test_prototypes.py index bf27561..fe62043 100644 --- a/Lib/test/test_ctypes/test_prototypes.py +++ b/Lib/test/test_ctypes/test_prototypes.py @@ -1,4 +1,7 @@ -from ctypes import * +from ctypes import (CDLL, CFUNCTYPE, POINTER, ArgumentError, + pointer, byref, sizeof, addressof, + c_void_p, c_char_p, c_wchar_p, c_char, c_wchar, c_buffer, + c_short, c_int, c_long, c_longlong, c_double) from test.test_ctypes import need_symbol import unittest diff --git a/Lib/test/test_ctypes/test_python_api.py b/Lib/test/test_ctypes/test_python_api.py index de8989e..3799311 100644 --- a/Lib/test/test_ctypes/test_python_api.py +++ b/Lib/test/test_ctypes/test_python_api.py @@ -1,6 +1,8 @@ -from ctypes import * import unittest from test import support +from ctypes import (pythonapi, POINTER, c_buffer, sizeof, + py_object, c_char_p, c_char, c_long, c_size_t) + ################################################################ # This section should be moved into ctypes\__init__.py, when it's ready. @@ -82,5 +84,6 @@ class PythonAPITestCase(unittest.TestCase): self.assertEqual(repr(py_object(42)), "py_object(42)") self.assertEqual(repr(py_object(object)), "py_object(%r)" % object) + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_ctypes/test_random_things.py b/Lib/test/test_ctypes/test_random_things.py index cfd355a..fcea8e8 100644 --- a/Lib/test/test_ctypes/test_random_things.py +++ b/Lib/test/test_ctypes/test_random_things.py @@ -1,9 +1,9 @@ -from ctypes import * -import ctypes import contextlib -from test import support -import unittest +import ctypes import sys +import unittest +from test import support +from ctypes import CFUNCTYPE, c_void_p, c_char_p, c_int, c_double def callback_func(arg): diff --git a/Lib/test/test_ctypes/test_repr.py b/Lib/test/test_ctypes/test_repr.py index 60a2c80..bb6b5ae 100644 --- a/Lib/test/test_ctypes/test_repr.py +++ b/Lib/test/test_ctypes/test_repr.py @@ -1,4 +1,6 @@ -from ctypes import * +from ctypes import (c_byte, c_short, c_int, c_long, c_longlong, + c_ubyte, c_ushort, c_uint, c_ulong, c_ulonglong, + c_float, c_double, c_longdouble, c_bool, c_char) import unittest subclasses = [] @@ -25,5 +27,6 @@ class ReprTest(unittest.TestCase): self.assertEqual("c_char(b'x')", repr(c_char(b'x'))) self.assertEqual("<X object at", repr(X(b'x'))[:12]) + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_ctypes/test_returnfuncptrs.py b/Lib/test/test_ctypes/test_returnfuncptrs.py index 1974f40..6a624133 100644 --- a/Lib/test/test_ctypes/test_returnfuncptrs.py +++ b/Lib/test/test_ctypes/test_returnfuncptrs.py @@ -1,5 +1,5 @@ import unittest -from ctypes import * +from ctypes import CDLL, CFUNCTYPE, ArgumentError, c_char_p, c_void_p, c_char import _ctypes_test @@ -62,5 +62,6 @@ class ReturnFuncPtrTestCase(unittest.TestCase): self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0) self.assertRaises(TypeError, strchr, b"abcdef") + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_ctypes/test_simplesubclasses.py b/Lib/test/test_ctypes/test_simplesubclasses.py index 3da2794..6072b62 100644 --- a/Lib/test/test_ctypes/test_simplesubclasses.py +++ b/Lib/test/test_ctypes/test_simplesubclasses.py @@ -1,5 +1,6 @@ import unittest -from ctypes import * +from ctypes import Structure, CFUNCTYPE, c_int + class MyInt(c_int): def __eq__(self, other): @@ -7,6 +8,7 @@ class MyInt(c_int): return NotImplementedError return self.value == other.value + class Test(unittest.TestCase): def test_compare(self): @@ -51,5 +53,6 @@ class Test(unittest.TestCase): self.assertEqual(s.x, MyInt(42)) + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_ctypes/test_sizes.py b/Lib/test/test_ctypes/test_sizes.py index bf8d6ea..e981ccf 100644 --- a/Lib/test/test_ctypes/test_sizes.py +++ b/Lib/test/test_ctypes/test_sizes.py @@ -1,7 +1,9 @@ # Test specifically-sized containers. -from ctypes import * - +from ctypes import (sizeof, + c_int8, c_uint8, c_int16, c_uint16, + c_int32, c_uint32, c_int64, c_uint64, + c_void_p, c_size_t, c_ssize_t, c_time_t, SIZEOF_TIME_T) import unittest diff --git a/Lib/test/test_ctypes/test_slicing.py b/Lib/test/test_ctypes/test_slicing.py index b3e68f9..8979b27 100644 --- a/Lib/test/test_ctypes/test_slicing.py +++ b/Lib/test/test_ctypes/test_slicing.py @@ -1,5 +1,6 @@ import unittest -from ctypes import * +from ctypes import (CDLL, POINTER, sizeof, + c_byte, c_short, c_int, c_long, c_char, c_wchar, c_char_p) from test.test_ctypes import need_symbol import _ctypes_test diff --git a/Lib/test/test_ctypes/test_stringptr.py b/Lib/test/test_ctypes/test_stringptr.py index c20951f..1eae154 100644 --- a/Lib/test/test_ctypes/test_stringptr.py +++ b/Lib/test/test_ctypes/test_stringptr.py @@ -1,6 +1,6 @@ import unittest from test import support -from ctypes import * +from ctypes import CDLL, Structure, POINTER, c_buffer, c_char, c_char_p import _ctypes_test diff --git a/Lib/test/test_ctypes/test_strings.py b/Lib/test/test_ctypes/test_strings.py index a9003be..62d84cc 100644 --- a/Lib/test/test_ctypes/test_strings.py +++ b/Lib/test/test_ctypes/test_strings.py @@ -1,5 +1,5 @@ import unittest -from ctypes import * +from ctypes import c_buffer, sizeof, byref, c_char, c_wchar from test.test_ctypes import need_symbol class StringArrayTestCase(unittest.TestCase): diff --git a/Lib/test/test_ctypes/test_struct_fields.py b/Lib/test/test_ctypes/test_struct_fields.py index e444f5e..17a2e69 100644 --- a/Lib/test/test_ctypes/test_struct_fields.py +++ b/Lib/test/test_ctypes/test_struct_fields.py @@ -1,5 +1,5 @@ import unittest -from ctypes import * +from ctypes import Structure, Union, sizeof, c_char, c_int class StructFieldsTestCase(unittest.TestCase): # Structure/Union classes must get 'finalized' sooner or diff --git a/Lib/test/test_ctypes/test_structures.py b/Lib/test/test_ctypes/test_structures.py index df39dc7..04ed73a 100644 --- a/Lib/test/test_ctypes/test_structures.py +++ b/Lib/test/test_ctypes/test_structures.py @@ -1,7 +1,11 @@ import platform import sys import unittest -from ctypes import * +from ctypes import (CDLL, Structure, Union, POINTER, sizeof, byref, alignment, + c_void_p, c_char, c_wchar, c_byte, c_ubyte, + c_uint8, c_uint16, c_uint32, + c_short, c_ushort, c_int, c_uint, + c_long, c_ulong, c_longlong, c_ulonglong, c_float, c_double) from test.test_ctypes import need_symbol from struct import calcsize import _ctypes_test diff --git a/Lib/test/test_ctypes/test_unaligned_structures.py b/Lib/test/test_ctypes/test_unaligned_structures.py index ee7fb45..a7e1796 100644 --- a/Lib/test/test_ctypes/test_unaligned_structures.py +++ b/Lib/test/test_ctypes/test_unaligned_structures.py @@ -1,5 +1,8 @@ import sys, unittest -from ctypes import * +from ctypes import (Structure, BigEndianStructure, LittleEndianStructure, + c_byte, c_short, c_int, c_long, c_longlong, + c_float, c_double, + c_ushort, c_uint, c_ulong, c_ulonglong) structures = [] byteswapped_structures = [] diff --git a/Lib/test/test_ctypes/test_values.py b/Lib/test/test_ctypes/test_values.py index 435fdd2..9707e03 100644 --- a/Lib/test/test_ctypes/test_values.py +++ b/Lib/test/test_ctypes/test_values.py @@ -6,7 +6,7 @@ import _imp import importlib.util import unittest import sys -from ctypes import * +from ctypes import Structure, CDLL, POINTER, pythonapi, c_ubyte, c_char_p, c_int from test.support import import_helper import _ctypes_test diff --git a/Lib/test/test_ctypes/test_varsize_struct.py b/Lib/test/test_ctypes/test_varsize_struct.py index f409500..d2fa0b3 100644 --- a/Lib/test/test_ctypes/test_varsize_struct.py +++ b/Lib/test/test_ctypes/test_varsize_struct.py @@ -1,4 +1,4 @@ -from ctypes import * +from ctypes import Structure, sizeof, resize, c_int import unittest class VarSizeTest(unittest.TestCase): diff --git a/Lib/test/test_ctypes/test_win32.py b/Lib/test/test_ctypes/test_win32.py index 43ed9db..a8987dd 100644 --- a/Lib/test/test_ctypes/test_win32.py +++ b/Lib/test/test_ctypes/test_win32.py @@ -1,11 +1,13 @@ # Windows specific tests +import _ctypes_test import ctypes -from ctypes import * -import unittest, sys +import sys +import unittest +from ctypes import (CDLL, Structure, POINTER, pointer, sizeof, byref, + c_void_p, c_char, c_int, c_long) from test import support -import _ctypes_test @unittest.skipUnless(sys.platform == "win32", 'Windows-specific test') class FunctionCallTestCase(unittest.TestCase): @@ -94,6 +96,7 @@ class TestWinError(unittest.TestCase): self.assertEqual(e.errno, errno.EINVAL) self.assertEqual(e.winerror, ERROR_INVALID_PARAMETER) + class Structures(unittest.TestCase): def test_struct_by_value(self): class POINT(Structure): @@ -136,5 +139,6 @@ class Structures(unittest.TestCase): from ctypes import _pointer_type_cache del _pointer_type_cache[RECT] + if __name__ == '__main__': unittest.main() diff --git a/Lib/test/test_ctypes/test_wintypes.py b/Lib/test/test_ctypes/test_wintypes.py index a01b9b1..66fb8b7 100644 --- a/Lib/test/test_ctypes/test_wintypes.py +++ b/Lib/test/test_ctypes/test_wintypes.py @@ -5,7 +5,7 @@ import unittest # also work on POSIX -from ctypes import * +from ctypes import POINTER, cast, c_int16 from ctypes import wintypes |