def __formatFailure(self, failure, logMessage, extras):
    """Generates a dict from the given Failure object."""

    parts = ['Traceback (most recent call last):']
    if not failure.frames:
      parts += traceback.format_stack()
    else:
      for functionName, filename, lineNumber, _, _ in failure.frames:
        parts.append('File "%s", line %s, in %s' % (filename, lineNumber, functionName))
    backtrace = '\n'.join(parts)

    result = {
      'project': self.__project,
      'type': failure.type.__module__ + '.' + failure.type.__name__,
      'message': str(failure.value),
      'environment': self.__environment,
      'serverName': self.__serverName,
      'logMessage': logMessage,
      'backtrace': backtrace
    }
    if context and context.all():
      result['context'] = context.all()
      if extras:
        result['context'] = result['context'].copy()
        result['context'].update(extras)
    elif extras:
      result['context'] = extras

    return result
  def __formatFailure(self, failure, logMessage, extras):
    """Generates a dict from the given Failure object."""

    parts = ['Traceback (most recent call last):']
    if not failure.frames:
      parts += traceback.format_stack()
    else:
      for functionName, filename, lineNumber, _, _ in failure.frames:
        parts.append('File "%s", line %s, in %s' % (filename, lineNumber, functionName))
    backtrace = '\n'.join(parts)

    result = {
      'project': self.__project,
      'type': failure.type.__module__ + '.' + failure.type.__name__,
      'message': str(failure.value),
      'environment': self.__environment,
      'serverName': self.__serverName,
      'logMessage': logMessage,
      'backtrace': backtrace
    }

    if extras and 'level' in extras:
      result['errorLevel'] = extras['level']
      del extras['level']

    if context and context.all():
      result['context'] = context.all()
      if extras:
        result['context'] = result['context'].copy()
        result['context'].update(extras)
    elif extras:
      result['context'] = extras

    return result
Ejemplo n.º 3
0
 def notCrashySleepWithNonRootContext(self, sleepFor, parentCtx, **kwargs):
     """Sleeps for sleepFor seconds and then asserts that kwargs + parentCtx is the current context"""
     expected = {}
     expected.update(parentCtx)
     expected.update(kwargs)
     with context.set(**kwargs):
         yield sleep(sleepFor)
         self.assertEquals(expected, context.all())
Ejemplo n.º 4
0
 def notCrashySleepWithNonRootContext(self, sleepFor, parentCtx, **kwargs):
   """Sleeps for sleepFor seconds and then asserts that kwargs + parentCtx is the current context"""
   expected = {}
   expected.update(parentCtx)
   expected.update(kwargs)
   with context.set(**kwargs):
     yield sleep(sleepFor)
     self.assertEquals(expected, context.all())
Ejemplo n.º 5
0
 def notCrashySleep(self, sleepFor, **kwargs):
     """Sleeps for sleepFor seconds and asserts that kwargs is equal to the stored context variables"""
     with context.set(**kwargs):
         yield sleep(sleepFor)
         self.assertEquals(kwargs, context.all())
Ejemplo n.º 6
0
 def notCrashySleep(self, sleepFor, **kwargs):
   """Sleeps for sleepFor seconds and asserts that kwargs is equal to the stored context variables"""
   with context.set(**kwargs):
     yield sleep(sleepFor)
     self.assertEquals(kwargs, context.all())