[pywin32-checkins] pywin32/com/win32com/test testvb.py,1.24,1.25
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-12-19 02:16:46
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv14237/win32com/test Modified Files: testvb.py Log Message: py3k-friendly buffer handling plus more object comparison tests Index: testvb.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testvb.py,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** testvb.py 4 Dec 2008 03:38:20 -0000 1.24 --- testvb.py 19 Dec 2008 01:53:28 -0000 1.25 *************** *** 4,7 **** --- 4,8 ---- # + import sys import winerror import pythoncom, win32com.client, win32com.client.dynamic, win32com.client.gencache *************** *** 11,14 **** --- 12,21 ---- import traceback + def string_to_buffer(s): + if sys.version_info < (3,0): + return buffer(s) + else: + return memoryview(s.encode("ascii")) + # for debugging useDispatcher = None *************** *** 67,72 **** 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" --- 74,79 ---- if vbtest.VariantProperty != 10: raise error("Could not set the variant integer property correctly.") ! vbtest.VariantProperty = string_to_buffer('raw\0data') ! if vbtest.VariantProperty != string_to_buffer('raw\0data'): raise error("Could not set the variant buffer property correctly.") vbtest.StringProperty = "Hello from Python" *************** *** 279,284 **** try: vbtest.DoCallbackSafeArraySizeFail(callback_ob) ! except pythoncom.com_error, (hr, msg, exc, arg): ! assert exc[1] == "Python COM Server Internal Error", "Didnt get the correct exception - '%s'" % (exc,) if bUseGenerated: --- 286,291 ---- try: vbtest.DoCallbackSafeArraySizeFail(callback_ob) ! except pythoncom.com_error, exc: ! assert exc.excepinfo[1] == "Python COM Server Internal Error", "Didnt get the correct exception - '%s'" % (exc,) if bUseGenerated: *************** *** 313,318 **** 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") --- 320,325 ---- vbtest.IntProperty = "One" raise error("Should have failed by now") ! except pythoncom.com_error, exc: ! if exc.hresult != winerror.DISP_E_TYPEMISMATCH: raise error("Expected DISP_E_TYPEMISMATCH") *************** *** 395,401 **** pass m = s.__members__ ! assert m[0]=="int_val" and m[1]=="str_val" and m[2]=="ob_val" and m[3]=="sub_val" ! # NOTE - a COM error is _not_ acceptable here! print "Struct/Record tests passed" --- 402,421 ---- pass m = s.__members__ ! assert m[0]=="int_val" and m[1]=="str_val" and m[2]=="ob_val" and m[3]=="sub_val", m ! # Test attribute errors. ! try: ! s.foo ! raise RuntimeError("Expected attribute error") ! except AttributeError, exc: ! assert "foo" in str(exc), exc ! ! # test repr - it uses repr() of the sub-objects, so check it matches. ! expected = "com_struct(int_val=%r, str_val=%r, ob_val=%r, sub_val=%r)" % (s.int_val, s.str_val, s.ob_val, s.sub_val) ! if repr(s) != expected: ! print "Expected repr:", expected ! print "Actual repr :", repr(s) ! raise RuntimeError("repr() of record object failed") ! print "Struct/Record tests passed" *************** *** 408,416 **** --- 428,461 ---- raise error("New value wrong") + def TestObjectSemantics(ob): + # a convenient place to test some of our equality semantics + assert ob==ob._oleobj_ + assert not ob!=ob._oleobj_ + # same test again, but lhs and rhs reversed. + assert ob._oleobj_==ob + assert not ob._oleobj_!=ob + # same tests but against different pointers. COM identity rules should + # still ensure all works + assert ob._oleobj_==ob._oleobj_.QueryInterface(pythoncom.IID_IUnknown) + assert not ob._oleobj_!=ob._oleobj_.QueryInterface(pythoncom.IID_IUnknown) + + assert ob._oleobj_.QueryInterface(pythoncom.IID_IUnknown)==ob._oleobj_ + assert not ob._oleobj_.QueryInterface(pythoncom.IID_IUnknown)!=ob._oleobj_ + + assert ob._oleobj_==ob._oleobj_.QueryInterface(pythoncom.IID_IDispatch) + assert not ob._oleobj_!=ob._oleobj_.QueryInterface(pythoncom.IID_IDispatch) + + assert ob._oleobj_.QueryInterface(pythoncom.IID_IDispatch)==ob._oleobj_ + assert not ob._oleobj_.QueryInterface(pythoncom.IID_IDispatch)!=ob._oleobj_ + + print "Object semantic tests passed" + def DoTestAll(): o = win32com.client.Dispatch("PyCOMVBTest.Tester") + TestObjectSemantics(o) TestVB(o,1) o = win32com.client.dynamic.DumbDispatch("PyCOMVBTest.Tester") + TestObjectSemantics(o) TestVB(o,0) |