Update of /cvsroot/pywin32/pywin32/com/win32com/test
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4261/com/win32com/test
Modified Files:
Tag: py3k
testAXScript.py testPyComTest.py testStreams.py testmakepy.py
testvb.py util.py
Log Message:
merge lots of changes (most via 2to3) from the trunk
Index: testPyComTest.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testPyComTest.py,v
retrieving revision 1.32.2.7
retrieving revision 1.32.2.8
diff -C2 -d -r1.32.2.7 -r1.32.2.8
*** testPyComTest.py 4 Dec 2008 07:32:05 -0000 1.32.2.7
--- testPyComTest.py 5 Jan 2009 12:51:27 -0000 1.32.2.8
***************
*** 3,12 ****
import sys; sys.coinit_flags=0 # Must be free-threaded!
! import win32api, types, pythoncom, time
import sys, os, win32com, win32com.client.connect
from win32com.test.util import CheckClean
! from win32com.client import constants
import win32com
! from .util import RegisterPythonServer
importMsg = "**** PyCOMTest is not installed ***\n PyCOMTest is a Python test specific COM client and server.\n It is likely this server is not installed on this machine\n To install the server, you must get the win32com sources\n and build it using MS Visual C++"
--- 3,12 ----
import sys; sys.coinit_flags=0 # Must be free-threaded!
! import win32api, pythoncom, time
import sys, os, win32com, win32com.client.connect
from win32com.test.util import CheckClean
! from win32com.client import constants, DispatchBaseClass
import win32com
! from win32com.test.util import RegisterPythonServer
importMsg = "**** PyCOMTest is not installed ***\n PyCOMTest is a Python test specific COM client and server.\n It is likely this server is not installed on this machine\n To install the server, you must get the win32com sources\n and build it using MS Visual C++"
***************
*** 33,36 ****
--- 33,45 ----
verbose = 0
+ # convert a normal int to a long int - used to avoid, eg, '1L' for py3k
+ # friendliness
+ def ensure_long(int_val):
+ if sys.version_info > (3,):
+ # py3k - no such thing as a 'long'
+ return int_val
+ # on py2x, we just use an expression that results in a long
+ return 0x100000000-0x100000000+int_val
+
def progress(*args):
if verbose:
***************
*** 180,184 ****
i1, i2 = o.GetMultipleInterfaces()
! if type(i1) != types.InstanceType or type(i2) != types.InstanceType:
# Yay - is now an instance returned!
raise error("GetMultipleInterfaces did not return instances - got '%s', '%s'" % (i1, i2))
--- 189,193 ----
i1, i2 = o.GetMultipleInterfaces()
! if not isinstance(i1, DispatchBaseClass) or not isinstance(i2, DispatchBaseClass):
# Yay - is now an instance returned!
raise error("GetMultipleInterfaces did not return instances - got '%s', '%s'" % (i1, i2))
***************
*** 212,216 ****
raise error("GetSetUnknown failed")
progress("Checking getting/passing IDispatch")
! if type(o.GetSetDispatch(o)) !=types.InstanceType:
raise error("GetSetDispatch failed")
progress("Checking getting/passing IDispatch of known type")
--- 221,225 ----
raise error("GetSetUnknown failed")
progress("Checking getting/passing IDispatch")
! if not isinstance(o.GetSetDispatch(o), DispatchBaseClass):
raise error("GetSetDispatch failed")
progress("Checking getting/passing IDispatch of known type")
***************
*** 223,227 ****
if o.GetSetVariant(o) != o:
raise error("GetSetVariant (dispatch) failed")
! for l in sys.maxint, sys.maxint+1, 1 << 65:
if o.GetSetVariant(l) != l:
raise error("GetSetVariant (long) failed")
--- 232,239 ----
if o.GetSetVariant(o) != o:
raise error("GetSetVariant (dispatch) failed")
! # We want to explicitly test > 32 bits. py3k has no 'maxint' and
! # 'maxsize+1' is no good on 64bit platforms as its 65 bits!
! big = 2147483647 # sys.maxint on py2k
! for l in big, big+1, 1 << 65:
if o.GetSetVariant(l) != l:
raise error("GetSetVariant (long) failed")
***************
*** 271,278 ****
TestApplyResult(o.Test6, (constants.WideAttr5,), constants.WideAttr5)
! TestConstant("ULongTest1", 0xFFFFFFFF)
! TestConstant("ULongTest2", 0x7FFFFFFF)
! TestConstant("LongTest1", -0x7FFFFFFF)
! TestConstant("LongTest2", 0x7FFFFFFF)
TestConstant("UCharTest", 255)
TestConstant("CharTest", -1)
--- 283,290 ----
TestApplyResult(o.Test6, (constants.WideAttr5,), constants.WideAttr5)
! TestConstant("ULongTest1", ensure_long(0xFFFFFFFF))
! TestConstant("ULongTest2", ensure_long(0x7FFFFFFF))
! TestConstant("LongTest1", ensure_long(-0x7FFFFFFF))
! TestConstant("LongTest2", ensure_long(0x7FFFFFFF))
TestConstant("UCharTest", 255)
TestConstant("CharTest", -1)
Index: util.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/util.py,v
retrieving revision 1.9.2.6
retrieving revision 1.9.2.7
diff -C2 -d -r1.9.2.6 -r1.9.2.7
*** util.py 11 Dec 2008 05:45:21 -0000 1.9.2.6
--- util.py 5 Jan 2009 12:51:27 -0000 1.9.2.7
***************
*** 187,191 ****
del i # created after we remembered the refcount!
# int division here means one or 2 stray references won't force
! # failure, but one per loop
lost = (gtrc() - trc) // self.num_leak_iters
if lost < 0:
--- 187,192 ----
del i # created after we remembered the refcount!
# int division here means one or 2 stray references won't force
! # failure, but one per loop
! gc.collect()
lost = (gtrc() - trc) // self.num_leak_iters
if lost < 0:
***************
*** 265,276 ****
self.emitted.append(record)
def setup_test_logger():
old_log = getattr(win32com, "logger", None)
! win32com.logger = logging.Logger('test')
! handler = LogHandler()
! win32com.logger.addHandler(handler)
return handler.emitted, old_log
def restore_test_logger(prev_logger):
if prev_logger is None:
del win32com.logger
--- 266,285 ----
self.emitted.append(record)
+ _win32com_logger = None
def setup_test_logger():
old_log = getattr(win32com, "logger", None)
! global _win32com_logger
! if _win32com_logger is None:
! _win32com_logger = logging.Logger('test')
! handler = LogHandler()
! _win32com_logger.addHandler(handler)
!
! win32com.logger = _win32com_logger
! handler = _win32com_logger.handlers[0]
! handler.emitted = []
return handler.emitted, old_log
def restore_test_logger(prev_logger):
+ assert prev_logger is None, "who needs this?"
if prev_logger is None:
del win32com.logger
***************
*** 322,331 ****
return "exec: " + cmd_repr
def testmain(*args, **kw):
new_kw = kw.copy()
if 'testLoader' not in new_kw:
new_kw['testLoader'] = TestLoader()
- if 'testRunner' not in new_kw:
- new_kw['testRunner'] = TestRunner()
unittest.main(*args, **new_kw)
CheckClean()
--- 331,344 ----
return "exec: " + cmd_repr
+ class TestProgram(unittest.TestProgram):
+ def runTests(self):
+ if self.testRunner is None:
+ self.testRunner = TestRunner(verbosity=self.verbosity)
+ unittest.TestProgram(self)
+
def testmain(*args, **kw):
new_kw = kw.copy()
if 'testLoader' not in new_kw:
new_kw['testLoader'] = TestLoader()
unittest.main(*args, **new_kw)
CheckClean()
Index: testStreams.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testStreams.py,v
retrieving revision 1.6.2.1
retrieving revision 1.6.2.2
diff -C2 -d -r1.6.2.1 -r1.6.2.2
*** testStreams.py 13 Sep 2008 12:27:42 -0000 1.6.2.1
--- testStreams.py 5 Jan 2009 12:51:27 -0000 1.6.2.2
***************
*** 10,14 ****
_com_interfaces_ = [ pythoncom.IID_IPersistStreamInit ]
def __init__(self):
! self.data = b"abcdefg"
self.dirty = 1
def GetClassID(self):
--- 10,14 ----
_com_interfaces_ = [ pythoncom.IID_IPersistStreamInit ]
def __init__(self):
! self.data = "abcdefg".encode("ascii")
self.dirty = 1
def GetClassID(self):
***************
*** 67,71 ****
"""
def Read(self, amount):
! return b'x'*(amount+1)
class StreamTest(win32com.test.util.TestCase):
--- 67,71 ----
"""
def Read(self, amount):
! return 'x'.encode('ascii')*(amount+1)
class StreamTest(win32com.test.util.TestCase):
***************
*** 81,85 ****
def testit(self):
! mydata = b'abcdefghijklmnopqrstuvwxyz'
# First test the objects just as Python objects...
--- 81,85 ----
def testit(self):
! mydata = 'abcdefghijklmnopqrstuvwxyz'.encode('ascii')
# First test the objects just as Python objects...
***************
*** 90,94 ****
p.Save(s, 0)
self.assertEqual(s.data, mydata)
!
# Wrap the Python objects as COM objects, and make the calls as if
# they were non-Python COM objects.
--- 90,94 ----
p.Save(s, 0)
self.assertEqual(s.data, mydata)
!
# Wrap the Python objects as COM objects, and make the calls as if
# they were non-Python COM objects.
***************
*** 101,105 ****
self._readWrite(mydata, s2, s2)
! self._readWrite(b"string with\0a NULL", s2, s2)
# reset the stream
s.Write(mydata)
--- 101,105 ----
self._readWrite(mydata, s2, s2)
! self._readWrite("string with\0a NULL".encode('ascii'), s2, s2)
# reset the stream
s.Write(mydata)
***************
*** 108,111 ****
--- 108,112 ----
self.assertEqual(s.data, mydata)
+ def testerrors(self):
# setup a test logger to capture tracebacks etc.
records, old_log = win32com.test.util.setup_test_logger()
Index: testAXScript.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testAXScript.py,v
retrieving revision 1.7.4.3
retrieving revision 1.7.4.4
diff -C2 -d -r1.7.4.3 -r1.7.4.4
*** testAXScript.py 27 Nov 2008 11:31:05 -0000 1.7.4.3
--- testAXScript.py 5 Jan 2009 12:51:27 -0000 1.7.4.4
***************
*** 13,17 ****
def setUp(self):
file = win32api.GetFullPathName(os.path.join(win32com.axscript.client.__path__[0], "pyscript.py"))
! from .util import RegisterPythonServer
self.verbose = verbose
RegisterPythonServer(file, 'python', verbose=self.verbose)
--- 13,17 ----
def setUp(self):
file = win32api.GetFullPathName(os.path.join(win32com.axscript.client.__path__[0], "pyscript.py"))
! from win32com.test.util import RegisterPythonServer
self.verbose = verbose
RegisterPythonServer(file, 'python', verbose=self.verbose)
Index: testvb.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testvb.py,v
retrieving revision 1.20.4.5
retrieving revision 1.20.4.6
diff -C2 -d -r1.20.4.5 -r1.20.4.6
*** testvb.py 19 Dec 2008 02:33:56 -0000 1.20.4.5
--- testvb.py 5 Jan 2009 12:51:27 -0000 1.20.4.6
***************
*** 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,75 ****
if vbtest.VariantProperty != 10:
raise error("Could not set the variant integer property correctly.")
! vbtest.VariantProperty = b'raw\0data'
! # FIX ME!!!
! print("Skipping bytes/variant tests 'cos they don't work :(")
! #if vbtest.VariantProperty != b'raw\0data':
! # raise error("Could not set the variant buffer property correctly: %r" % vbtest.VariantProperty)
vbtest.StringProperty = "Hello from Python"
if vbtest.StringProperty != "Hello from Python":
--- 74,80 ----
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"
if vbtest.StringProperty != "Hello from Python":
***************
*** 82,87 ****
raise error("Could not set the variant property to an array of floats correctly - '%s'." % (vbtest.VariantProperty,))
- TestStructs(vbtest)
TestArrays(vbtest, bUseGenerated)
TestCollections(vbtest)
--- 87,92 ----
raise error("Could not set the variant property to an array of floats correctly - '%s'." % (vbtest.VariantProperty,))
TestArrays(vbtest, bUseGenerated)
+ TestStructs(vbtest)
TestCollections(vbtest)
***************
*** 397,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"
# Test attribute errors.
--- 402,406 ----
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.
***************
*** 408,412 ****
# 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)
- print("REPR is", repr(s))
if repr(s) != expected:
print("Expected repr:", expected)
--- 413,416 ----
***************
*** 424,432 ****
--- 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)
Index: testmakepy.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testmakepy.py,v
retrieving revision 1.5.4.2
retrieving revision 1.5.4.3
diff -C2 -d -r1.5.4.2 -r1.5.4.3
*** testmakepy.py 4 Dec 2008 05:08:41 -0000 1.5.4.2
--- testmakepy.py 5 Jan 2009 12:51:27 -0000 1.5.4.3
***************
*** 26,30 ****
# Ignore these 2 errors, as the are very common and can obscure
# useful warnings.
! if details[0] not in [winerror.TYPE_E_CANTLOADLIBRARY,
winerror.TYPE_E_LIBNOTREGISTERED]:
print("** COM error on", info.desc)
--- 26,30 ----
# Ignore these 2 errors, as the are very common and can obscure
# useful warnings.
! if details.hresult not in [winerror.TYPE_E_CANTLOADLIBRARY,
winerror.TYPE_E_LIBNOTREGISTERED]:
print("** COM error on", info.desc)
|