home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activepython / ActivePython-2.1.1.msi / Python21_win32com_test_util.py < prev    next >
Encoding:
Python Source  |  2001-07-26  |  955 b   |  37 lines

  1. import sys
  2. import string
  3. from pythoncom import _GetInterfaceCount, _GetGatewayCount
  4.  
  5. def CheckClean():
  6.     # Ensure no lingering exceptions - Python should have zero outstanding
  7.     # COM objects
  8.     sys.exc_traceback = sys.exc_value = sys.exc_type = None
  9.     c = _GetInterfaceCount()
  10.     if c:
  11.         print "Warning - %d com interface objects still alive" % c
  12.     c = _GetGatewayCount()
  13.     if c:
  14.         print "Warning - %d com gateway objects still alive" % c
  15.  
  16. class CaptureWriter:
  17.     def __init__(self):
  18.         self.old = None
  19.         self.clear()
  20.     def capture(self):
  21.         self.clear()
  22.         self.old = sys.stdout
  23.         sys.stdout = self
  24.     def release(self):
  25.         if self.old:
  26.             sys.stdout = self.old
  27.             self.old = None
  28.     def clear(self):
  29.         self.captured = []
  30.     def write(self, msg):
  31.         self.captured.append(msg)
  32.     def get_captured(self):
  33.         return string.join(self.captured,"")
  34.     def get_num_lines_captured(self):
  35.         return len(string.split(string.join(self.captured, ""),"\n"))
  36.  
  37.