Update of /cvsroot/pywin32/pywin32/com/win32com/test
In directory sc8-pr-cvs1:/tmp/cvs-serv4790
Modified Files:
testWMI.py testStreams.py
Log Message:
Convert to unittest tests
Index: testWMI.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testWMI.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** testWMI.py 3 Jul 2003 03:45:18 -0000 1.1
--- testWMI.py 2 Nov 2003 10:04:06 -0000 1.2
***************
*** 1,9 ****
from win32com.client import GetObject
! def test():
! cses = GetObject("WinMgMts:").InstancesOf("Win32_Process")
! for cs in cses:
! print cs.Properties_("Caption").Value
if __name__=='__main__':
! test()
--- 1,16 ----
from win32com.client import GetObject
! import unittest
!
! class Simple(unittest.TestCase):
! def testit(self):
! cses = GetObject("WinMgMts:").InstancesOf("Win32_Process")
! vals = []
! for cs in cses:
! val = cs.Properties_("Caption").Value
! vals.append(val)
! self.failIf(len(vals)<5, "We only found %d processes!" % len(vals))
if __name__=='__main__':
! unittest.main()
!
Index: testStreams.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testStreams.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** testStreams.py 18 Nov 2002 11:20:07 -0000 1.2
--- testStreams.py 2 Nov 2003 10:04:07 -0000 1.3
***************
*** 3,26 ****
import util
class Persists:
_public_methods_ = [ 'GetClassID', 'IsDirty', 'Load', 'Save',
'GetSizeMax', 'InitNew' ]
_com_interfaces_ = [ pythoncom.IID_IPersistStreamInit ]
!
def GetClassID(self):
return pythoncom.IID_NULL
-
def IsDirty(self):
! return 1
!
def Load(self, stream):
! print "loaded:", stream.Read(26)
!
def Save(self, stream, clearDirty):
! stream.Write('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
! print "(saved state)"
!
def GetSizeMax(self):
! return 26
def InitNew(self):
--- 3,27 ----
import util
+ import unittest
+
class Persists:
_public_methods_ = [ 'GetClassID', 'IsDirty', 'Load', 'Save',
'GetSizeMax', 'InitNew' ]
_com_interfaces_ = [ pythoncom.IID_IPersistStreamInit ]
! def __init__(self):
! self.data = "abcdefg"
! self.dirty = 1
def GetClassID(self):
return pythoncom.IID_NULL
def IsDirty(self):
! return self.dirty
def Load(self, stream):
! self.data = stream.Read(26)
def Save(self, stream, clearDirty):
! stream.Write(self.data)
! if clearDirty:
! self.dirty = 0
def GetSizeMax(self):
! return 1024
def InitNew(self):
***************
*** 47,81 ****
! def test():
! mydata = 'abcdefghijklmnopqrstuvwxyz'
!
! # First test the objects just as Python objects...
! s = Stream(mydata)
! p = Persists()
!
! p.Load(s)
! p.Save(s, 0)
! print "new state:", s.data
!
! # reset the stream
! s.Write(mydata)
!
! # Wrap the Python objects as COM objects, and make the calls as if
! # they were non-Python COM objects.
! s2 = win32com.server.util.wrap(s, pythoncom.IID_IStream)
! p2 = win32com.server.util.wrap(p, pythoncom.IID_IPersistStreamInit)
! print "read:", s2.Read(26)
! s2.Write("kilroy was here")
! print "new state:", s.data
! # reset the stream
! s.Write(mydata)
! p2.Load(s2)
! p2.Save(s2, 0)
! print "new state:", s.data
if __name__=='__main__':
! test()
util.CheckClean()
--- 48,87 ----
! class StreamTest(unittest.TestCase):
! def _readWrite(self, data, write_stream, read_stream = None):
! if read_stream is None: read_stream = write_stream
! write_stream.Write(data)
! got = read_stream.Read(len(data))
! self.assertEqual(data, got)
! def testit(self):
! mydata = 'abcdefghijklmnopqrstuvwxyz'
!
! # First test the objects just as Python objects...
! s = Stream(mydata)
! p = Persists()
!
! p.Load(s)
! 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.
! s2 = win32com.server.util.wrap(s, pythoncom.IID_IStream)
! p2 = win32com.server.util.wrap(p, pythoncom.IID_IPersistStreamInit)
! self._readWrite(mydata, s, s)
! self._readWrite(mydata, s, s2)
! self._readWrite(mydata, s2, s)
! self._readWrite(mydata, s2, s2)
! self._readWrite("string with\0a NULL", s2, s2)
! # reset the stream
! s.Write(mydata)
! p2.Load(s2)
! p2.Save(s2, 0)
! self.assertEqual(s.data, mydata)
if __name__=='__main__':
! unittest.main()
util.CheckClean()
|