home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import pythoncom
- from win32com.server.exception import COMException
- from win32com.server.util import wrap
- from win32com.client import Dispatch
- import winerror
- from win32com.test.util import CaptureWriter
-
- class error(Exception):
-
- def __init__(self, msg, com_exception = None):
- Exception.__init__(self, msg, str(com_exception))
-
-
-
- class TestServer:
- _public_methods_ = [
- 'Clone',
- 'Commit',
- 'LockRegion',
- 'Read']
- _com_interfaces_ = [
- pythoncom.IID_IStream]
-
- def Clone(self):
- raise COMException('Not today', scode = winerror.E_UNEXPECTED)
-
-
- def Commit(self, flags):
- raise 'foo'
-
-
-
- def test():
- com_server = wrap(TestServer(), pythoncom.IID_IStream)
-
- try:
- com_server.Clone()
- except pythoncom.com_error:
- com_exc = None
- (hr, desc, exc, argErr) = com_exc
- if hr != winerror.E_UNEXPECTED:
- raise error('Calling the object natively did not yield the correct scode', com_exc)
- hr != winerror.E_UNEXPECTED
- if not exc or exc[-1] != winerror.E_UNEXPECTED:
- raise error('The scode element of the exception tuple did not yield the correct scode', com_exc)
- exc[-1] != winerror.E_UNEXPECTED
- if exc[2] != 'Not today':
- raise error('The description in the exception tuple did not yield the correct string', com_exc)
- exc[2] != 'Not today'
-
- cap = CaptureWriter()
-
- try:
- cap.capture()
-
- try:
- com_server.Commit(0)
- finally:
- cap.release()
-
- except pythoncom.com_error:
- com_exc = None
- (hr, desc, exc, argErr) = com_exc
- if hr != winerror.E_FAIL:
- raise error('The hresult was not E_FAIL for an internal error', com_exc)
- hr != winerror.E_FAIL
- if exc[1] != 'Python COM Server Internal Error':
- raise error('The description in the exception tuple did not yield the correct string', com_exc)
- exc[1] != 'Python COM Server Internal Error'
-
- if cap.get_captured().find('Traceback') < 0:
- raise error('Could not find a traceback in stderr: %r' % (cap.get_captured(),))
- cap.get_captured().find('Traceback') < 0
- com_server = Dispatch(wrap(TestServer()))
-
- try:
- com_server.Clone()
- except pythoncom.com_error:
- com_exc = None
- (hr, desc, exc, argErr) = com_exc
- if hr != winerror.DISP_E_EXCEPTION:
- raise error('Calling the object via IDispatch did not yield the correct scode', com_exc)
- hr != winerror.DISP_E_EXCEPTION
- if not exc or exc[-1] != winerror.E_UNEXPECTED:
- raise error('The scode element of the exception tuple did not yield the correct scode', com_exc)
- exc[-1] != winerror.E_UNEXPECTED
- if exc[2] != 'Not today':
- raise error('The description in the exception tuple did not yield the correct string', com_exc)
- exc[2] != 'Not today'
-
- cap.clear()
-
- try:
- cap.capture()
-
- try:
- com_server.Commit(0)
- finally:
- cap.release()
-
- except pythoncom.com_error:
- com_exc = None
- (hr, desc, exc, argErr) = com_exc
- if hr != winerror.DISP_E_EXCEPTION:
- raise error('Calling the object via IDispatch did not yield the correct scode', com_exc)
- hr != winerror.DISP_E_EXCEPTION
- if not exc or exc[-1] != winerror.E_FAIL:
- raise error('The scode element of the exception tuple did not yield the correct scode', com_exc)
- exc[-1] != winerror.E_FAIL
- if exc[1] != 'Python COM Server Internal Error':
- raise error('The description in the exception tuple did not yield the correct string', com_exc)
- exc[1] != 'Python COM Server Internal Error'
-
- if cap.get_captured().find('Traceback') < 0:
- raise error('Could not find a traceback in stderr: %r' % (cap.get_captured(),))
- cap.get_captured().find('Traceback') < 0
-
-
- try:
- import logging
- except ImportError:
- logging = None
-
- if logging is not None:
- import win32com
-
- class TestLogHandler(logging.Handler):
-
- def __init__(self):
- self.num_emits = 0
- logging.Handler.__init__(self)
-
-
- def emit(self, record):
- self.num_emits += 1
- return None
- print '--- record start'
- print self.format(record)
- print '--- record end'
-
-
-
- def testLogger():
- handler = TestLogHandler()
- formatter = logging.Formatter('%(message)s')
- handler.setFormatter(formatter)
- log = logging.getLogger('win32com_test')
- log.addHandler(handler)
- win32com.logger = log
- com_server = wrap(TestServer(), pythoncom.IID_IStream)
-
- try:
- com_server.Commit(0)
- raise RuntimeError, 'should have failed'
- except pythoncom.error:
- pass
-
- handler.num_emits = 0
- com_server = Dispatch(wrap(TestServer()))
-
- try:
- com_server.Commit(0)
- raise RuntimeError, 'should have failed'
- except pythoncom.error:
- pass
-
-
-
- if __name__ == '__main__':
- test()
- if logging is not None:
- testLogger()
-
- from util import CheckClean
- CheckClean()
- print 'error semantic tests worked'
-
-