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
11 class AnnotatedFunctions(object):
12 """A container for annotated methods."""
16 def _AddFunction(annotation
, function
):
17 """Adds an annotated function to our container.
20 annotation: the annotation string.
21 function: the function.
23 The function passed in.
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
34 def IsAnnotated(annotation
, qualified_function_name
):
35 """True if function name (module.function) contains the annotation.
38 annotation: the annotation string.
39 qualified_function_name: the qualified function name.
41 True if module.function contains the annotation.
43 return qualified_function_name
in AnnotatedFunctions
._ANNOTATED
.get(
47 def GetTestAnnotations(qualified_function_name
):
48 """Returns a list containing all annotations for the given function.
51 qualified_function_name: the qualified function name.
53 List of all annotations for this function.
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.
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
)