예제 #1
0
    def test_relative_path(self):
        data = [
            os.getcwd(),
            os.path.dirname(
                os.path.dirname(os.path.dirname(formatter.runtime.__file__))),
            os.path.dirname(
                os.path.dirname(os.path.dirname(formatter.webapp2.__file__))),
            os.path.dirname(os.getcwd()),
            '.',
        ]
        for value in data:
            i = os.path.join(value, 'foo')
            self.assertEqual('foo', formatter._relative_path(i))

        self.assertEqual('bar/foo', formatter._relative_path('bar/foo'))
예제 #2
0
  def test_relative_path(self):
    data = [
      os.getcwd(),
      os.path.dirname(os.path.dirname(os.path.dirname(
          formatter.runtime.__file__))),
      os.path.dirname(os.path.dirname(os.path.dirname(
          formatter.webapp2.__file__))),
      os.path.dirname(os.getcwd()),
      '.',
    ]
    for value in data:
      i = os.path.join(value, 'foo')
      self.assertEqual('foo', formatter._relative_path(i))

    self.assertEqual('bar/foo', formatter._relative_path('bar/foo'))
예제 #3
0
 def test_exception(self):
   on_error.log(env='str')
   self.assertEqual(1, models.Error.query().count())
   relpath_on_error = formatter._relative_path(ON_ERROR_PATH)
   expected = {
     'args': [],
     'category': u'exception',
     'created_ts': self._now,
     'cwd': None,
     'duration': None,
     'endpoint': None,
     'env': None,
     'exception_type': u'<type \'exceptions.TypeError\'>',
     'hostname': None,
     'identity': None,
     'message':
         u'log({\'env\': \'str\'}) caused: JSON property must be a '
         u'<type \'dict\'>',
     'method': None,
     'os': None,
     'params': None,
     'python_version': None,
     'request_id': None,
     'source': u'server',
     'source_ip': None,
     'stack':
         u'Traceback (most recent call last):\n'
         u'  File "%s", line 0, in log\n'
         u'    error = models.Error(identity=identity, **kwargs)\n'
         u'  File "appengine/ext/ndb/model.py", line 0, in __init__\n' %
           relpath_on_error.replace('.pyc', '.py'),
     'user': None,
     'version': None,
   }
   actual = models.Error.query().get().to_dict()
   # Zap out line numbers to 0, it's annoying otherwise to update the unit test
   # just for line move. Only keep the first 4 lines because json_dict
   # verification is a tad deep insode ndb/model.py.
   actual['stack'] = ''.join(
       re.sub(r' \d+', ' 0', actual['stack']).splitlines(True)[:4])
   # Also make no distinction between *.pyc and *.py files.
   actual['stack'] = actual['stack'].replace('.pyc', '.py')
   self.assertEqual(expected, actual)
예제 #4
0
 def test_exception(self):
   on_error.log(env='str')
   self.assertEqual(1, models.Error.query().count())
   relpath_on_error = formatter._relative_path(ON_ERROR_PATH)
   expected = {
     'args': [],
     'category': u'exception',
     'created_ts': self._now,
     'cwd': None,
     'duration': None,
     'endpoint': None,
     'env': None,
     'exception_type': u'<type \'exceptions.TypeError\'>',
     'hostname': None,
     'identity': None,
     'message':
         u'log({\'env\': \'str\'}) caused: JSON property must be a '
         u'<type \'dict\'>',
     'method': None,
     'os': None,
     'params': None,
     'python_version': None,
     'request_id': None,
     'source': u'server',
     'source_ip': None,
     'stack':
         u'Traceback (most recent call last):\n'
         u'  File "%s", line 0, in log\n'
         u'    error = models.Error(identity=identity, **kwargs)\n'
         u'  File "appengine/ext/ndb/model.py", line 0, in __init__\n' %
           relpath_on_error.replace('.pyc', '.py'),
     'user': None,
     'version': None,
   }
   actual = models.Error.query().get().to_dict()
   # Zap out line numbers to 0, it's annoying otherwise to update the unit test
   # just for line move. Only keep the first 4 lines because json_dict
   # verification is a tad deep insode ndb/model.py.
   actual['stack'] = ''.join(
       re.sub(r' \d+', ' 0', actual['stack']).splitlines(True)[:4])
   # Also make no distinction between *.pyc and *.py files.
   actual['stack'] = actual['stack'].replace('.pyc', '.py')
   self.assertEqual(expected, actual)