def UploadWpr(self): cli_helpers.Step('UPLOAD WPR: %s' % self.story) archive, _ = self._ExistingWpr() if archive is None: cli_helpers.Error('NO WPR FOUND, use the "record" subcommand') _UploadArchiveToGoogleStorage(archive) return _GitAddArtifactHash(archive)
def _PrintRunInfo(out_file, chrome_log_file=False, results_details=True): try: if results_details: _PrintResultsHTMLInfo(out_file) except Exception as e: cli_helpers.Error('Could not print results.html tests: %s' % e) cli_helpers.Info('Stdout/Stderr Log: %s' % out_file) if chrome_log_file: cli_helpers.Info('Chrome Log: %s.chrome.log' % out_file) cli_helpers.Info(' Total output: %d' % _CountLogLines(out_file)) cli_helpers.Info(' Total Console: %d' % _CountLogLines(out_file, r'DevTools console')) cli_helpers.Info(' [security]: %d' % _CountLogLines(out_file, r'DevTools console .security.')) cli_helpers.Info(' [network]: %d' % _CountLogLines(out_file, r'DevTools console .network.')) chrome_log = '%s.chrome.log' % out_file if os.path.isfile(chrome_log): cli_helpers.Info(' [javascript]: %d' % _CountLogLines(chrome_log, r'Uncaught .*Error')) if results_details: missing_urls = _ExtractMissingURLsFromLog(out_file) if missing_urls: cli_helpers.Info('Missing URLs in the archive:') for missing_url in missing_urls: cli_helpers.Info(' - %s' % missing_url)
def _GitAddArtifactHash(archive): """Stages changes into SHA1 file for commit.""" archive_sha1 = archive + '.sha1' if not os.path.exists(archive_sha1): cli_helpers.Error('Could not find upload artifact: {sha}', sha=archive_sha1) return False cli_helpers.Run(['git', 'add', archive_sha1]) return True
def _ExtractLogFile(out_file): # This method extracts the name of the chrome log file from the # run_benchmark output log and copies it to the temporary directory next to # the log file, which ensures that it is not overridden by the next run. try: line = subprocess.check_output( ['grep', 'Chrome log file will be saved in', out_file]) os.rename(line.split()[-1], out_file + '.chrome.log') except subprocess.CalledProcessError as e: cli_helpers.Error('Could not find log file: {error}', error=e)
def _PrintRunInfo(self, out_file, results_details=True): try: if results_details: _PrintResultsHTMLInfo(out_file) except Exception as e: cli_helpers.Error('Could not print results.html tests: %s' % e) def shell(cmd): return subprocess.check_output(cmd, shell=True).rstrip() def statsFor(name, filters='wc -l'): cmd = 'grep "DevTools console .%s." "%s"' % (name, out_file) cmd += ' | ' + filters output = shell(cmd) or '0' if len(output) > 7: cli_helpers.Info(' %-26s%s' % ('[%s]:' % name, cmd)) cli_helpers.Info(' ' + output.replace('\n', '\n ')) else: cli_helpers.Info(' %-16s%-8s %s' % ('[%s]:' % name, output, cmd)) cli_helpers.Info('Stdout/Stderr Log: %s' % out_file) if self._IsDesktop( ): # Mobile test runner does not product the log file. cli_helpers.Info('Chrome Log: %s.chrome.log' % out_file) cli_helpers.Info( ' Total output: %s' % subprocess.check_output(['wc', '-l', out_file]).rstrip()) cli_helpers.Info( ' Total Console: %s' % shell('grep "DevTools console" "%s" | wc -l' % out_file)) statsFor('security') statsFor('network', 'cut -d " " -f 20- | sort | uniq -c | sort -nr') chrome_log = '%s.chrome.log' % out_file if os.path.isfile(chrome_log): cmd = 'grep "Uncaught .*Error" "%s"' % chrome_log count = shell(cmd + '| wc -l') cli_helpers.Info(' %-16s%-8s %s' % ('[javascript]:', count, cmd))
def testPrintsError(self, print_mock): cli_helpers.Error('foo') print_mock.assert_called_once_with('\033[91mfoo\033[0m')