[ctypes-commit] ctypes/ctypes/test test_simplesubclasses.py,1.1.2.1,1.1.2.2 test_paramflags.py,1.1.2
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2006-01-02 19:12:11
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5101 Modified Files: Tag: branch_1_0 test_simplesubclasses.py test_paramflags.py test_libc.py test_leaks.py test_functions.py test_checkretval.py __init__.py Log Message: Sync with upstream version. Index: test_functions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_functions.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** test_functions.py 2 Jan 2006 15:09:01 -0000 1.1.2.2 --- test_functions.py 2 Jan 2006 19:12:01 -0000 1.1.2.3 *************** *** 5,10 **** Later... """ ! import sys, unittest from ctypes import * try: --- 5,11 ---- Later... """ ! from ctypes import * + import sys, unittest try: Index: test_simplesubclasses.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_simplesubclasses.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** test_simplesubclasses.py 3 Nov 2005 19:49:19 -0000 1.1.2.1 --- test_simplesubclasses.py 2 Jan 2006 19:12:01 -0000 1.1.2.2 *************** *** 2,8 **** from ctypes import * - from ctypes.test import requires, is_resource_enabled - requires("devel") - class MyInt(c_int): def __cmp__(self, other): --- 2,5 ---- Index: test_checkretval.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_checkretval.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** test_checkretval.py 3 Nov 2005 19:49:19 -0000 1.1.2.1 --- test_checkretval.py 2 Jan 2006 19:12:01 -0000 1.1.2.2 *************** *** 10,14 **** class CHECKED(c_int): def _check_retval_(value): ! return str(value) _check_retval_ = staticmethod(_check_retval_) --- 10,15 ---- class CHECKED(c_int): def _check_retval_(value): ! # Receives a CHECKED instance. ! return str(value.value) _check_retval_ = staticmethod(_check_retval_) Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/__init__.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** __init__.py 4 Nov 2005 07:36:35 -0000 1.1.2.2 --- __init__.py 2 Jan 2006 19:12:01 -0000 1.1.2.3 *************** *** 16,22 **** if sys._getframe().f_back.f_globals.get("__name__") == "__main__": return True ! return use_resources is not None and \ (resource in use_resources or "*" in use_resources) def requires(resource, msg=None): """Raise ResourceDenied if the specified resource is not available. --- 16,26 ---- if sys._getframe().f_back.f_globals.get("__name__") == "__main__": return True ! result = use_resources is not None and \ (resource in use_resources or "*" in use_resources) + if not result: + _unavail[resource] = None + return result + _unavail = {} def requires(resource, msg=None): """Raise ResourceDenied if the specified resource is not available. *************** *** 108,116 **** self.stream.writeln(result.separator2) run = result.testsRun ! if skipped: self.stream.writeln("Ran %d test%s in %.3fs (%s module%s skipped)" % (run, run != 1 and "s" or "", timeTaken, len(skipped), ! len(skipped) > 1 and "s" or "")) else: self.stream.writeln("Ran %d test%s in %.3fs" % --- 112,123 ---- self.stream.writeln(result.separator2) run = result.testsRun ! if _unavail: #skipped: ! requested = _unavail.keys() ! requested.sort() self.stream.writeln("Ran %d test%s in %.3fs (%s module%s skipped)" % (run, run != 1 and "s" or "", timeTaken, len(skipped), ! len(skipped) != 1 and "s" or "")) ! self.stream.writeln("Unavailable resources: %s" % ", ".join(requested)) else: self.stream.writeln("Ran %d test%s in %.3fs" % *************** *** 131,135 **** ! def main(package): try: opts, args = getopt.getopt(sys.argv[1:], "rqvu:") --- 138,142 ---- ! def main(*packages): try: opts, args = getopt.getopt(sys.argv[1:], "rqvu:") *************** *** 158,162 **** mask = args[0] ! run_tests(package, mask, verbosity, search_leaks) --- 165,170 ---- mask = args[0] ! for package in packages: ! run_tests(package, mask, verbosity, search_leaks) Index: test_libc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_libc.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** test_libc.py 22 Dec 2005 20:34:57 -0000 1.1.2.2 --- test_libc.py 2 Jan 2006 19:12:01 -0000 1.1.2.3 *************** *** 15,19 **** self.failUnlessEqual(libm.sqrt(2.0), math.sqrt(2.0)) ! def SKIP_test_cdecl_decorator(self): # @ cdecl(c_double, "libm", [c_double]) --- 15,19 ---- self.failUnlessEqual(libm.sqrt(2.0), math.sqrt(2.0)) ! def test_cdecl_decorator(self): # @ cdecl(c_double, "libm", [c_double]) *************** *** 21,25 **** return sqrt._api_(value) # Oh well, compatibility with Python 2.3 ! sqrt = cdecl(c_double, "libm", [c_double]) (sqrt) self.failUnlessEqual(sqrt(4.0), 2.0) --- 21,25 ---- return sqrt._api_(value) # Oh well, compatibility with Python 2.3 ! sqrt = cdecl(c_double, "m", [c_double]) (sqrt) self.failUnlessEqual(sqrt(4.0), 2.0) *************** *** 37,42 **** self.failUnlessEqual(chars.raw, " ,,aaaadmmmnpppsss\x00") ! def SKIP_test_qsort_decorator(self): ! from ctypes.decorators import cdecl, name_library CMPFUNC = CFUNCTYPE(c_int, c_void_p, c_void_p) --- 37,42 ---- self.failUnlessEqual(chars.raw, " ,,aaaadmmmnpppsss\x00") ! def test_qsort_decorator(self): ! from ctypes.decorators import cdecl CMPFUNC = CFUNCTYPE(c_int, c_void_p, c_void_p) *************** *** 46,50 **** itemsize = sizeof(sequence) / len(sequence) qsort._api_(sequence, len(sequence), itemsize, CMPFUNC(cmp_func)) ! qsort = cdecl(None, "libc", [c_void_p, c_int, c_int, CMPFUNC])(qsort) def sortfunc(a, b): --- 46,50 ---- itemsize = sizeof(sequence) / len(sequence) qsort._api_(sequence, len(sequence), itemsize, CMPFUNC(cmp_func)) ! qsort = cdecl(None, "c", [c_void_p, c_int, c_int, CMPFUNC])(qsort) def sortfunc(a, b): Index: test_paramflags.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_paramflags.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** test_paramflags.py 3 Nov 2005 19:49:19 -0000 1.1.2.1 --- test_paramflags.py 2 Jan 2006 19:12:01 -0000 1.1.2.2 *************** *** 1,4 **** --- 1,5 ---- import unittest, os from ctypes import * + from ctypes.test import is_resource_enabled class RECT(Structure): *************** *** 20,25 **** return cmp((self.left, self.top, self.right, self.bottom), (other.left, other.top, other.right, other.bottom)) - - class BOOL(c_long): def check_retval(self, val): --- 21,24 ---- *************** *** 30,33 **** --- 29,38 ---- _check_retval_ = classmethod(check_retval) + # paramflag values + IN = 1 + OUT = 2 + RETVAL = 8 + INOUT = IN + OUT + class Test(unittest.TestCase): *************** *** 56,66 **** proto = CFUNCTYPE(c_int, POINTER(c_int)) proto("TwoOutArgs", dll, ! ((1,),) ) proto("TwoOutArgs", dll, ! ((1, "paramname"),) ) proto("TwoOutArgs", dll, ! ((1, "paramname", 'DefaultVal'),) ) # We CAN pass None instead of the paramflags tuple --- 61,71 ---- proto = CFUNCTYPE(c_int, POINTER(c_int)) proto("TwoOutArgs", dll, ! ((IN,),) ) proto("TwoOutArgs", dll, ! ((IN, "paramname"),) ) proto("TwoOutArgs", dll, ! ((IN, "paramname", 'DefaultVal'),) ) # We CAN pass None instead of the paramflags tuple *************** *** 68,75 **** # and we CAN pass None instead of the parameter names proto("TwoOutArgs", dll, ! ((1, None),) ) proto("TwoOutArgs", dll, ! ((1, None, 'DefaultVal'),) ) --- 73,80 ---- # and we CAN pass None instead of the parameter names proto("TwoOutArgs", dll, ! ((IN, None),) ) proto("TwoOutArgs", dll, ! ((IN, None, 'DefaultVal'),) ) *************** *** 80,84 **** proto = CFUNCTYPE(BOOL, c_long, POINTER(RECT)) ! func = proto("GetRectangle", dll, ((1, "hwnd"), (2,))) # returns a RECT instance... --- 85,89 ---- proto = CFUNCTYPE(BOOL, c_long, POINTER(RECT)) ! func = proto("GetRectangle", dll, ((IN, "hwnd"), (OUT,))) # returns a RECT instance... *************** *** 99,109 **** dll = CDLL(_ctypes_test.__file__) ! def checker(retval, func, args, *opt): if retval == 0: raise ValueError(args[0]) ! return args[1]._obj proto = CFUNCTYPE(c_int, c_long, POINTER(RECT)) ! func = proto("GetRectangle", dll, ((1, "hwnd"), (2,))) func.errcheck = checker --- 104,114 ---- dll = CDLL(_ctypes_test.__file__) ! def checker(retval, func, args): if retval == 0: raise ValueError(args[0]) ! return args[1] proto = CFUNCTYPE(c_int, c_long, POINTER(RECT)) ! func = proto("GetRectangle", dll, ((IN, "hwnd"), (OUT,))) func.errcheck = checker *************** *** 130,134 **** proto = WINFUNCTYPE(BOOL, c_long, POINTER(RECT)) ! func = proto("GetWindowRect", windll.user32, ((1, "hwnd"), (2,))) # returns a RECT instance... --- 135,139 ---- proto = WINFUNCTYPE(BOOL, c_long, POINTER(RECT)) ! func = proto("GetWindowRect", windll.user32, ((IN, "hwnd"), (OUT,))) # returns a RECT instance... *************** *** 152,156 **** proto = WINFUNCTYPE(c_long, c_wchar_p) func = proto("GetModuleHandleW", windll.kernel32, ! ((1, "lpModuleName", None),)) func(lpModuleName="kernel32") func("kernel32") --- 157,161 ---- proto = WINFUNCTYPE(c_long, c_wchar_p) func = proto("GetModuleHandleW", windll.kernel32, ! ((IN, "lpModuleName", None),)) func(lpModuleName="kernel32") func("kernel32") *************** *** 163,186 **** #func(a=1) - ## def test_BSTR_inout(self): - ## # test BSTR [in, out] parameter - ## import _ctypes_test - ## dll = CDLL(_ctypes_test.__file__) - - ## from _ctypes import _SimpleCData - - ## class BSTR(_SimpleCData): - ## _type_ = "X" - ## def __repr__(self): - ## return "%s(%r)" % (self.__class__.__name__, self.value) - ## def __del__(self, _free=windll.oleaut32.SysFreeString): - ## if not self._b_base_: - ## _free(self) - - ## proto = CFUNCTYPE(None, BSTR) - ## func = proto("GetBSTR", dll, ((3, "p1"),)) - - ## self.failUnlessEqual(func("SPAM"), "XPAM") - ## def test_c_wchar_p_out(self): ## # XXX XXX XXX XXX XXX Doesn't this modify a Python string??? YES, it does. --- 168,171 ---- *************** *** 202,209 **** # void TwoOutArgs([in] int a, [out] int *p1, [in] int b, [out] int *p2); proto = CFUNCTYPE(None, c_int, POINTER(c_int), c_int, POINTER(c_int)) ! func = proto("TwoOutArgs", dll, ((1, "a"), (2, "p1"), (1, "b"), (2, "p2"))) self.failUnlessEqual((1, 2), func(1, 2)) self.failUnlessEqual((1, 2), func(b=2, a=1)) def test_inout_args(self): import _ctypes_test --- 187,210 ---- # void TwoOutArgs([in] int a, [out] int *p1, [in] int b, [out] int *p2); proto = CFUNCTYPE(None, c_int, POINTER(c_int), c_int, POINTER(c_int)) ! func = proto("TwoOutArgs", dll, ((IN, "a"), (OUT, "p1"), (IN, "b"), (OUT, "p2"))) self.failUnlessEqual((1, 2), func(1, 2)) self.failUnlessEqual((1, 2), func(b=2, a=1)) + def test_COMPTR_inout(self): + # test POINTER(interface) [in, out] parameter + import _ctypes_test + dll = CDLL(_ctypes_test.__file__) + + from comtypes import IUnknown + + proto = CFUNCTYPE(None, POINTER(IUnknown)) + func = proto("_testfunc_p_p", dll, ((IN | OUT, "p1"),)) + + from comtypes.errorinfo import CreateErrorInfo + ei = CreateErrorInfo() + + self.failUnlessEqual(func(ei), ei) + + def test_inout_args(self): import _ctypes_test *************** *** 213,224 **** # void TwoOutArgs([in] int a, [in, out] int *p1, [in] int b, [in, out] int *p2); proto = CFUNCTYPE(None, c_int, POINTER(c_int), c_int, POINTER(c_int)) ! func = proto("TwoOutArgs", dll, ((1, "a"), (3, "p1"), (1, "b"), (3, "p2"))) # The function returns ((a + p1), (b + p2)) ! self.failUnlessEqual((3, 7), func(1, 2, 3, 4)) ! self.failUnlessEqual((10, 14), func(a=1, b=3, p1=9, p2=11)) # TypeError: required argument 'p1' is missing self.assertRaises(TypeError, lambda: func(a=1, b=3)) # TypeError: required argument 'p2' is missing ! self.assertRaises(TypeError, lambda: func(a=1, b=3, p1=3)) def get_inout_args_func(): --- 214,263 ---- # void TwoOutArgs([in] int a, [in, out] int *p1, [in] int b, [in, out] int *p2); proto = CFUNCTYPE(None, c_int, POINTER(c_int), c_int, POINTER(c_int)) ! func = proto("TwoOutArgs", dll, ((IN, "a"), (INOUT, "p1"), (IN, "b"), (INOUT, "p2"))) # The function returns ((a + p1), (b + p2)) ! p1 = c_int(2) ! p2 = c_int(4) ! self.failUnlessEqual((p1, p2), func(1, p1, 3, p2)) ! self.failUnlessEqual((p1, p2), func(a=1, b=3, p1=p1, p2=p2)) # TypeError: required argument 'p1' is missing self.assertRaises(TypeError, lambda: func(a=1, b=3)) # TypeError: required argument 'p2' is missing ! self.assertRaises(TypeError, lambda: func(a=1, b=3, p1=p1)) ! ! def test_array_out_args(self): ! ! @ dllimport(c_ulong, "kernel32", ! ((['in'], c_ulong, "hModule"), ! (['out'], c_wchar * 256, "lpFilename"), ! (['in'], c_ulong, "nSize", 256))) ! def GetModuleFileName(retval, func, (hModule, lpFileName, nSize)): ! if retval == 0: ! raise WinError(GetLastError()) ! return lpFileName[:retval] ! ! import sys ! print GetModuleFileName(0) ! print GetModuleFileName(sys.dllhandle) ! ! # XXX Cleanup. ! from ctypes import * ! # XXX hack: we use COMMETHOD for parsing. ! from comtypes import COMMETHOD ! ! def dllimport(restype, dllname, argspec, ! cc="stdcall"): ! # COMMETHOD returns: ! # restype, methodname, tuple(argtypes), tuple(paramflags), tuple(idlflags), helptext ! restype, _, argtypes, paramflags, _, _ = COMMETHOD([], restype, "", *argspec) ! if cc == "stdcall": ! proto = WINFUNCTYPE(restype, *argtypes) ! elif cc == "cdecl": ! proto = CFUNCTYPE(restype, *argtypes) ! dll = getattr(windll, dllname) ! def decorate(func): ! result = proto(func.__name__ + "W", getattr(windll, dllname), paramflags) ! result.errcheck = func ! return result ! return decorate def get_inout_args_func(): Index: test_leaks.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_leaks.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** test_leaks.py 3 Nov 2005 19:49:19 -0000 1.1.2.1 --- test_leaks.py 2 Jan 2006 19:12:01 -0000 1.1.2.2 *************** *** 15,19 **** ("br", POINT)] ! if 0 and hasattr(sys, "gettotalrefcount"): def test_no_cycles_refcount(self): --- 15,19 ---- ("br", POINT)] ! if hasattr(sys, "gettotalrefcount"): def test_no_cycles_refcount(self): *************** *** 54,58 **** del _pointer_type_cache[LIST] # XXX should this be a weakkeydict? ! if 0 and hasattr(sys, "gettotalrefcount"): def test_cycles_refcount(self): --- 54,58 ---- del _pointer_type_cache[LIST] # XXX should this be a weakkeydict? ! if hasattr(sys, "gettotalrefcount"): def test_cycles_refcount(self): |