Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def mobly_logger(self, alias='latest'):
"""Starts and stops a logging context for a Mobly test run.
Args:
alias: optional string, the name of the latest log alias directory to
create. If a falsy value is specified, then the directory will not
be created.
Yields:
The host file path where the logs for the test run are stored.
"""
self._update_log_path()
logger.setup_test_logger(self._root_output_path,
self._testbed_name,
alias=alias)
try:
yield self._root_output_path
finally:
logger.kill_test_logger(logging.getLogger())
def _is_timestamp_in_range(self, target, begin_time, end_time):
low = mobly_logger.logline_timestamp_comparator(begin_time,
target) <= 0
high = mobly_logger.logline_timestamp_comparator(end_time, target) >= 0
return low and high
.. deprecated:: 1.10
Use :func:`create_output_excerpts` instead.
Args:
tag: An identifier of the time period, usualy the name of a test.
begin_time: Logline format timestamp of the beginning of the time
period.
Returns:
String, full path to the excerpt file created.
"""
if not self.adb_logcat_file_path:
raise Error(
self._ad,
'Attempting to cat adb log when none has been collected.')
end_time = mobly_logger.get_log_line_timestamp()
self._ad.log.debug('Extracting adb log from logcat.')
adb_excerpt_path = os.path.join(self._ad.log_path, 'AdbLogExcerpts')
utils.create_dir(adb_excerpt_path)
out_name = '%s,%s.txt' % (tag, begin_time)
out_name = mobly_logger.sanitize_filename(out_name)
full_adblog_path = os.path.join(adb_excerpt_path, out_name)
with io.open(full_adblog_path, 'w', encoding='utf-8') as out:
in_file = self.adb_logcat_file_path
with io.open(in_file, 'r', encoding='utf-8',
errors='replace') as f:
in_range = False
while True:
line = None
try:
line = f.readline()
if not line:
devices in the list concurrently. Bug report takes a relative long
time to take, so use this cautiously.
Args:
ads: A list of AndroidDevice instances.
test_name: Name of the test method that triggered this bug report.
If None, the default name "bugreport" will be used.
begin_time: timestamp taken when the test started, can be either
string or int. If None, the current time will be used.
destination: string, path to the directory where the bugreport
should be saved.
"""
if begin_time is None:
begin_time = mobly_logger.get_log_file_timestamp()
else:
begin_time = mobly_logger.sanitize_filename(str(begin_time))
def take_br(test_name, begin_time, ad, destination):
ad.take_bug_report(test_name=test_name,
begin_time=begin_time,
destination=destination)
args = [(test_name, begin_time, ad, destination) for ad in ads]
utils.concurrent_exec(take_br, args)