Roll src/third_party/WebKit 787a07c:716df21 (svn 201034:201036)
[chromium-blink-merge.git] / media / tools / layout_tests / bug.py
blobd8cd20a1b3f93c0077c716a0529d6f093c06778a
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Bug module that is necessary for the layout analyzer."""
7 import re
9 from webkitpy.layout_tests.models.test_expectations import *
12 class Bug(object):
13 """A class representing a bug.
15 TODO(imasaki): add more functionalities here if bug-tracker API is available.
16 For example, you can get the name of a bug owner.
17 """
18 # Type enum for the bug.
19 WEBKIT = 0
20 CHROMIUM = 1
21 OTHERS = 2
23 def __init__(self, bug_modifier):
24 """Initialize the object using raw bug text (such as BUGWK2322).
26 The bug modifier used in the test expectation file.
28 Args:
29 bug_modifier: a string representing a bug modifier. According to
30 http://www.chromium.org/developers/testing/webkit-layout-tests/\
31 testexpectations
32 Bug identifiers are of the form "webkit.org/b/12345", "crbug.com/12345",
33 "code.google.com/p/v8/issues/detail?id=12345" or "Bug(username)"
34 """
35 match = re.match('Bug\((\w+)\)$', bug_modifier)
36 if match:
37 self.type = self.OTHERS
38 self.url = 'mailto:%s@chromium.org' % match.group(1).lower()
39 self.bug_txt = bug_modifier
40 return
42 self.type = self.GetBugType(bug_modifier)
43 self.url = bug_modifier
44 self.bug_txt = bug_modifier
47 def GetBugType(self, bug_modifier):
48 """Returns type of the bug based on URL."""
49 if bug_modifier.startswith(WEBKIT_BUG_PREFIX):
50 return self.WEBKIT;
51 if bug_modifier.startswith(CHROMIUM_BUG_PREFIX):
52 return self.CHROMIUM;
53 return self.OTHERS
55 def __str__(self):
56 """Get a string representation of a bug object.
58 Returns:
59 a string for HTML link representation of a bug.
60 """
61 return '<a href="%s">%s</a>' % (self.url, self.bug_txt)