Add Apps.AppListSearchQueryLength UMA histogram.
[chromium-blink-merge.git] / build / android / pylib / host_driven / tests_annotations.py
blob533114065e5bab3f737c99bbd0332f0cc66c576b
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 """Annotations for host-driven tests."""
6 # pylint: disable=W0212
8 import os
11 class AnnotatedFunctions(object):
12 """A container for annotated methods."""
13 _ANNOTATED = {}
15 @staticmethod
16 def _AddFunction(annotation, function):
17 """Adds an annotated function to our container.
19 Args:
20 annotation: the annotation string.
21 function: the function.
22 Returns:
23 The function passed in.
24 """
25 module_name = os.path.splitext(os.path.basename(
26 function.__globals__['__file__']))[0]
27 qualified_function_name = '.'.join([module_name, function.func_name])
28 function_list = AnnotatedFunctions._ANNOTATED.get(annotation, [])
29 function_list.append(qualified_function_name)
30 AnnotatedFunctions._ANNOTATED[annotation] = function_list
31 return function
33 @staticmethod
34 def IsAnnotated(annotation, qualified_function_name):
35 """True if function name (module.function) contains the annotation.
37 Args:
38 annotation: the annotation string.
39 qualified_function_name: the qualified function name.
40 Returns:
41 True if module.function contains the annotation.
42 """
43 return qualified_function_name in AnnotatedFunctions._ANNOTATED.get(
44 annotation, [])
46 @staticmethod
47 def GetTestAnnotations(qualified_function_name):
48 """Returns a list containing all annotations for the given function.
50 Args:
51 qualified_function_name: the qualified function name.
52 Returns:
53 List of all annotations for this function.
54 """
55 return [annotation
56 for annotation, tests in AnnotatedFunctions._ANNOTATED.iteritems()
57 if qualified_function_name in tests]
60 # The following functions are annotations used for the host-driven tests.
61 def Smoke(function):
62 return AnnotatedFunctions._AddFunction('Smoke', function)
65 def SmallTest(function):
66 return AnnotatedFunctions._AddFunction('SmallTest', function)
69 def MediumTest(function):
70 return AnnotatedFunctions._AddFunction('MediumTest', function)
73 def LargeTest(function):
74 return AnnotatedFunctions._AddFunction('LargeTest', function)
77 def EnormousTest(function):
78 return AnnotatedFunctions._AddFunction('EnormousTest', function)
81 def FlakyTest(function):
82 return AnnotatedFunctions._AddFunction('FlakyTest', function)
85 def DisabledTest(function):
86 return AnnotatedFunctions._AddFunction('DisabledTest', function)
89 def Feature(feature_list):
90 def _AddFeatures(function):
91 for feature in feature_list:
92 AnnotatedFunctions._AddFunction('Feature:%s' % feature, function)
93 return AnnotatedFunctions._AddFunction('Feature', function)
94 return _AddFeatures