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. 4 5 """Annotations for host-driven tests.""" 6 7 import os 8 9 10 class AnnotatedFunctions(object): 11 """A container for annotated methods.""" 12 _ANNOTATED = {} 13 14 @staticmethod 15 def _AddFunction(annotation, function): 16 """Adds an annotated function to our container. 17 18 Args: 19 annotation: the annotation string. 20 function: the function. 21 Returns: 22 The function passed in. 23 """ 24 module_name = os.path.splitext(os.path.basename( 25 function.__globals__['__file__']))[0] 26 qualified_function_name = '.'.join([module_name, function.func_name]) 27 function_list = AnnotatedFunctions._ANNOTATED.get(annotation, []) 28 function_list.append(qualified_function_name) 29 AnnotatedFunctions._ANNOTATED[annotation] = function_list 30 return function 31 32 @staticmethod 33 def IsAnnotated(annotation, qualified_function_name): 34 """True if function name (module.function) contains the annotation. 35 36 Args: 37 annotation: the annotation string. 38 qualified_function_name: the qualified function name. 39 Returns: 40 True if module.function contains the annotation. 41 """ 42 return qualified_function_name in AnnotatedFunctions._ANNOTATED.get( 43 annotation, []) 44 45 @staticmethod 46 def GetTestAnnotations(qualified_function_name): 47 """Returns a list containing all annotations for the given function. 48 49 Args: 50 qualified_function_name: the qualified function name. 51 Returns: 52 List of all annotations for this function. 53 """ 54 return [annotation 55 for annotation, tests in AnnotatedFunctions._ANNOTATED.iteritems() 56 if qualified_function_name in tests] 57 58 59 # The following functions are annotations used for the host-driven tests. 60 def Smoke(function): 61 return AnnotatedFunctions._AddFunction('Smoke', function) 62 63 64 def SmallTest(function): 65 return AnnotatedFunctions._AddFunction('SmallTest', function) 66 67 68 def MediumTest(function): 69 return AnnotatedFunctions._AddFunction('MediumTest', function) 70 71 72 def LargeTest(function): 73 return AnnotatedFunctions._AddFunction('LargeTest', function) 74 75 76 def EnormousTest(function): 77 return AnnotatedFunctions._AddFunction('EnormousTest', function) 78 79 80 def FlakyTest(function): 81 return AnnotatedFunctions._AddFunction('FlakyTest', function) 82 83 84 def DisabledTest(function): 85 return AnnotatedFunctions._AddFunction('DisabledTest', function) 86 87 88 def Feature(feature_list): 89 def _AddFeatures(function): 90 for feature in feature_list: 91 AnnotatedFunctions._AddFunction('Feature:%s' % feature, function) 92 return AnnotatedFunctions._AddFunction('Feature', function) 93 return _AddFeatures 94