summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/catapult/tracing/tracing/mre/failure_unittest.py
blob: 1140b17aa663cb389aae7a026d75bd3d4e214276 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import unittest

from tracing.mre import function_handle
from tracing.mre import failure as failure_module
from tracing.mre import job as job_module


def _SingleFileFunctionHandle(filename, function_name, guid):
  return function_handle.FunctionHandle(
      modules_to_load=[function_handle.ModuleToLoad(filename=filename)],
      function_name=function_name, guid=guid)


class FailureTests(unittest.TestCase):

  def testAsDict(self):
    map_function_handle = _SingleFileFunctionHandle('foo.html', 'Foo', '2')
    job = job_module.Job(map_function_handle, '1')
    failure = failure_module.Failure(job, 'foo.html:Foo',
                                     'file://foo.html',
                                     'err', 'desc', 'stack')

    self.assertEquals(failure.AsDict(), {
        'job_guid': '1',
        'function_handle_string': 'foo.html:Foo',
        'trace_canonical_url': 'file://foo.html',
        'type': 'err',
        'description': 'desc',
        'stack': 'stack'
    })

  def testFromDict(self):
    map_function_handle = _SingleFileFunctionHandle('foo.html', 'Foo', '2')
    job = job_module.Job(map_function_handle, '1')

    failure_dict = {
        'job_guid': '1',
        'function_handle_string': 'foo.html:Foo',
        'trace_canonical_url': 'file://foo.html',
        'type': 'err',
        'description': 'desc',
        'stack': 'stack'
    }

    failure = failure_module.Failure.FromDict(failure_dict, job)

    self.assertEquals(failure.job.guid, '1')
    self.assertEquals(failure.function_handle_string, 'foo.html:Foo')
    self.assertEquals(failure.trace_canonical_url, 'file://foo.html')
    self.assertEquals(failure.failure_type_name, 'err')
    self.assertEquals(failure.description, 'desc')
    self.assertEquals(failure.stack, 'stack')