• 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"""
16Test finder base class.
17"""
18from collections import namedtuple
19
20
21Finder = namedtuple('Finder', ['test_finder_instance', 'find_method',
22                               'finder_info'])
23
24
25def find_method_register(cls):
26    """Class decorater to find all registered find methods."""
27    cls.find_methods = []
28    cls.get_all_find_methods = lambda x: x.find_methods
29    for methodname in dir(cls):
30        method = getattr(cls, methodname)
31        if hasattr(method, '_registered'):
32            cls.find_methods.append(Finder(None, method, None))
33    return cls
34
35
36def register():
37    """Decorator to register find methods."""
38
39    def wrapper(func):
40        """Wrapper for the register decorator."""
41        #pylint: disable=protected-access
42        func._registered = True
43        return func
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(object):
51    """Base class for test finder class."""
52
53    def __init__(self, *args, **kwargs):
54        pass
55