Update of /cvsroot/pywin32/pywin32/com/win32com/test
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4367/com/win32com/test
Modified Files:
testClipboard.py testShell.py testStreams.py testvb.py
Log Message:
Move most tests and demos to using pywin32_testutil helpers, particularly
for tests involving bytes and buffers. Some tests raise TestSkipped when
appropriate and other minor test fixes.
Index: testvb.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testvb.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** testvb.py 19 Dec 2008 01:53:28 -0000 1.25
--- testvb.py 7 Jan 2009 06:03:29 -0000 1.26
***************
*** 9,21 ****
from win32com.server.util import NewCollection, wrap
from win32com.test import util
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
--- 9,16 ----
from win32com.server.util import NewCollection, wrap
from win32com.test import util
+ from pywin32_testutil import str2memory
import traceback
# for debugging
useDispatcher = None
***************
*** 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"
--- 69,74 ----
if vbtest.VariantProperty != 10:
raise error("Could not set the variant integer property correctly.")
! vbtest.VariantProperty = str2memory('raw\0data')
! if vbtest.VariantProperty != str2memory('raw\0data'):
raise error("Could not set the variant buffer property correctly.")
vbtest.StringProperty = "Hello from Python"
Index: testStreams.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testStreams.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** testStreams.py 19 Dec 2008 01:52:15 -0000 1.8
--- testStreams.py 7 Jan 2009 06:03:29 -0000 1.9
***************
*** 4,7 ****
--- 4,8 ----
import unittest
+ from pywin32_testutil import str2bytes
class Persists:
***************
*** 10,14 ****
_com_interfaces_ = [ pythoncom.IID_IPersistStreamInit ]
def __init__(self):
! self.data = "abcdefg".encode("ascii")
self.dirty = 1
def GetClassID(self):
--- 11,15 ----
_com_interfaces_ = [ pythoncom.IID_IPersistStreamInit ]
def __init__(self):
! self.data = str2bytes("abcdefg")
self.dirty = 1
def GetClassID(self):
***************
*** 67,71 ****
"""
def Read(self, amount):
! return 'x'.encode('ascii')*(amount+1)
class StreamTest(win32com.test.util.TestCase):
--- 68,72 ----
"""
def Read(self, amount):
! return str2bytes('x')*(amount+1)
class StreamTest(win32com.test.util.TestCase):
***************
*** 81,85 ****
def testit(self):
! mydata = 'abcdefghijklmnopqrstuvwxyz'.encode('ascii')
# First test the objects just as Python objects...
--- 82,86 ----
def testit(self):
! mydata = str2bytes('abcdefghijklmnopqrstuvwxyz')
# First test the objects just as Python objects...
***************
*** 101,105 ****
self._readWrite(mydata, s2, s2)
! self._readWrite("string with\0a NULL".encode('ascii'), s2, s2)
# reset the stream
s.Write(mydata)
--- 102,106 ----
self._readWrite(mydata, s2, s2)
! self._readWrite(str2bytes("string with\0a NULL"), s2, s2)
# reset the stream
s.Write(mydata)
Index: testShell.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testShell.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** testShell.py 26 Nov 2008 01:27:40 -0000 1.12
--- testShell.py 7 Jan 2009 06:03:29 -0000 1.13
***************
*** 16,19 ****
--- 16,20 ----
import win32com.test.util
+ from pywin32_testutil import str2bytes
class ShellTester(win32com.test.util.TestCase):
***************
*** 75,94 ****
def testPIDL(self):
# A PIDL of "\1" is: cb pidl cb
! expect = "\03\00" "\1" "\0\0"
! self.assertEqual(shell.PIDLAsString(["\1"]), expect)
! self._rtPIDL(["\0"])
! self._rtPIDL(["\1", "\2", "\3"])
! self._rtPIDL(["\0" * 2048] * 2048)
# PIDL must be a list
self.assertRaises(TypeError, shell.PIDLAsString, "foo")
def testCIDA(self):
! self._rtCIDA(["\0"], [ ["\0"] ])
! self._rtCIDA(["\1"], [ ["\2"] ])
! self._rtCIDA(["\0"], [ ["\0"], ["\1"], ["\2"] ])
def testBadShortPIDL(self):
# A too-short child element: cb pidl cb
! pidl = "\01\00" "\1"
self.assertRaises(ValueError, shell.StringAsPIDL, pidl)
--- 76,95 ----
def testPIDL(self):
# A PIDL of "\1" is: cb pidl cb
! expect = str2bytes("\03\00" "\1" "\0\0")
! self.assertEqual(shell.PIDLAsString([str2bytes("\1")]), expect)
! self._rtPIDL([str2bytes("\0")])
! self._rtPIDL([str2bytes("\1"), str2bytes("\2"), str2bytes("\3")])
! self._rtPIDL([str2bytes("\0") * 2048] * 2048)
# PIDL must be a list
self.assertRaises(TypeError, shell.PIDLAsString, "foo")
def testCIDA(self):
! self._rtCIDA([str2bytes("\0")], [ [str2bytes("\0")] ])
! self._rtCIDA([str2bytes("\1")], [ [str2bytes("\2")] ])
! self._rtCIDA([str2bytes("\0")], [ [str2bytes("\0")], [str2bytes("\1")], [str2bytes("\2")] ])
def testBadShortPIDL(self):
# A too-short child element: cb pidl cb
! pidl = str2bytes("\01\00" "\1")
self.assertRaises(ValueError, shell.StringAsPIDL, pidl)
***************
*** 182,187 ****
self.src_name = os.path.join(tempfile.gettempdir(), "pywin32_testshell")
self.dest_name = os.path.join(tempfile.gettempdir(), "pywin32_testshell_dest")
! self.test_data = "Hello from\0Python"
! f=file(self.src_name, "wb")
f.write(self.test_data)
f.close()
--- 183,188 ----
self.src_name = os.path.join(tempfile.gettempdir(), "pywin32_testshell")
self.dest_name = os.path.join(tempfile.gettempdir(), "pywin32_testshell_dest")
! self.test_data = str2bytes("Hello from\0Python")
! f=open(self.src_name, "wb")
f.write(self.test_data)
f.close()
Index: testClipboard.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testClipboard.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** testClipboard.py 26 Nov 2008 01:20:23 -0000 1.3
--- testClipboard.py 7 Jan 2009 06:03:29 -0000 1.4
***************
*** 6,9 ****
--- 6,11 ----
import win32clipboard
+ from pywin32_testutil import str2bytes
+
from win32com.server.util import NewEnum, wrap
from win32com.server.exception import COMException
***************
*** 47,51 ****
ret_stg = pythoncom.STGMEDIUM()
# ensure always 'bytes' by encoding string.
! ret_stg.set(pythoncom.TYMED_HGLOBAL, self.strval.encode("ascii"))
elif cf == win32con.CF_UNICODETEXT:
ret_stg = pythoncom.STGMEDIUM()
--- 49,53 ----
ret_stg = pythoncom.STGMEDIUM()
# ensure always 'bytes' by encoding string.
! ret_stg.set(pythoncom.TYMED_HGLOBAL, str2bytes(self.strval))
elif cf == win32con.CF_UNICODETEXT:
ret_stg = pythoncom.STGMEDIUM()
***************
*** 111,116 ****
win32clipboard.OpenClipboard()
got = win32clipboard.GetClipboardData(win32con.CF_TEXT)
! # CF_TEXT gives bytes on py3k - use encode() to ensure that's true.
! expected = "Hello from Python".encode("ascii")
self.assertEqual(got, expected)
# Now check unicode
--- 113,118 ----
win32clipboard.OpenClipboard()
got = win32clipboard.GetClipboardData(win32con.CF_TEXT)
! # CF_TEXT gives bytes on py3k - use str2bytes() to ensure that's true.
! expected = str2bytes("Hello from Python")
self.assertEqual(got, expected)
# Now check unicode
***************
*** 121,125 ****
def testWin32ToCom(self):
# Set the data via the std win32 clipboard functions.
! val = "Hello again!".encode("ascii") # ensure always bytes, even in py3k
win32clipboard.OpenClipboard()
win32clipboard.SetClipboardData(win32con.CF_TEXT, val)
--- 123,127 ----
def testWin32ToCom(self):
# Set the data via the std win32 clipboard functions.
! val = str2bytes("Hello again!") # ensure always bytes, even in py3k
win32clipboard.OpenClipboard()
win32clipboard.SetClipboardData(win32con.CF_TEXT, val)
***************
*** 133,137 ****
# knowing if it meant to be a string, or a binary buffer, so
# it must return it too.
! self.failUnlessEqual(got, "Hello again!\0".encode("ascii"))
def testDataObjectFlush(self):
--- 135,139 ----
# knowing if it meant to be a string, or a binary buffer, so
# it must return it too.
! self.failUnlessEqual(got, str2bytes("Hello again!\0"))
def testDataObjectFlush(self):
|