• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018, The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Test finder base class."""
16from collections import namedtuple
17
18
19Finder = namedtuple(
20    'Finder', ['test_finder_instance', 'find_method', 'finder_info']
21)
22
23
24def find_method_register(cls):
25  """Class decorater to find all registered find methods."""
26  cls.find_methods = []
27  cls.get_all_find_methods = lambda x: x.find_methods
28  for methodname in dir(cls):
29    method = getattr(cls, methodname)
30    if hasattr(method, '_registered'):
31      cls.find_methods.append(Finder(None, method, None))
32  return cls
33
34
35def register():
36  """Decorator to register find methods."""
37
38  def wrapper(func):
39    """Wrapper for the register decorator."""
40    # pylint: disable=protected-access
41    func._registered = True
42    return func
43
44  return wrapper
45
46
47# This doesn't really do anything since there are no find methods defined but
48# it's here anyways as an example for other test type classes.
49@find_method_register
50class TestFinderBase:
51  """Base class for test finder class."""
52
53  def __init__(self, *args, **kwargs):
54    pass
55