[pywin32-checkins] pywin32/com/win32com/test testall.py, 1.29, 1.30 testvb.py, 1.21, 1.22
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-11-26 08:39:37
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18639/com/win32com/test Modified Files: testall.py testvb.py Log Message: various syntax modernizations Index: testvb.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testvb.py,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** testvb.py 26 Nov 2008 01:27:40 -0000 1.21 --- testvb.py 26 Nov 2008 08:39:33 -0000 1.22 *************** *** 17,21 **** ## useDispatcher = win32com.server.dispatcher.DefaultDebugDispatcher ! error = "VB Test Error" # Set up a COM object that VB will do some callbacks on. This is used --- 17,21 ---- ## useDispatcher = win32com.server.dispatcher.DefaultDebugDispatcher ! error = RuntimeError # Set up a COM object that VB will do some callbacks on. This is used *************** *** 61,83 **** vbtest.LongProperty = -1 if vbtest.LongProperty != -1: ! raise error, "Could not set the long property correctly." vbtest.IntProperty = 10 if vbtest.IntProperty != 10: ! raise error, "Could not set the integer property correctly." vbtest.VariantProperty = 10 if vbtest.VariantProperty != 10: ! raise error, "Could not set the variant integer property correctly." vbtest.VariantProperty = buffer('raw\0data') if vbtest.VariantProperty != buffer('raw\0data'): ! raise error, "Could not set the variant buffer property correctly." vbtest.StringProperty = "Hello from Python" if vbtest.StringProperty != "Hello from Python": ! raise error, "Could not set the string property correctly." vbtest.VariantProperty = "Hello from Python" if vbtest.VariantProperty != "Hello from Python": ! raise error, "Could not set the variant string property correctly." vbtest.VariantProperty = (1.0, 2.0, 3.0) if vbtest.VariantProperty != (1.0, 2.0, 3.0): ! raise error, "Could not set the variant property to an array of floats correctly - '%s'." % (vbtest.VariantProperty,) TestArrays(vbtest, bUseGenerated) --- 61,83 ---- vbtest.LongProperty = -1 if vbtest.LongProperty != -1: ! raise error("Could not set the long property correctly.") vbtest.IntProperty = 10 if vbtest.IntProperty != 10: ! raise error("Could not set the integer property correctly.") vbtest.VariantProperty = 10 if vbtest.VariantProperty != 10: ! raise error("Could not set the variant integer property correctly.") vbtest.VariantProperty = buffer('raw\0data') if vbtest.VariantProperty != buffer('raw\0data'): ! raise error("Could not set the variant buffer property correctly.") vbtest.StringProperty = "Hello from Python" if vbtest.StringProperty != "Hello from Python": ! raise error("Could not set the string property correctly.") vbtest.VariantProperty = "Hello from Python" if vbtest.VariantProperty != "Hello from Python": ! raise error("Could not set the variant string property correctly.") vbtest.VariantProperty = (1.0, 2.0, 3.0) if vbtest.VariantProperty != (1.0, 2.0, 3.0): ! raise error("Could not set the variant property to an array of floats correctly - '%s'." % (vbtest.VariantProperty,)) TestArrays(vbtest, bUseGenerated) *************** *** 96,100 **** vbtest.VariantPutref = vbtest if vbtest.VariantPutref._oleobj_!= vbtest._oleobj_: ! raise error, "Could not set the VariantPutref property correctly." # Cant test further types for this VariantPutref, as only # COM objects can be stored ByRef. --- 96,100 ---- vbtest.VariantPutref = vbtest if vbtest.VariantPutref._oleobj_!= vbtest._oleobj_: ! raise error("Could not set the VariantPutref property correctly.") # Cant test further types for this VariantPutref, as only # COM objects can be stored ByRef. *************** *** 105,114 **** # vbtest.CollectionProperty = NewCollection((1,2,"3", "Four")) # if vbtest.CollectionProperty != (1,2,"3", "Four"): ! # raise error, "Could not set the Collection property correctly - got back " + str(vbtest.CollectionProperty) # These are sub's that have a single byref param # Result should be just the byref. if vbtest.IncrementIntegerParam(1) != 2: ! raise error, "Could not pass an integer byref" # Sigh - we cant have *both* "ommited byref" and optional args --- 105,114 ---- # vbtest.CollectionProperty = NewCollection((1,2,"3", "Four")) # if vbtest.CollectionProperty != (1,2,"3", "Four"): ! # raise error("Could not set the Collection property correctly - got back " + str(vbtest.CollectionProperty)) # These are sub's that have a single byref param # Result should be just the byref. if vbtest.IncrementIntegerParam(1) != 2: ! raise error("Could not pass an integer byref") # Sigh - we cant have *both* "ommited byref" and optional args *************** *** 116,126 **** # rather than simply all byrefs working as optional. # if vbtest.IncrementIntegerParam() != 1: ! # raise error, "Could not pass an omitted integer byref" if vbtest.IncrementVariantParam(1) != 2: ! raise error, "Could not pass an int VARIANT byref:"+str(vbtest.IncrementVariantParam(1)) if vbtest.IncrementVariantParam(1.5) != 2.5: ! raise error, "Could not pass a float VARIANT byref" # Can't test IncrementVariantParam with the param omitted as it --- 116,126 ---- # rather than simply all byrefs working as optional. # if vbtest.IncrementIntegerParam() != 1: ! # raise error("Could not pass an omitted integer byref") if vbtest.IncrementVariantParam(1) != 2: ! raise error("Could not pass an int VARIANT byref:"+str(vbtest.IncrementVariantParam(1))) if vbtest.IncrementVariantParam(1.5) != 2.5: ! raise error("Could not pass a float VARIANT byref") # Can't test IncrementVariantParam with the param omitted as it *************** *** 131,135 **** ret = vbtest.PassIntByVal(1) if ret != 2: ! raise error, "Could not increment the integer - "+str(ret) TestVBInterface(vbtest) --- 131,135 ---- ret = vbtest.PassIntByVal(1) if ret != 2: ! raise error("Could not increment the integer - "+str(ret)) TestVBInterface(vbtest) *************** *** 140,149 **** ret = vbtest.PassIntByRef(1) if ret != (1,2): ! raise error, "Could not increment the integer - "+str(ret) # Check you can leave a byref arg blank. # see above # ret = vbtest.PassIntByRef() # if ret != (0,1): ! # raise error, "Could not increment the integer with default arg- "+str(ret) def _DoTestCollection(vbtest, col_name, expected): --- 140,149 ---- ret = vbtest.PassIntByRef(1) if ret != (1,2): ! raise error("Could not increment the integer - "+str(ret)) # Check you can leave a byref arg blank. # see above # ret = vbtest.PassIntByRef() # if ret != (0,1): ! # raise error("Could not increment the integer with default arg- "+str(ret)) def _DoTestCollection(vbtest, col_name, expected): *************** *** 159,163 **** check.append(item) if check != list(expected): ! raise error, "Collection %s didn't have %r (had %r)" % (col_name, expected, check) # Just looping over the collection again works (ie, is restartable) check = [] --- 159,163 ---- check.append(item) if check != list(expected): ! raise error("Collection %s didn't have %r (had %r)" % (col_name, expected, check)) # Just looping over the collection again works (ie, is restartable) check = [] *************** *** 165,169 **** check.append(item) if check != list(expected): ! raise error, "Collection 2nd time around %s didn't have %r (had %r)" % (col_name, expected, check) # Check we can get it via iter() i = iter(getattr(vbtest, col_name)) --- 165,169 ---- check.append(item) if check != list(expected): ! raise error("Collection 2nd time around %s didn't have %r (had %r)" % (col_name, expected, check)) # Check we can get it via iter() i = iter(getattr(vbtest, col_name)) *************** *** 172,176 **** check.append(item) if check != list(expected): ! raise error, "Collection iterator %s didn't have %r 2nd time around (had %r)" % (col_name, expected, check) # but an iterator is not restartable check = [] --- 172,176 ---- check.append(item) if check != list(expected): ! raise error("Collection iterator %s didn't have %r 2nd time around (had %r)" % (col_name, expected, check)) # but an iterator is not restartable check = [] *************** *** 178,187 **** check.append(item) if check != []: ! raise error, "2nd time around Collection iterator %s wasn't empty (had %r)" % (col_name, check) # Check len()==Count() c = getattr(vbtest, col_name) if len(c) != _getcount(c): ! raise error, "Collection %s __len__(%r) wasn't==Count(%r)" % (col_name, len(c), _getcount(c)) # Check we can do it with zero based indexing. c = getattr(vbtest, col_name) --- 178,187 ---- check.append(item) if check != []: ! raise error("2nd time around Collection iterator %s wasn't empty (had %r)" % (col_name, check)) # Check len()==Count() c = getattr(vbtest, col_name) if len(c) != _getcount(c): ! raise error("Collection %s __len__(%r) wasn't==Count(%r)" % (col_name, len(c), _getcount(c))) # Check we can do it with zero based indexing. c = getattr(vbtest, col_name) *************** *** 190,194 **** check.append(c[i]) if check != list(expected): ! raise error, "Collection %s didn't have %r (had %r)" % (col_name, expected, check) # Check we can do it with our old "Skip/Next" methods. --- 190,194 ---- check.append(c[i]) if check != list(expected): ! raise error("Collection %s didn't have %r (had %r)" % (col_name, expected, check)) # Check we can do it with our old "Skip/Next" methods. *************** *** 201,205 **** check.append(n[0]) if check != list(expected): ! raise error, "Collection %s didn't have %r (had %r)" % (col_name, expected, check) def TestCollections(vbtest): --- 201,205 ---- check.append(n[0]) if check != list(expected): ! raise error("Collection %s didn't have %r (had %r)" % (col_name, expected, check)) def TestCollections(vbtest): *************** *** 207,211 **** # zero based indexing works for simple VB collections. if vbtest.CollectionProperty[0] != 1: ! raise error, "The CollectionProperty[0] element was not the default value" _DoTestCollection(vbtest, "EnumerableCollectionProperty", []) --- 207,211 ---- # zero based indexing works for simple VB collections. if vbtest.CollectionProperty[0] != 1: ! raise error("The CollectionProperty[0] element was not the default value") _DoTestCollection(vbtest, "EnumerableCollectionProperty", []) *************** *** 219,230 **** vbtest.ArrayProperty = data if expected_exception is not None: ! raise error, "Expected '%s'" % expected_exception except expected_exception: return got = vbtest.ArrayProperty if got != data: ! raise error, \ ! "Could not set the array data correctly - got %r, expected %r" \ ! % (got, data) def TestArrays(vbtest, bUseGenerated): --- 219,230 ---- vbtest.ArrayProperty = data if expected_exception is not None: ! raise error("Expected '%s'" % expected_exception) except expected_exception: return got = vbtest.ArrayProperty if got != data: ! raise error( ! "Could not set the array data correctly - got %r, expected %r" ! % (got, data)) def TestArrays(vbtest, bUseGenerated): *************** *** 297,303 **** byRefParam = map(str, byRefParam) if testData != list(resultData): ! raise error, "The safe array data was not what we expected - got " + str(resultData) if testData != list(byRefParam): ! raise error, "The safe array data was not what we expected - got " + str(byRefParam) testData = [1.0, 2.0, 3.0] resultData, byRefParam = vbtest.PassSAFEARRAYVariant(testData) --- 297,303 ---- byRefParam = map(str, byRefParam) if testData != list(resultData): ! raise error("The safe array data was not what we expected - got " + str(resultData)) if testData != list(byRefParam): ! raise error("The safe array data was not what we expected - got " + str(byRefParam)) testData = [1.0, 2.0, 3.0] resultData, byRefParam = vbtest.PassSAFEARRAYVariant(testData) *************** *** 319,350 **** try: vbtest.IntProperty = "One" ! raise error, "Should have failed by now" except pythoncom.com_error, (hr, desc, exc, argErr): if hr != winerror.DISP_E_TYPEMISMATCH: ! raise error, "Expected DISP_E_TYPEMISMATCH" s = vbtest.StructProperty if s.int_val != 99 or str(s.str_val) != "hello": ! raise error, "The struct value was not correct" s.str_val = "Hi from Python" s.int_val = 11 if s.int_val != 11 or str(s.str_val) != "Hi from Python": ! raise error, "The struct value didnt persist!" if s.sub_val.int_val != 66 or str(s.sub_val.str_val) != "sub hello": ! raise error, "The sub-struct value was not correct" sub = s.sub_val sub.int_val = 22 if sub.int_val != 22: print sub.int_val ! raise error, "The sub-struct value didnt persist!" if s.sub_val.int_val != 22: print s.sub_val.int_val ! raise error, "The sub-struct value (re-fetched) didnt persist!" if s.sub_val.array_val[0].int_val != 0 or str(s.sub_val.array_val[0].str_val) != "zero": print s.sub_val.array_val[0].int_val ! raise error, "The array element wasnt correct" s.sub_val.array_val[0].int_val = 99 s.sub_val.array_val[1].int_val = 66 --- 319,350 ---- try: vbtest.IntProperty = "One" ! raise error("Should have failed by now") except pythoncom.com_error, (hr, desc, exc, argErr): if hr != winerror.DISP_E_TYPEMISMATCH: ! raise error("Expected DISP_E_TYPEMISMATCH") s = vbtest.StructProperty if s.int_val != 99 or str(s.str_val) != "hello": ! raise error("The struct value was not correct") s.str_val = "Hi from Python" s.int_val = 11 if s.int_val != 11 or str(s.str_val) != "Hi from Python": ! raise error("The struct value didnt persist!") if s.sub_val.int_val != 66 or str(s.sub_val.str_val) != "sub hello": ! raise error("The sub-struct value was not correct") sub = s.sub_val sub.int_val = 22 if sub.int_val != 22: print sub.int_val ! raise error("The sub-struct value didnt persist!") if s.sub_val.int_val != 22: print s.sub_val.int_val ! raise error("The sub-struct value (re-fetched) didnt persist!") if s.sub_val.array_val[0].int_val != 0 or str(s.sub_val.array_val[0].str_val) != "zero": print s.sub_val.array_val[0].int_val ! raise error("The array element wasnt correct") s.sub_val.array_val[0].int_val = 99 s.sub_val.array_val[1].int_val = 66 *************** *** 352,356 **** s.sub_val.array_val[1].int_val != 66: print s.sub_val.array_val[0].int_val ! raise error, "The array element didnt persist." # Now pass the struct back to VB vbtest.StructProperty = s --- 352,356 ---- s.sub_val.array_val[1].int_val != 66: print s.sub_val.array_val[0].int_val ! raise error("The array element didnt persist.") # Now pass the struct back to VB vbtest.StructProperty = s *************** *** 358,364 **** s = vbtest.StructProperty if s.int_val != 11 or str(s.str_val) != "Hi from Python": ! raise error, "After sending to VB, the struct value didnt persist!" if s.sub_val.array_val[0].int_val != 99: ! raise error, "After sending to VB, the struct array value didnt persist!" # Now do some object equality tests. --- 358,364 ---- s = vbtest.StructProperty if s.int_val != 11 or str(s.str_val) != "Hi from Python": ! raise error("After sending to VB, the struct value didnt persist!") if s.sub_val.array_val[0].int_val != 99: ! raise error("After sending to VB, the struct array value didnt persist!") # Now do some object equality tests. *************** *** 398,402 **** try: s.bad_attribute ! raise RuntimeError, "Could get a bad attribute" except AttributeError: pass --- 398,402 ---- try: s.bad_attribute ! raise RuntimeError("Could get a bad attribute") except AttributeError: pass *************** *** 410,417 **** t = ob.GetInterfaceTester(2) if t.getn() != 2: ! raise error, "Initial value wrong" t.setn(3) if t.getn() != 3: ! raise error, "New value wrong" def DoTestAll(): --- 410,417 ---- t = ob.GetInterfaceTester(2) if t.getn() != 2: ! raise error("Initial value wrong") t.setn(3) if t.getn() != 3: ! raise error("New value wrong") def DoTestAll(): *************** *** 428,432 **** if not __debug__: ! raise RuntimeError, "This must be run in debug mode - we use assert!" try: DoTestAll() --- 428,432 ---- if not __debug__: ! raise RuntimeError("This must be run in debug mode - we use assert!") try: DoTestAll() Index: testall.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testall.py,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** testall.py 26 Nov 2008 01:27:40 -0000 1.29 --- testall.py 26 Nov 2008 08:39:33 -0000 1.30 *************** *** 2,8 **** import pythoncom import win32com.client ! from win32com.test.util import (CheckClean, TestCase, ! CapturingFunctionTestCase, ShellTestCase, ! TestLoader, TestRunner, RegisterPythonServer) import traceback import getopt --- 2,8 ---- import pythoncom import win32com.client ! from win32com.test.util import CheckClean, TestCase, \ ! CapturingFunctionTestCase, ShellTestCase, \ ! TestLoader, TestRunner, RegisterPythonServer import traceback import getopt |