1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/trunk/build/android/pylib/tests_annotations.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 1.4 +# Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.5 +# Use of this source code is governed by a BSD-style license that can be 1.6 +# found in the LICENSE file. 1.7 + 1.8 +"""Annotations for python-driven tests.""" 1.9 + 1.10 +import os 1.11 + 1.12 + 1.13 +class AnnotatedFunctions(object): 1.14 + """A container for annotated methods.""" 1.15 + _ANNOTATED = {} 1.16 + 1.17 + @staticmethod 1.18 + def _AddFunction(annotation, function): 1.19 + """Adds an annotated to function to our container. 1.20 + 1.21 + Args: 1.22 + annotation: the annotation string. 1.23 + function: the function. 1.24 + Returns: 1.25 + The function passed in. 1.26 + """ 1.27 + module_name = os.path.splitext(os.path.basename( 1.28 + function.__globals__['__file__']))[0] 1.29 + qualified_function_name = '.'.join([module_name, function.func_name]) 1.30 + function_list = AnnotatedFunctions._ANNOTATED.get(annotation, []) 1.31 + function_list.append(qualified_function_name) 1.32 + AnnotatedFunctions._ANNOTATED[annotation] = function_list 1.33 + return function 1.34 + 1.35 + @staticmethod 1.36 + def IsAnnotated(annotation, qualified_function_name): 1.37 + """True if function name (module.function) contains the annotation. 1.38 + 1.39 + Args: 1.40 + annotation: the annotation string. 1.41 + qualified_function_name: the qualified function name. 1.42 + Returns: 1.43 + True if module.function contains the annotation. 1.44 + """ 1.45 + return qualified_function_name in AnnotatedFunctions._ANNOTATED.get( 1.46 + annotation, []) 1.47 + 1.48 + @staticmethod 1.49 + def GetTestAnnotations(qualified_function_name): 1.50 + """Returns a list containing all annotations for the given function. 1.51 + 1.52 + Args: 1.53 + qualified_function_name: the qualified function name. 1.54 + Returns: 1.55 + List of all annotations for this function. 1.56 + """ 1.57 + return [annotation 1.58 + for annotation, tests in AnnotatedFunctions._ANNOTATED.iteritems() 1.59 + if qualified_function_name in tests] 1.60 + 1.61 + 1.62 +# The following functions are annotations used for the python driven tests. 1.63 +def Smoke(function): 1.64 + return AnnotatedFunctions._AddFunction('Smoke', function) 1.65 + 1.66 + 1.67 +def SmallTest(function): 1.68 + return AnnotatedFunctions._AddFunction('SmallTest', function) 1.69 + 1.70 + 1.71 +def MediumTest(function): 1.72 + return AnnotatedFunctions._AddFunction('MediumTest', function) 1.73 + 1.74 + 1.75 +def LargeTest(function): 1.76 + return AnnotatedFunctions._AddFunction('LargeTest', function) 1.77 + 1.78 + 1.79 +def FlakyTest(function): 1.80 + return AnnotatedFunctions._AddFunction('FlakyTest', function) 1.81 + 1.82 + 1.83 +def DisabledTest(function): 1.84 + return AnnotatedFunctions._AddFunction('DisabledTest', function) 1.85 + 1.86 + 1.87 +def Feature(feature_list): 1.88 + def _AddFeatures(function): 1.89 + for feature in feature_list: 1.90 + AnnotatedFunctions._AddFunction('Feature' + feature, function) 1.91 + return AnnotatedFunctions._AddFunction('Feature', function) 1.92 + return _AddFeatures