home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2724 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.9 KB  |  181 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import pythoncom
  5. from win32com.server.exception import COMException
  6. from win32com.server.util import wrap
  7. from win32com.client import Dispatch
  8. import winerror
  9. from win32com.test.util import CaptureWriter
  10.  
  11. class error(Exception):
  12.     
  13.     def __init__(self, msg, com_exception = None):
  14.         Exception.__init__(self, msg, str(com_exception))
  15.  
  16.  
  17.  
  18. class TestServer:
  19.     _public_methods_ = [
  20.         'Clone',
  21.         'Commit',
  22.         'LockRegion',
  23.         'Read']
  24.     _com_interfaces_ = [
  25.         pythoncom.IID_IStream]
  26.     
  27.     def Clone(self):
  28.         raise COMException('Not today', scode = winerror.E_UNEXPECTED)
  29.  
  30.     
  31.     def Commit(self, flags):
  32.         raise 'foo'
  33.  
  34.  
  35.  
  36. def test():
  37.     com_server = wrap(TestServer(), pythoncom.IID_IStream)
  38.     
  39.     try:
  40.         com_server.Clone()
  41.     except pythoncom.com_error:
  42.         com_exc = None
  43.         (hr, desc, exc, argErr) = com_exc
  44.         if hr != winerror.E_UNEXPECTED:
  45.             raise error('Calling the object natively did not yield the correct scode', com_exc)
  46.         hr != winerror.E_UNEXPECTED
  47.         if not exc or exc[-1] != winerror.E_UNEXPECTED:
  48.             raise error('The scode element of the exception tuple did not yield the correct scode', com_exc)
  49.         exc[-1] != winerror.E_UNEXPECTED
  50.         if exc[2] != 'Not today':
  51.             raise error('The description in the exception tuple did not yield the correct string', com_exc)
  52.         exc[2] != 'Not today'
  53.  
  54.     cap = CaptureWriter()
  55.     
  56.     try:
  57.         cap.capture()
  58.         
  59.         try:
  60.             com_server.Commit(0)
  61.         finally:
  62.             cap.release()
  63.  
  64.     except pythoncom.com_error:
  65.         com_exc = None
  66.         (hr, desc, exc, argErr) = com_exc
  67.         if hr != winerror.E_FAIL:
  68.             raise error('The hresult was not E_FAIL for an internal error', com_exc)
  69.         hr != winerror.E_FAIL
  70.         if exc[1] != 'Python COM Server Internal Error':
  71.             raise error('The description in the exception tuple did not yield the correct string', com_exc)
  72.         exc[1] != 'Python COM Server Internal Error'
  73.  
  74.     if cap.get_captured().find('Traceback') < 0:
  75.         raise error('Could not find a traceback in stderr: %r' % (cap.get_captured(),))
  76.     cap.get_captured().find('Traceback') < 0
  77.     com_server = Dispatch(wrap(TestServer()))
  78.     
  79.     try:
  80.         com_server.Clone()
  81.     except pythoncom.com_error:
  82.         com_exc = None
  83.         (hr, desc, exc, argErr) = com_exc
  84.         if hr != winerror.DISP_E_EXCEPTION:
  85.             raise error('Calling the object via IDispatch did not yield the correct scode', com_exc)
  86.         hr != winerror.DISP_E_EXCEPTION
  87.         if not exc or exc[-1] != winerror.E_UNEXPECTED:
  88.             raise error('The scode element of the exception tuple did not yield the correct scode', com_exc)
  89.         exc[-1] != winerror.E_UNEXPECTED
  90.         if exc[2] != 'Not today':
  91.             raise error('The description in the exception tuple did not yield the correct string', com_exc)
  92.         exc[2] != 'Not today'
  93.  
  94.     cap.clear()
  95.     
  96.     try:
  97.         cap.capture()
  98.         
  99.         try:
  100.             com_server.Commit(0)
  101.         finally:
  102.             cap.release()
  103.  
  104.     except pythoncom.com_error:
  105.         com_exc = None
  106.         (hr, desc, exc, argErr) = com_exc
  107.         if hr != winerror.DISP_E_EXCEPTION:
  108.             raise error('Calling the object via IDispatch did not yield the correct scode', com_exc)
  109.         hr != winerror.DISP_E_EXCEPTION
  110.         if not exc or exc[-1] != winerror.E_FAIL:
  111.             raise error('The scode element of the exception tuple did not yield the correct scode', com_exc)
  112.         exc[-1] != winerror.E_FAIL
  113.         if exc[1] != 'Python COM Server Internal Error':
  114.             raise error('The description in the exception tuple did not yield the correct string', com_exc)
  115.         exc[1] != 'Python COM Server Internal Error'
  116.  
  117.     if cap.get_captured().find('Traceback') < 0:
  118.         raise error('Could not find a traceback in stderr: %r' % (cap.get_captured(),))
  119.     cap.get_captured().find('Traceback') < 0
  120.  
  121.  
  122. try:
  123.     import logging
  124. except ImportError:
  125.     logging = None
  126.  
  127. if logging is not None:
  128.     import win32com
  129.     
  130.     class TestLogHandler(logging.Handler):
  131.         
  132.         def __init__(self):
  133.             self.num_emits = 0
  134.             logging.Handler.__init__(self)
  135.  
  136.         
  137.         def emit(self, record):
  138.             self.num_emits += 1
  139.             return None
  140.             print '--- record start'
  141.             print self.format(record)
  142.             print '--- record end'
  143.  
  144.  
  145.     
  146.     def testLogger():
  147.         handler = TestLogHandler()
  148.         formatter = logging.Formatter('%(message)s')
  149.         handler.setFormatter(formatter)
  150.         log = logging.getLogger('win32com_test')
  151.         log.addHandler(handler)
  152.         win32com.logger = log
  153.         com_server = wrap(TestServer(), pythoncom.IID_IStream)
  154.         
  155.         try:
  156.             com_server.Commit(0)
  157.             raise RuntimeError, 'should have failed'
  158.         except pythoncom.error:
  159.             pass
  160.  
  161.         handler.num_emits = 0
  162.         com_server = Dispatch(wrap(TestServer()))
  163.         
  164.         try:
  165.             com_server.Commit(0)
  166.             raise RuntimeError, 'should have failed'
  167.         except pythoncom.error:
  168.             pass
  169.  
  170.  
  171.  
  172. if __name__ == '__main__':
  173.     test()
  174.     if logging is not None:
  175.         testLogger()
  176.     
  177.     from util import CheckClean
  178.     CheckClean()
  179.     print 'error semantic tests worked'
  180.  
  181.