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""" 16TestInfo class. 17""" 18 19from collections import namedtuple 20 21 22TestFilterBase = namedtuple('TestFilter', ['class_name', 'methods']) 23 24 25class TestInfo(object): 26 """Information needed to identify and run a test.""" 27 28 def __init__(self, test_name, test_runner, build_targets, data=None): 29 """Init for TestInfo. 30 31 Args: 32 test_name: String of test name. 33 test_runner: String of test runner. 34 build_targets: Set of build targets. 35 data: Dict of data for test runners to use. 36 """ 37 self.test_name = test_name 38 self.test_runner = test_runner 39 self.build_targets = build_targets 40 self.data = data if data else {} 41 42 def __str__(self): 43 return ('test_name: %s - test_runner:%s - build_targets:%s - data:%s' % 44 (self.test_name, self.test_runner, self.build_targets, 45 self.data)) 46 47 48class TestFilter(TestFilterBase): 49 """Information needed to filter a test in Tradefed""" 50 51 def to_set_of_tf_strings(self): 52 """Return TestFilter as set of strings in TradeFed filter format.""" 53 if self.methods: 54 return {'%s#%s' % (self.class_name, m) for m in self.methods} 55 return {self.class_name} 56