[svn r63566] the InternalException event class bites the dust.
--HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									d1946ae978
								
							
						
					
					
						commit
						45e0499f10
					
				|  | @ -140,7 +140,7 @@ class DSession(Session): | |||
|         except KeyboardInterrupt: | ||||
|             exitstatus = outcome.EXIT_INTERRUPTED | ||||
|         except: | ||||
|             self.bus.notify("internalerror", event.InternalException()) | ||||
|             self.config.pytestplugins.notify_exception() | ||||
|             exitstatus = outcome.EXIT_INTERNALERROR | ||||
|         self.config.bus.unregister(loopstate) | ||||
|         if exitstatus == 0 and self._testsfailed: | ||||
|  |  | |||
|  | @ -109,7 +109,7 @@ class TestMasterSlaveConnection: | |||
|         node = mysetup.makenode(item.config) | ||||
|         node.channel.close() | ||||
|         py.test.raises(IOError, "node.send(item)") | ||||
|         #ev = self.geteventargs(event.InternalException) | ||||
|         #ev = self.getevents("internalerror") | ||||
|         #assert ev.excinfo.errisinstance(IOError) | ||||
| 
 | ||||
|     def test_send_one(self, testdir, mysetup): | ||||
|  |  | |||
|  | @ -63,7 +63,7 @@ class TXNode(object): | |||
|         except: | ||||
|             excinfo = py.code.ExceptionInfo() | ||||
|             print "!" * 20, excinfo | ||||
|             self.notify("internalerror", event.InternalException(excinfo)) | ||||
|             self.notify_internal(excinfo) | ||||
| 
 | ||||
|     def send(self, item): | ||||
|         assert item is not None | ||||
|  | @ -127,7 +127,8 @@ class SlaveNode(object): | |||
|         except KeyboardInterrupt: | ||||
|             raise | ||||
|         except: | ||||
|             self.sendevent("internalerror", event.InternalException()) | ||||
|             er = py.code.ExceptionInfo().getrepr(funcargs=True, showlocals=True) | ||||
|             self.sendevent("internalerror", excrepr=er) | ||||
|             raise | ||||
| 
 | ||||
|     def runtest(self, item): | ||||
|  |  | |||
|  | @ -18,16 +18,6 @@ def timestamp(): | |||
| class NOP(BaseEvent): | ||||
|     pass | ||||
| 
 | ||||
| # ---------------------------------------------------------------------- | ||||
| # Basic Live Reporting Events  | ||||
| # ---------------------------------------------------------------------- | ||||
| 
 | ||||
| class InternalException(BaseEvent): | ||||
|     def __init__(self, excinfo=None): | ||||
|         if excinfo is None: | ||||
|             excinfo = py.code.ExceptionInfo() | ||||
|         self.repr = excinfo.getrepr(funcargs=True, showlocals=True) | ||||
| 
 | ||||
| # ---------------------------------------------------------------------- | ||||
| # Events related to collecting and executing test Items  | ||||
| # ---------------------------------------------------------------------- | ||||
|  | @ -36,7 +26,6 @@ class Deselected(BaseEvent): | |||
|     def __init__(self, items): | ||||
|         self.items = items  | ||||
| 
 | ||||
| 
 | ||||
| class BaseReport(BaseEvent): | ||||
|     def toterminal(self, out): | ||||
|         longrepr = self.longrepr  | ||||
|  |  | |||
|  | @ -73,7 +73,7 @@ class Events: | |||
|     def pyevent__trace(self, category, msg): | ||||
|         """ called for tracing events. """ | ||||
| 
 | ||||
|     def pyevent__internalerror(self, event): | ||||
|     def pyevent__internalerror(self, excrepr): | ||||
|         """ called for internal errors. """ | ||||
| 
 | ||||
|     def pyevent__itemstart(self, item, node=None): | ||||
|  |  | |||
|  | @ -264,7 +264,7 @@ class ParsedEvent: | |||
|         self.__dict__ = locals.copy() | ||||
| 
 | ||||
|     def __repr__(self): | ||||
|         return "<Event %r>" %(self.__dict__,) | ||||
|         return "<ParsedEvent %r>" %(self.__dict__,) | ||||
| 
 | ||||
| class EventRecorder(object): | ||||
|     def __init__(self, pyplugins, debug=False): # True): | ||||
|  | @ -288,6 +288,7 @@ class EventRecorder(object): | |||
|         raise KeyError("popevent: %r not found in %r"  %(name, self.events)) | ||||
| 
 | ||||
|     def getevents(self, eventname): | ||||
|         """ return list of ParsedEvent instances matching the given eventname. """ | ||||
|         method = self.geteventmethod(eventname) | ||||
|         l = [] | ||||
|         for event in self.events: | ||||
|  |  | |||
|  | @ -178,10 +178,10 @@ class ResultDB(object): | |||
|         if not event.passed: | ||||
|             self.log_outcome(event) | ||||
| 
 | ||||
|     def pyevent__internalerror(self, event): | ||||
|         path = event.repr.reprcrash.path # fishing :( | ||||
|         self.write_log_entry(event, '!', path, str(event.repr)) | ||||
| 
 | ||||
