OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Effectively a singleton for maintaining exit code state of tests.""" |
| 6 |
| 7 import constants |
| 8 |
| 9 _exit_code = constants.NORMAL_EXIT_CODE |
| 10 |
| 11 VALID_EXIT_CODES = [constants.ERROR_EXIT_CODE, |
| 12 constants.WARNING_EXIT_CODE, |
| 13 constants.NORMAL_EXIT_CODE] |
| 14 |
| 15 |
| 16 class InvalidExitCodeError(Exception): |
| 17 """Invalid exit code observed.""" |
| 18 |
| 19 |
| 20 def UpdateExitCode(new_exit_code): |
| 21 """Updates the exit code with some checking and priority. |
| 22 |
| 23 Args: |
| 24 new_exit_code: The exit code to update to. |
| 25 |
| 26 Raises: |
| 27 InvalidExitCodeError: If |new_exit_code| is not in the set of |
| 28 valid exit codes. |
| 29 """ |
| 30 |
| 31 if new_exit_code not in VALID_EXIT_CODES: |
| 32 raise InvalidExitCodeError('Observed exit code: %s' % new_exit_code) |
| 33 |
| 34 # Only escalate exit codes |
| 35 global _exit_code |
| 36 if (_exit_code == constants.WARNING_EXIT_CODE and |
| 37 new_exit_code == constants.ERROR_EXIT_CODE): |
| 38 _exit_code = new_exit_code |
| 39 elif _exit_code == constants.NORMAL_EXIT_CODE: |
| 40 _exit_code = new_exit_code |
| 41 |
| 42 |
| 43 def ResetExitCode(): |
| 44 global _exit_code |
| 45 _exit_code = constants.NORMAL_EXIT_CODE |
| 46 |
| 47 |
| 48 def GetExitCode(): |
| 49 global _exit_code |
| 50 return _exit_code |
OLD | NEW |