Update of /cvsroot/pywin32/pywin32/com/win32com/test
In directory sc8-pr-cvs1:/tmp/cvs-serv29948
Modified Files:
testvb.py
Log Message:
Add some more collection tests, to ensure we don't break things while
fixing them :)
Index: testvb.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testvb.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** testvb.py 1 Mar 2003 00:13:27 -0000 1.13
--- testvb.py 20 Oct 2003 10:01:45 -0000 1.14
***************
*** 116,119 ****
--- 116,120 ----
TestStructs(vbtest)
+ TestCollections(vbtest)
assert vbtest.TakeByValObject(vbtest)==vbtest
***************
*** 218,221 ****
--- 219,270 ----
# if ret != (0,1):
# raise error, "Could not increment the integer with default arg- "+str(ret)
+
+ def _DoTestCollection(vbtest, col_name, expected):
+ # It sucks that some objects allow "Count()", but others "Count"
+ def _getcount(ob):
+ r = getattr(ob, "Count")
+ if type(r)!=type(0):
+ return r()
+ return r
+ c = getattr(vbtest, col_name)
+ check = []
+ for item in c:
+ check.append(item)
+ if check != list(expected):
+ raise error, "Collection %s didn't have %r (had %r)" % (col_name, expected, 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)
+ check = []
+ for i in range(_getcount(c)):
+ 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.
+ c = getattr(vbtest, col_name)._NewEnum()
+ check = []
+ while 1:
+ n = c.Next()
+ if not n:
+ break
+ 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):
+ _DoTestCollection(vbtest, "CollectionProperty", [1,"Two", "3"])
+ # 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", [])
+ vbtest.EnumerableCollectionProperty.Add(1)
+ vbtest.EnumerableCollectionProperty.Add("Two")
+ vbtest.EnumerableCollectionProperty.Add("3")
+ _DoTestCollection(vbtest, "EnumerableCollectionProperty", [1,"Two", "3"])
def TestStructs(vbtest):
|