| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Helper functions common to native, java and python test runners.""" | 5 """Helper functions common to native, java and python test runners.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 import time | 10 import time |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 def format(self, record): | 24 def format(self, record): |
| 25 # Can't use super() because in older Python versions logging.Formatter does | 25 # Can't use super() because in older Python versions logging.Formatter does |
| 26 # not inherit from object. | 26 # not inherit from object. |
| 27 msg = logging.Formatter.format(self, record) | 27 msg = logging.Formatter.format(self, record) |
| 28 if 'MainThread' in msg[:19]: | 28 if 'MainThread' in msg[:19]: |
| 29 msg = msg.replace('MainThread', 'Main', 1) | 29 msg = msg.replace('MainThread', 'Main', 1) |
| 30 timediff = str(int(time.time() - self._creation_time)) | 30 timediff = str(int(time.time() - self._creation_time)) |
| 31 return '%s %ss %s' % (record.levelname[0], timediff.rjust(4), msg) | 31 return '%s %ss %s' % (record.levelname[0], timediff.rjust(4), msg) |
| 32 | 32 |
| 33 | 33 |
| 34 def GetExpectations(file_name): | |
| 35 """Returns a list of test names in the |file_name| test expectations file.""" | |
| 36 if not file_name or not os.path.exists(file_name): | |
| 37 return [] | |
| 38 return [x for x in [x.strip() for x in file(file_name).readlines()] | |
| 39 if x and x[0] != '#'] | |
| 40 | |
| 41 | |
| 42 def SetLogLevel(verbose_count): | 34 def SetLogLevel(verbose_count): |
| 43 """Sets log level as |verbose_count|.""" | 35 """Sets log level as |verbose_count|.""" |
| 44 log_level = logging.WARNING # Default. | 36 log_level = logging.WARNING # Default. |
| 45 if verbose_count == 1: | 37 if verbose_count == 1: |
| 46 log_level = logging.INFO | 38 log_level = logging.INFO |
| 47 elif verbose_count >= 2: | 39 elif verbose_count >= 2: |
| 48 log_level = logging.DEBUG | 40 log_level = logging.DEBUG |
| 49 logger = logging.getLogger() | 41 logger = logging.getLogger() |
| 50 logger.setLevel(log_level) | 42 logger.setLevel(log_level) |
| 51 custom_handler = logging.StreamHandler(sys.stdout) | 43 custom_handler = logging.StreamHandler(sys.stdout) |
| 52 custom_handler.setFormatter(CustomFormatter()) | 44 custom_handler.setFormatter(CustomFormatter()) |
| 53 logging.getLogger().addHandler(custom_handler) | 45 logging.getLogger().addHandler(custom_handler) |
| OLD | NEW |