|     def pyevent__internalerror(self, excrepr): | ||||
|         path = excrepr.reprcrash.path  | ||||
|         XXX # we don't have an event | ||||
|         self.write_log_entry(event, '!', path, str(excrepr)) | ||||
| 
 | ||||
| SQL_CREATE_TABLES = """ | ||||
| create table pytest_results ( | ||||
|  | @ -368,9 +368,9 @@ class TestWithFunctionIntegration: | |||
|         try: | ||||
|             raise ValueError | ||||
|         except ValueError: | ||||
|             excinfo = event.InternalException() | ||||
|             excinfo = py.code.ExceptionInfo() | ||||
|         reslog = ResultDB(StringIO.StringIO())         | ||||
|         reslog.pyevent("internalerror", (excinfo,), {}) | ||||
|         reslog.pyevent("internalerror", (excinfo.getrepr(),), {}) | ||||
|         entry = reslog.logfile.getvalue() | ||||
|         entry_lines = entry.splitlines() | ||||
| 
 | ||||
|  |  | |||
|  | @ -90,8 +90,9 @@ class ResultLog(object): | |||
|             if not event.passed: | ||||
|                 self.log_outcome(event) | ||||
|         elif eventname == "internalerror": | ||||
|             path = event.repr.reprcrash.path # fishing :( | ||||
|             self.write_log_entry('!', path, str(event.repr)) | ||||
|             excrepr = args[0] | ||||
|             path = excrepr.reprcrash.path # fishing :( | ||||
|             self.write_log_entry('!', path, str(excrepr)) | ||||
| 
 | ||||
| 
 | ||||
| # =============================================================================== | ||||
|  | @ -224,9 +225,9 @@ class TestWithFunctionIntegration: | |||
|         try: | ||||
|             raise ValueError | ||||
|         except ValueError: | ||||
|             excinfo = event.InternalException() | ||||
|             excinfo = py.code.ExceptionInfo() | ||||
|         reslog = ResultLog(StringIO.StringIO())         | ||||
|         reslog.pyevent("internalerror", (excinfo,), {}) | ||||
|         reslog.pyevent("internalerror", (excinfo.getrepr(),), {}) | ||||
|         entry = reslog.logfile.getvalue() | ||||
|         entry_lines = entry.splitlines() | ||||
| 
 | ||||
|  |  | |||
|  | @ -82,9 +82,9 @@ class TerminalReporter: | |||
|         else:  | ||||
|             return "???", dict(red=True) | ||||
| 
 | ||||
|     def pyevent__internalerror(self, event): | ||||
|         for line in str(event.repr).split("\n"): | ||||
|             self.write_line("InternalException: " + line) | ||||
|     def pyevent__internalerror(self, excrepr): | ||||
|         for line in str(excrepr).split("\n"): | ||||
|             self.write_line("INTERNALERROR> " + line) | ||||
| 
 | ||||
|     def pyevent__gwmanage_newgateway(self, gateway, rinfo): | ||||
|         #self.write_line("%s instantiated gateway from spec %r" %(gateway.id, gateway.spec._spec)) | ||||
|  | @ -438,9 +438,9 @@ class TestTerminal: | |||
|         modcol = testdir.getmodulecol("def test_one(): pass") | ||||
|         rep = TerminalReporter(modcol.config, file=linecomp.stringio) | ||||
|         excinfo = py.test.raises(ValueError, "raise ValueError('hello')") | ||||
|         rep.pyevent__internalerror(event.InternalException(excinfo)) | ||||
|         rep.pyevent__internalerror(excinfo.getrepr()) | ||||
|         linecomp.assert_contains_lines([ | ||||
|             "InternalException: >*raise ValueError*" | ||||
|             "INTERNALERROR> *raise ValueError*" | ||||
|         ]) | ||||
| 
 | ||||
|     def test_gwmanage_events(self, testdir, linecomp): | ||||
|  |  | |||
|  | @ -77,6 +77,12 @@ class PytestPlugins(object): | |||
|     def notify(self, eventname, *args, **kwargs): | ||||
|         return self.pyplugins.notify(eventname, *args, **kwargs) | ||||
| 
 | ||||
|     def notify_exception(self, excinfo=None): | ||||
|         if excinfo is None: | ||||
|             excinfo = py.code.ExceptionInfo() | ||||
|         excrepr = excinfo.getrepr(funcargs=True, showlocals=True) | ||||
|         return self.notify("internalerror", excrepr) | ||||
| 
 | ||||
|     def do_addoption(self, parser): | ||||
|         methods = self.pyplugins.listattr("pytest_addoption", reverse=True) | ||||
|         mc = py._com.MultiCall(methods, parser=parser) | ||||
|  |  | |||
|  | @ -121,7 +121,7 @@ class Session(object): | |||
|             exitstatus = outcome.EXIT_INTERRUPTED | ||||
|         except: | ||||
|             captured_excinfo = py.code.ExceptionInfo() | ||||
|             self.bus.notify("internalerror", event.InternalException(captured_excinfo)) | ||||
|             self.config.pytestplugins.notify_exception(captured_excinfo) | ||||
|             exitstatus = outcome.EXIT_INTERNALERROR | ||||
|         if exitstatus == 0 and self._testsfailed: | ||||
|             exitstatus = outcome.EXIT_TESTSFAILED | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue