def test_start_cmd(self): # Fails on win - see https://bugs.webkit.org/show_bug.cgi?id=84726 if sys.platform == 'win32': return def fake_pid(_): host.filesystem.write_text_file('/tmp/WebKit/httpd.pid', '42') return True host = MockHost() host.executive = MockExecutive(should_log=True) test_port = test.TestPort(host) host.filesystem.write_text_file(test_port.path_to_apache_config_file(), '') server = ApacheHTTP(test_port, '/mock/output_dir', additional_dirs=[], number_of_servers=4) server._check_that_all_ports_are_available = lambda: True server._is_server_running_on_all_ports = lambda: True server._wait_for_action = fake_pid oc = OutputCapture() try: oc.capture_output() server.start() server.stop() finally: _, _, logs = oc.restore_output() self.assertIn('StartServers 4', logs) self.assertIn('MinSpareServers 4', logs) self.assertIn('MaxSpareServers 4', logs)
def run_test(self, tests, expected_stdout, platform='test-win-win7', **kwargs): options_defaults = { 'all': False, 'csv': False, 'full': False, 'platform': platform, 'include_keyword': [], 'exclude_keyword': [], 'paths': False, } options_defaults.update(kwargs) options = optparse.Values(dict(**options_defaults)) tool = MockBlinkTool() tool.port_factory.all_port_names = lambda: [ 'test-linux-trusty', 'test-linux-precise', 'test-mac-mac10.11', 'test-mac-mac10.10', 'test-win-win10', 'test-win-win7' ] command = PrintExpectations() oc = OutputCapture() try: oc.capture_output() command.execute(options, tests, tool) finally: stdout, _, _ = oc.restore_output() self.assertMultiLineEqual(stdout, expected_stdout)
def test_parse_warnings_are_logged_if_not_in_lint_mode(self): oc = OutputCapture() try: oc.capture_output() self.parse_exp('-- this should be a syntax error', is_lint_mode=False) finally: _, _, logs = oc.restore_output() self.assertNotEquals(logs, '')
def test_help_command(self): oc = OutputCapture() oc.capture_output() tool = BlinkTool('path') tool.main(['tool', 'help']) out, err, logs = oc.restore_output() self.assertTrue(out.startswith('Usage: ')) self.assertEqual('', err) self.assertEqual('', logs)
class OutputCaptureTest(unittest.TestCase): def setUp(self): self.output = OutputCapture() def log_all_levels(self): _log.info('INFO') _log.warning('WARN') _log.error('ERROR') _log.critical('CRITICAL') def assert_logged(self, expected_logs): actual_stdout, actual_stderr, actual_logs = self.output.restore_output( ) self.assertEqual('', actual_stdout) self.assertEqual('', actual_stderr) self.assertMultiLineEqual(expected_logs, actual_logs) def test_initial_log_level(self): self.output.capture_output() self.log_all_levels() self.assert_logged('INFO\nWARN\nERROR\nCRITICAL\n') def test_set_log_level(self): self.output.set_log_level(logging.ERROR) self.output.capture_output() self.log_all_levels() self.output.set_log_level(logging.WARN) self.log_all_levels() self.assert_logged('ERROR\nCRITICAL\nWARN\nERROR\nCRITICAL\n')
def test_skipped_entry_dont_exist(self): port = MockHost().port_factory.get( 'test-win-win7', options=optparse.Values({'ignore_tests': ['foo/bar/baz.html']})) expectations_dict = OrderedDict() expectations_dict['expectations'] = '' port.expectations_dict = lambda: expectations_dict capture = OutputCapture() capture.capture_output() TestExpectations(port) _, _, logs = capture.restore_output() self.assertEqual('The following test foo/bar/baz.html from the Skipped list doesn\'t exist\n', logs)
def test_help_argument(self): oc = OutputCapture() oc.capture_output() tool = BlinkTool('path') try: tool.main(['tool', '--help']) except SystemExit: pass # optparse calls sys.exit after showing help. finally: out, err, logs = oc.restore_output() self.assertTrue(out.startswith('Usage: ')) self.assertEqual('', err) self.assertEqual('', logs)
def assert_execute_outputs(self, command, args=None, expected_stdout='', expected_stderr='', expected_exception=None, expected_logs=None, options=optparse.Values(), tool=MockBlinkTool()): args = args or [] options.blocks = None options.cc = 'MOCK cc' options.component = 'MOCK component' options.confirm = True options.email = 'MOCK email' options.git_commit = 'MOCK git commit' options.obsolete_patches = True options.open_bug = True options.port = 'MOCK port' options.update_changelogs = False options.quiet = True options.reviewer = 'MOCK reviewer' OutputCapture().assert_outputs(self, command.execute, [options, args, tool], expected_stdout=expected_stdout, expected_stderr=expected_stderr, expected_exception=expected_exception, expected_logs=expected_logs)
def test_rebaseline_reftest(self): # pylint: disable=protected-access self._write('userscripts/another-test.html', 'test data') self._write('userscripts/another-test-expected.html', 'generic result') OutputCapture().assert_outputs( self, self.command._rebaseline_test_and_update_expectations, args=[self.options(suffixes='png')], expected_logs='Cannot rebaseline image result for reftest: userscripts/another-test.html\n') self.assertDictEqual(self.command.expectation_line_changes.to_dict(), {'remove-lines': []})
def run_prompt_test(inputs, expected_result, can_choose_multiple=False): def mock_raw_input(_): return inputs.pop(0) output_capture = OutputCapture() actual_result = output_capture.assert_outputs( self, User.prompt_with_list, args=['title', ['foo', 'bar']], kwargs={ 'can_choose_multiple': can_choose_multiple, 'input_func': mock_raw_input }, expected_stdout='title\n 1. foo\n 2. bar\n') self.assertEqual(actual_result, expected_result) self.assertEqual(len(inputs), 0)
def test_rebaseline_test_internal_with_port_that_lacks_buildbot(self): self.tool.executive = MockExecutive() port = self.tool.port_factory.get('test-win-win7') baseline_relative_path = 'platform/test-win-win10/failures/expected/image-expected.txt' baseline_local_absolute_path = port.host.filesystem.join( port.web_tests_dir(), baseline_relative_path) self._write(baseline_local_absolute_path, 'original win10 result') actual_result_url = ( 'https://test-results.appspot.com/data/layout_results/MOCK_Win10/' + 'results/layout-test-results/failures/expected/image-actual.txt') self.tool.web.urls[actual_result_url] = 'new win10 result' oc = OutputCapture() try: options = optparse.Values({ 'optimize': True, 'builder': 'MOCK Win10', 'port_name': None, 'suffixes': 'txt', 'verbose': True, 'test': 'failures/expected/image.html', 'results_directory': None, 'build_number': None, 'step_name': None, }) oc.capture_output() self.command.execute(options, [], self.tool) finally: out, _, _ = oc.restore_output() self.assertItemsEqual(self.tool.web.urls_fetched, [actual_result_url]) self.assertMultiLineEqual(self._read(baseline_local_absolute_path), 'new win10 result') self.assertFalse( self.tool.filesystem.exists( self.tool.filesystem.join( port.web_tests_dir(), 'platform/test-win-win7/failures/expected/image-expected.txt' ))) self.assertMultiLineEqual( out, '{"remove-lines": [{"test": "failures/expected/image.html", "port_name": "test-win-win10"}]}\n' )
def test_rebaseline_test_internal_with_port_that_lacks_buildbot(self): self.tool.executive = MockExecutive() port = self.tool.port_factory.get('test-win-win7') self._write( port.host.filesystem.join( port.layout_tests_dir(), 'platform/test-win-win10/failures/expected/image-expected.txt' ), 'original win10 result') oc = OutputCapture() try: options = optparse.Values({ 'optimize': True, 'builder': 'MOCK Win10', 'port_name': None, 'suffixes': 'txt', 'verbose': True, 'test': 'failures/expected/image.html', 'results_directory': None, 'build_number': None, 'step_name': None, }) oc.capture_output() self.command.execute(options, [], self.tool) finally: out, _, _ = oc.restore_output() self.assertMultiLineEqual( self._read( self.tool.filesystem.join( port.layout_tests_dir(), 'platform/test-win-win10/failures/expected/image-expected.txt' )), 'MOCK Web result, convert 404 to None=True') self.assertFalse( self.tool.filesystem.exists( self.tool.filesystem.join( port.layout_tests_dir(), 'platform/test-win-win7/failures/expected/image-expected.txt' ))) self.assertMultiLineEqual( out, '{"remove-lines": [{"test": "failures/expected/image.html", "port_name": "test-win-win10"}]}\n' )
def test_required_arguments(self): class TrivialCommandWithRequiredAndOptionalArgs(TrivialCommand): argument_names = "ARG1 ARG2 [ARG3]" two_required_arguments = TrivialCommandWithRequiredAndOptionalArgs() expected_logs = ( "2 arguments required, 1 argument provided. Provided: 'foo' Required: ARG1 ARG2\n" "See 'dummy-tool help trivial' for usage.\n") exit_code = OutputCapture().assert_outputs( self, two_required_arguments.check_arguments_and_execute, [None, ["foo"], DummyTool()], expected_logs=expected_logs) self.assertEqual(exit_code, 1)
def test_rebaseline_reftest_with_text(self): # pylint: disable=protected-access self._write('userscripts/another-test.html', 'test data') self._write('userscripts/another-test-expected.html', 'generic result') self._write('userscripts/another-test-expected.txt', 'text') OutputCapture().assert_outputs( self, self.command._rebaseline_test_and_update_expectations, args=[self.options(suffixes='png,txt')], expected_logs= 'Cannot rebaseline image result for reftest: userscripts/another-test.html\n' ) six.assertCountEqual( self, self.tool.web.urls_fetched, [self.WEB_PREFIX + '/userscripts/another-test-actual.txt']) self.assertDictEqual(self.command.expectation_line_changes.to_dict(), {'remove-lines': []})
def capture_output(self): self.oc = OutputCapture() self.oc.capture_output()
class PrintBaselinesTest(unittest.TestCase): def setUp(self): self.oc = None self.tool = MockBlinkTool() self.test_port = self.tool.port_factory.get('test-win-win7') self.tool.port_factory.get = lambda port_name=None: self.test_port self.tool.port_factory.all_port_names = lambda: [ 'test-linux-trusty', 'test-linux-precise', 'test-mac-mac10.11', 'test-mac-mac10.10', 'test-win-win10', 'test-win-win7' ] def tearDown(self): if self.oc: self.restore_output() def capture_output(self): self.oc = OutputCapture() self.oc.capture_output() def restore_output(self): stdout, stderr, logs = self.oc.restore_output() self.oc = None return (stdout, stderr, logs) def test_basic(self): command = PrintBaselines() self.capture_output() options = optparse.Values({ 'all': False, 'include_virtual_tests': False, 'csv': False, 'platform': None }) command.execute(options, ['passes/text.html'], self.tool) stdout, _, _ = self.restore_output() self.assertMultiLineEqual(stdout, ('// For test-win-win7\n' 'passes/text-expected.png\n' 'passes/text-expected.txt\n')) def test_multiple(self): command = PrintBaselines() self.capture_output() options = optparse.Values({ 'all': False, 'include_virtual_tests': False, 'csv': False, 'platform': 'test-win-*' }) command.execute(options, ['passes/text.html'], self.tool) stdout, _, _ = self.restore_output() self.assertMultiLineEqual(stdout, ('// For test-win-win10\n' 'passes/text-expected.png\n' 'passes/text-expected.txt\n' '\n' '// For test-win-win7\n' 'passes/text-expected.png\n' 'passes/text-expected.txt\n')) def test_csv(self): command = PrintBaselines() self.capture_output() options = optparse.Values({ 'all': False, 'platform': '*win7', 'csv': True, 'include_virtual_tests': False }) command.execute(options, ['passes/text.html'], self.tool) stdout, _, _ = self.restore_output() self.assertMultiLineEqual(stdout, ( 'test-win-win7,passes/text.html,None,png,passes/text-expected.png,None\n' 'test-win-win7,passes/text.html,None,txt,passes/text-expected.txt,None\n' ))
def setUp(self): self.output = OutputCapture()