1#
2# Copyright (C) 2018 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import logging
17
18
19class TestFrameworkInstrumentationCategories(object):
20    """Enum values for common category strings."""
21    FRAMEWORK_SETUP = 'Framework setUp'
22    FRAMEWORK_TEARDOWN = 'Framework tearDown'
23    TEST_MODULE_SETUP = 'Test module setUp'
24    TEST_MODULE_TEARDOWN = 'Test module tearDown'
25    TEST_CLASS_SETUP = 'Test class setUp'
26    TEST_CLASS_TEARDOWN = 'Test class tearDown'
27    TEST_CASE_SETUP = 'Test case setUp'
28    TEST_CASE_TEARDOWN = 'Test case tearDown'
29    DEVICE_SETUP = 'Device setUp'
30    DEVICE_CLEANUP = 'Device cleanUp'
31    FAILED_TEST_CASE_PROCESSING = 'Failed test case processing'
32    TEST_CASE_EXECUTION = 'Test case execution'
33    RESULT_PROCESSING = 'Result processing'
34    WAITING_FOR_DEVICE_RESPOND = 'Waiting for device respond'
35
36    def Add(self, key, value):
37        """Add a category key and value to the class attribute.
38
39        Key being empty or starting with non-letter is not allowed.
40
41        Returns:
42            bool, whether adding the values is success
43        """
44        if not key or not key[0].isalpha():
45            logging.error('Category name empty or starting with non-letter '
46                          'is not allowed. Ignoring key=[%s], value=[%s]',
47                          key, value)
48            return False
49
50        if hasattr(self, key):
51            logging.warn('Categories key %s already exists with value %s. '
52                         'Overwriting with %s.', key, getattr(self,key), value)
53
54        setattr(self, key, value)
55        return True