コード例 #1
0
    def test_exc(self):
        """Test exception."""
        entry = {'extras': {}, 'message': 'original'}
        exception = Exception('ex message')
        exception.extras = {'test': 'value', 'task_payload': 'task'}

        try:
            statement_line = inspect.currentframe().f_lineno + 1
            raise exception
        except:
            # We do this because we need the traceback instance.
            exc_info = sys.exc_info()

        logs.update_entry_with_exc(entry, exc_info)
        self.maxDiff = None  # pylint: disable=invalid-name

        self.assertEqual(
            {
                'extras': {
                    'test': 'value'
                },
                'task_payload':
                'task',
                'serviceContext': {
                    'service': 'bots'
                },
                'message': ('original\n'
                            'Traceback (most recent call last):\n'
                            '  File "%s", line %d, in test_exc\n'
                            '    raise exception\n'
                            'Exception: ex message\n') %
                (__file__.strip('c'), statement_line)
            }, entry)
コード例 #2
0
    def test_none_exc(self):
        """Test exc_info is (None, None, None)."""
        entry = {
            'task_payload': 'task',
            'extras': {
                'test': 'value'
            },
            'message': 'original',
            'serviceContext': {
                'service': 'bots'
            },
            'location': {
                'path': 'source_path',
                'line': 1234,
                'method': 'new_method'
            }
        }
        exc_info = sys.exc_info()  # expected to be (None, None, None).

        logs.update_entry_with_exc(entry, exc_info)

        self.assertEqual(
            {
                'extras': {
                    'test': 'value'
                },
                'task_payload': 'task',
                'message': 'original',
                'serviceContext': {
                    'service': 'bots'
                },
                'location': {
                    'path': 'source_path',
                    'line': 1234,
                    'method': 'new_method'
                },
                'context': {
                    'reportLocation': {
                        'filePath': 'source_path',
                        'lineNumber': 1234,
                        'functionName': 'new_method'
                    }
                }
            }, entry)
コード例 #3
0
 def test_empty(self):
     """Test empty exc_info."""
     entry = {}
     logs.update_entry_with_exc(entry, None)
     self.assertEqual({}, entry)