1# Copyright 2017 Google Inc. 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 15import copy 16import os 17 18from mobly import utils 19 20 21class RuntimeTestInfo: 22 """Container class for runtime information of a test or test stage. 23 24 One object corresponds to one test. This is meant to be a read-only class. 25 26 This also applies to test stages like `setup_class`, which has its own 27 runtime info but is not part of any single test. 28 29 Attributes: 30 name: string, name of the test. 31 signature: string, an identifier of the test, a combination of test 32 name and begin time. 33 record: TestResultRecord, the current test result record. This changes 34 as the test's execution progresses. 35 output_path: string, path to the test's output directory. It's created 36 upon accessing. 37 """ 38 39 def __init__(self, test_name, log_path, record): 40 self._name = test_name 41 self._record = record 42 self._output_dir_path = utils.abs_path( 43 os.path.join(log_path, self._record.signature) 44 ) 45 46 @property 47 def name(self): 48 return self._name 49 50 @property 51 def signature(self): 52 return self.record.signature 53 54 @property 55 def record(self): 56 return copy.deepcopy(self._record) 57 58 @property 59 def output_path(self): 60 utils.create_dir(self._output_dir_path) 61 return self._output_dir_path 62