[pywin32-checkins] pywin32/com/win32comext/axscript/test testHost.py, 1.4, 1.5
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2007-05-07 02:27:51
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/axscript/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17342/test Modified Files: testHost.py Log Message: Correct a number of issues with unicode, particularly errors. Index: testHost.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/axscript/test/testHost.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** testHost.py 18 Jun 2006 13:09:35 -0000 1.4 --- testHost.py 7 May 2007 02:27:44 -0000 1.5 *************** *** 6,9 **** --- 6,11 ---- from win32com.server import util, connect import win32com.server.policy + from win32com.client.dynamic import Dispatch + from win32com.server.exception import COMException import unittest *************** *** 14,24 **** class MySite(axsite.AXSite): def __init__(self, *args): ! self.seen_exception = 0 axsite.AXSite.__init__(self, *args) def OnScriptError(self, error): ! exc = error.GetExceptionInfo() context, line, char = error.GetSourcePosition() - self.seen_exception = 1 if not verbose: return --- 16,25 ---- class MySite(axsite.AXSite): def __init__(self, *args): ! self.exception_seen = None axsite.AXSite.__init__(self, *args) def OnScriptError(self, error): ! self.exception_seen = exc = error.GetExceptionInfo() context, line, char = error.GetSourcePosition() if not verbose: return *************** *** 34,39 **** class MyCollection(util.Collection): ! def _NewEnum(self): ! return util.Collection._NewEnum(self) class Test: --- 35,40 ---- class MyCollection(util.Collection): ! def _NewEnum(self): ! return util.Collection._NewEnum(self) class Test: *************** *** 124,127 **** --- 125,133 ---- """ + PyScript_Exc = u"""\ + def hello(arg1): + raise RuntimeError, "exc with extended \xa9har" + """ + ErrScript = """\ bad code for everyone! *************** *** 145,171 **** class EngineTester(win32com.test.util.TestCase): ! def _TestEngine(self, engineName, code, bShouldWork = 1): echoer = Test() model = { 'test' : util.wrap(echoer), } try: ! try: ! site = MySite(model) ! engine = site._AddEngine(engineName) ! _CheckEngineState(site, engineName, axscript.SCRIPTSTATE_INITIALIZED) ! engine.AddCode(code) ! engine.Start() ! _CheckEngineState(site, engineName, axscript.SCRIPTSTATE_STARTED) ! finally: ! if bShouldWork: ! self.failUnless(not site.seen_exception, "Script site should not have seen an exception") ! else: ! self.failUnless(site.seen_exception, "Script site should have seen an exception") self.failUnless(not echoer.fail_called, "Fail should not have been called") # Now call into the scripts IDispatch - from win32com.client.dynamic import Dispatch ob = Dispatch(engine.GetScriptDispatch()) ! ob.hello("Goober") self.assertEqual(echoer.last, "Goober") --- 151,179 ---- class EngineTester(win32com.test.util.TestCase): ! def _TestEngine(self, engineName, code, expected_exc = None): echoer = Test() model = { 'test' : util.wrap(echoer), } + site = MySite(model) + engine = site._AddEngine(engineName) try: ! _CheckEngineState(site, engineName, axscript.SCRIPTSTATE_INITIALIZED) ! engine.AddCode(code) ! engine.Start() ! _CheckEngineState(site, engineName, axscript.SCRIPTSTATE_STARTED) self.failUnless(not echoer.fail_called, "Fail should not have been called") # Now call into the scripts IDispatch ob = Dispatch(engine.GetScriptDispatch()) ! try: ! ob.hello("Goober") ! self.failUnless(expected_exc is None, ! "Expected %r, but no exception seen" % (expected_exc,)) ! except pythoncom.com_error: ! if expected_exc is None: ! self.fail("Unexpected failure from script code: %s" % (site.exception_seen,)) ! if expected_exc not in site.exception_seen[2]: ! self.fail("Could not find %r in %r" % (expected_exc, site.exception_seen[2])) ! return self.assertEqual(echoer.last, "Goober") *************** *** 204,213 **** def testPython(self): self._TestEngine("Python", PyScript) def testVBExceptions(self): self.assertRaises(pythoncom.com_error, ! self._TestEngine, "VBScript", ErrScript, 0) def testPythonExceptions(self): ! self.assertRaises(pythoncom.com_error, ! self._TestEngine, "Python", ErrScript, 0) if __name__ == '__main__': --- 212,223 ---- def testPython(self): self._TestEngine("Python", PyScript) + def testPythonUnicodeError(self): + self._TestEngine("Python", PyScript) def testVBExceptions(self): self.assertRaises(pythoncom.com_error, ! self._TestEngine, "VBScript", ErrScript) def testPythonExceptions(self): ! expected = u"RuntimeError: exc with extended \xa9har" ! self._TestEngine("Python", PyScript_Exc, expected) if __name__ == '__main__': |