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"""Holds util functions that are used in more than one test module.""" 15 16from mobly import records 17 18 19def validate_test_result(result): 20 """Validate basic properties of a test result. 21 22 The records in each bucket of the test result should have the corresponding 23 result enum. 24 25 Args: 26 result: The `records.TestResult` object to validate. 27 """ 28 buckets = [ 29 (result.passed, records.TestResultEnums.TEST_RESULT_PASS), 30 (result.failed, records.TestResultEnums.TEST_RESULT_FAIL), 31 (result.error, records.TestResultEnums.TEST_RESULT_ERROR), 32 (result.skipped, records.TestResultEnums.TEST_RESULT_SKIP), 33 ] 34 for bucket_list, expected_enum in buckets: 35 for record in bucket_list: 36 if record.result != expected_enum: 37 raise AssertionError('Expected result %s, got %s.' % 38 (expected_enum, record.result)) 39