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"""
16Test finder base class.
17"""
18from collections import namedtuple
19
20
21Finder = namedtuple('Finder', ['test_finder_instance', 'find_method'])
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))
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    return wrapper
44
45
46# This doesn't really do anything since there are no find methods defined but
47# it's here anyways as an example for other test type classes.
48@find_method_register
49class TestFinderBase(object):
50    """Base class for test finder class."""
51
52    def __init__(self, *args, **kwargs):
53        pass
54