def main(host=None, args=None): options = parse_args(args) if options.no_autopep8: options.style = None if options.leave_strings_alone: options.quoting = None autopep8_options = _autopep8_options_for_style(options.style) fixers = ['webkitpy.formatter.fix_docstrings'] fixers.extend(_fixers_for_quoting(options.quoting)) if options.files == ['-']: host = host or SystemHost() host.print_(reformat_source(host.stdin.read(), autopep8_options, fixers, '<stdin>'), end='') return # We create the arglist before checking if we need to create a Host, because a # real host is non-picklable and can't be passed to host.executive.map(). arglist = [(host, name, autopep8_options, fixers, options.backup) for name in options.files] host = host or SystemHost() host.executive.map(_reformat_thunk, arglist, processes=options.jobs)
def test_find_log_darwin(self): if not SystemHost().platform.is_mac(): return older_mock_crash_report = make_mock_crash_report_darwin( 'DumpRenderTree', 28528) mock_crash_report = make_mock_crash_report_darwin( 'DumpRenderTree', 28530) newer_mock_crash_report = make_mock_crash_report_darwin( 'DumpRenderTree', 28529) other_process_mock_crash_report = make_mock_crash_report_darwin( 'FooProcess', 28527) misformatted_mock_crash_report = 'Junk that should not appear in a crash report' + \ make_mock_crash_report_darwin('DumpRenderTree', 28526)[200:] files = { '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150718_quadzen.crash': older_mock_crash_report, '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150719_quadzen.crash': mock_crash_report, '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150720_quadzen.crash': newer_mock_crash_report, '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150721_quadzen.crash': None, '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150722_quadzen.crash': other_process_mock_crash_report, '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150723_quadzen.crash': misformatted_mock_crash_report, } filesystem = MockFileSystem(files) crash_logs = CrashLogs(MockSystemHost(filesystem=filesystem)) log = crash_logs.find_newest_log("DumpRenderTree") self.assertMultiLineEqual(log, newer_mock_crash_report) log = crash_logs.find_newest_log("DumpRenderTree", 28529) self.assertMultiLineEqual(log, newer_mock_crash_report) log = crash_logs.find_newest_log("DumpRenderTree", 28530) self.assertMultiLineEqual(log, mock_crash_report) log = crash_logs.find_newest_log("DumpRenderTree", 28531) self.assertIsNone(log) log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0) self.assertIsNone(log) def bad_read(_): raise IOError('IOError: No such file or directory') def bad_mtime(_): raise OSError('OSError: No such file or directory') filesystem.read_text_file = bad_read log = crash_logs.find_newest_log("DumpRenderTree", 28531, include_errors=True) self.assertIn('IOError: No such file or directory', log) filesystem = MockFileSystem(files) crash_logs = CrashLogs(MockSystemHost(filesystem=filesystem)) filesystem.mtime = bad_mtime log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0, include_errors=True) self.assertIn('OSError: No such file or directory', log)
def __init__(self): SystemHost.__init__(self) self.web = web.Web() self._git = None # Everything below this line is WebKit-specific and belongs on a higher-level object. self.buildbot = BuildBot() # FIXME: Unfortunately Port objects are currently the central-dispatch objects of the NRWT world. # In order to instantiate a port correctly, we have to pass it at least an executive, user, git, and filesystem # so for now we just pass along the whole Host object. # FIXME: PortFactory doesn't belong on this Host object if Port is going to have a Host (circular dependency). self.port_factory = PortFactory(self) self.builders = BuilderList.load_default_builder_list(self.filesystem)
def test_basic(self): cmd = [ sys.executable, '-c', 'import sys; import time; time.sleep(0.02); print "stdout"; sys.stdout.flush(); print >>sys.stderr, "stderr"' ] host = SystemHost() factory = PortFactory(host) port = factory.get() now = time.time() proc = server_process.ServerProcess(port, 'python', cmd) proc.write('') self.assertIsNone(proc.poll()) self.assertFalse(proc.has_crashed()) # check that doing a read after an expired deadline returns # nothing immediately. line = proc.read_stdout_line(now - 1) self.assertIsNone(line) # FIXME: This part appears to be flaky. line should always be non-None. # FIXME: https://bugs.webkit.org/show_bug.cgi?id=88280 line = proc.read_stdout_line(now + 1.0) if line: self.assertEqual(line.strip(), "stdout") line = proc.read_stderr_line(now + 1.0) if line: self.assertEqual(line.strip(), "stderr") proc.stop(0)
def test_virtual_test_suites(self): # We test that we can load the real LayoutTests/VirtualTestSuites file properly, so we # use a real SystemHost(). We don't care what virtual_test_suites() returns as long # as it is iterable. port = self.make_port(host=SystemHost(), port_name=self.full_port_name) self.assertTrue( isinstance(port.virtual_test_suites(), collections.Iterable))
def reformat_file(host, name, autopep8_options, fixers, should_backup_file): host = host or SystemHost() source = host.filesystem.read_text_file(name) dest = reformat_source(source, autopep8_options, fixers, name) if dest != source: if should_backup_file: host.filesystem.write_text_file(name + '.bak', source) host.filesystem.write_text_file(name, dest)
def test_can_load_actual_virtual_test_suite_file(self): port = Port(SystemHost(), 'baseport') # If this call returns successfully, we found and loaded the LayoutTests/VirtualTestSuites. _ = port.virtual_test_suites()
self._stdout.write(base64.b64encode(output.audio)) self._stdout.write('\n') else: self._stdout.write('Content-Type: text/plain\n') # FIXME: Note that we don't ensure there is a trailing newline! # This mirrors actual (Mac) DRT behavior but is a bug. if output.text: self._stdout.write(output.text) self._stdout.write('#EOF\n') if test_input.should_run_pixel_test and output.image_hash: self._stdout.write('\n') self._stdout.write('ActualHash: %s\n' % output.image_hash) self._stdout.write('ExpectedHash: %s\n' % test_input.image_hash) if output.image_hash != test_input.image_hash: self._stdout.write('Content-Type: image/png\n') self._stdout.write('Content-Length: %s\n' % len(output.image)) self._stdout.write(output.image) self._stdout.write('#EOF\n') self._stdout.flush() self._stderr.write('#EOF\n') self._stderr.flush() if __name__ == '__main__': # Note that the Mock in MockDRT refers to the fact that it is emulating a # real DRT, and as such, it needs access to a real SystemHost, not a MockSystemHost. sys.exit( main(sys.argv[1:], SystemHost(), sys.stdin, sys.stdout, sys.stderr))
def platform_info(self): return SystemHost().platform
def __init__(self, file_path, handle_style_error, host=None): self._file_path = file_path self._handle_style_error = handle_style_error self._host = host or SystemHost() self._fs = self._host.filesystem