⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 252443 in webkit


Ignore:
Timestamp:
Nov 13, 2019, 6:08:56 PM (7 years ago)
Author:
Jonathan Bedard
Message:

Python 3: Add support in webkitpy.layout_tests.controllers
https://bugs.webkit.org/show_bug.cgi?id=204180

Reviewed by Stephanie Lewis.

  • Scripts/test-webkitpy-python3: Add webkitpy.layout_tests.controllers.
  • Scripts/webkitpy/common/message_pool.py:

(_MessagePool.init): Use Python 3 queue syntax.
(_MessagePool._can_pickle): Use Python 3 pickle syntax.
(_MessagePool._loop): Use Python 3 queue syntax.
(_Worker.run): Use Python 3 queue syntax.
(_Worker._raise): Python 2 and Python 3 have different semantics for raising an exception
With a stack trace. However, 'raise' will raise the exception we are in the process of capturing,
Which is exactly what we want in this case.

  • Scripts/webkitpy/common/read_checksum_from_png.py:

(read_checksum): Standardize checksum as a string.

  • Scripts/webkitpy/common/system/filesystem.py:

(FileSystem.write_binary_file): Binary files should be written with bytes, not strings.

  • Scripts/webkitpy/common/system/filesystem_mock.py:

(MockFileSystem.write_binary_file): Binary files should be written with bytes, not strings.

  • Scripts/webkitpy/layout_tests/controllers/layout_test_finder_unittest.py: assertItemsEqual is not

Defined in Python 3.

  • Scripts/webkitpy/layout_tests/controllers/layout_test_runner.py:

(Worker._do_post_tests_work): Use compatible iteritems.
(Sharder._shard_by_directory): Ditto.

  • Scripts/webkitpy/layout_tests/controllers/manager.py:

(Manager.run): Use compatible itervalues.
(Manager._look_for_new_crash_logs): Use Python 3 item iteration.
(Manager._results_to_upload_json_trie): Use compatible itervalues.
(Manager._stats_trie): Use compatible iteritems.

  • Scripts/webkitpy/port/base.py:

(Port.expected_text): Be explicit about decoding text expectations.

  • Scripts/webkitpy/port/mock_drt.py:

(MockDRT.write_test_output):

Location:
trunk/Tools
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r252442 r252443  
     12019-11-13  Jonathan Bedard  <jbedard@apple.com>
     2
     3        Python 3: Add support in webkitpy.layout_tests.controllers
     4        https://bugs.webkit.org/show_bug.cgi?id=204180
     5
     6        Reviewed by Stephanie Lewis.
     7
     8        * Scripts/test-webkitpy-python3: Add webkitpy.layout_tests.controllers.
     9        * Scripts/webkitpy/common/message_pool.py:
     10        (_MessagePool.__init__): Use Python 3 queue syntax.
     11        (_MessagePool._can_pickle): Use Python 3 pickle syntax.
     12        (_MessagePool._loop): Use Python 3 queue syntax.
     13        (_Worker.run): Use Python 3 queue syntax.
     14        (_Worker._raise): Python 2 and Python 3 have different semantics for raising an exception
     15        With a stack trace. However, 'raise' will raise the exception we are in the process of capturing,
     16        Which is exactly what we want in this case.
     17        * Scripts/webkitpy/common/read_checksum_from_png.py:
     18        (read_checksum): Standardize checksum as a string.
     19        * Scripts/webkitpy/common/system/filesystem.py:
     20        (FileSystem.write_binary_file): Binary files should be written with bytes, not strings.
     21        * Scripts/webkitpy/common/system/filesystem_mock.py:
     22        (MockFileSystem.write_binary_file): Binary files should be written with bytes, not strings.
     23        * Scripts/webkitpy/layout_tests/controllers/layout_test_finder_unittest.py: assertItemsEqual is not
     24        Defined in Python 3.
     25        * Scripts/webkitpy/layout_tests/controllers/layout_test_runner.py:
     26        (Worker._do_post_tests_work): Use compatible iteritems.
     27        (Sharder._shard_by_directory): Ditto.
     28        * Scripts/webkitpy/layout_tests/controllers/manager.py:
     29        (Manager.run): Use compatible itervalues.
     30        (Manager._look_for_new_crash_logs): Use Python 3 item iteration.
     31        (Manager._results_to_upload_json_trie): Use compatible itervalues.
     32        (Manager._stats_trie): Use compatible iteritems.
     33        * Scripts/webkitpy/port/base.py:
     34        (Port.expected_text): Be explicit about decoding text expectations.
     35        * Scripts/webkitpy/port/mock_drt.py:
     36        (MockDRT.write_test_output):
     37
    1382019-11-13  Per Arne Vollan  <pvollan@apple.com>
    239
  • trunk/Tools/Scripts/test-webkitpy-python3

    r252440 r252443  
    3636PYTHON3_COMPATIBLE_DIRECTORIES = [
    3737  'webkitpy.common',
     38  'webkitpy.layout_tests.controllers',
    3839  'webkitpy.layout_tests.models',
    3940  'webkitpy.port',
  • trunk/Tools/Scripts/webkitpy/common/message_pool.py

    r244571 r252443  
    4141"""
    4242
    43 import cPickle
    4443import logging
    4544import multiprocessing
    4645import os
    47 import Queue
    4846import signal
    4947import sys
     
    5149import traceback
    5250
     51if sys.version_info > (3, 0):
     52    import pickle
     53    import queue
     54else:
     55    import cPickle as pickle
     56    import Queue as queue
    5357
    5458from webkitpy.common.host import Host
     
    7781        self._timeout = timeout
    7882        if self._running_inline:
    79             self._messages_to_worker = Queue.Queue()
    80             self._messages_to_manager = Queue.Queue()
     83            self._messages_to_worker = queue.Queue()
     84            self._messages_to_manager = queue.Queue()
    8185        else:
    8286            self._messages_to_worker = multiprocessing.Queue()
     
    176180    def _can_pickle(self, host):
    177181        try:
    178             cPickle.dumps(host)
     182            pickle.dumps(host)
    179183            return True
    180184        except TypeError:
     
    194198                assert method, 'bad message %s' % repr(message)
    195199                method(message.src, *message.args)
    196         except Queue.Empty:
     200        except queue.Empty:
    197201            pass
    198202
     
    273277
    274278            _log.debug("%s exiting" % self.name)
    275         except Queue.Empty:
     279        except queue.Empty:
    276280            assert False, '%s: ran out of messages in worker queue.' % self.name
    277281        except KeyboardInterrupt as e:
     
    303307        exception_type, exception_value, exception_traceback = exc_info
    304308        if self._running_inline:
    305             raise exception_type, exception_value, exception_traceback
     309            raise
    306310
    307311        if exception_type == KeyboardInterrupt:
  • trunk/Tools/Scripts/webkitpy/common/read_checksum_from_png.py

    r136545 r252443  
    2828
    2929
     30from webkitpy.common.unicode_compatibility import encode_if_necessary, decode_for
     31
    3032def read_checksum(filehandle):
    3133    # We expect the comment to be at the beginning of the file.
    32     data = filehandle.read(2048)
    33     comment_key = 'tEXtchecksum\x00'
     34    data = encode_if_necessary(filehandle.read(2048))
     35    comment_key = b'tEXtchecksum\x00'
    3436    comment_pos = data.find(comment_key)
    3537    if comment_pos == -1:
     
    3739
    3840    checksum_pos = comment_pos + len(comment_key)
    39     return data[checksum_pos:checksum_pos + 32]
     41    return decode_for(data[checksum_pos:checksum_pos + 32], str)
  • trunk/Tools/Scripts/webkitpy/common/system/filesystem.py

    r250375 r252443  
    4040import time
    4141
    42 from webkitpy.common.unicode_compatibility import decode_if_necessary
     42from webkitpy.common.unicode_compatibility import decode_if_necessary, encode_for
    4343
    4444
     
    228228    def write_binary_file(self, path, contents):
    229229        with open(path, 'wb') as f:
    230             f.write(contents)
     230            f.write(encode_for(contents, bytes))
    231231
    232232    def open_text_file_for_reading(self, path, errors='strict'):
  • trunk/Tools/Scripts/webkitpy/common/system/filesystem_mock.py

    r251608 r252443  
    330330        # FIXME: should this assert if dirname(path) doesn't exist?
    331331        self.maybe_make_directory(self.dirname(path))
    332         self.files[path] = contents
    333         self.written_files[path] = contents
     332        self.files[path] = unicode_compatibility.encode_for(contents, bytes)
     333        self.written_files[path] = unicode_compatibility.encode_for(contents, bytes)
    334334
    335335    def open_text_file_for_reading(self, path, errors='strict'):
  • trunk/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_finder_unittest.py

    r240150 r252443  
    5656        paths = ['LayoutTests/test.html', 'LayoutTests/test', 'test2.html', 'Source/test1.html']
    5757        fs, touched_tests = self.touched_files(paths)
    58         self.assertItemsEqual(touched_tests, ['test.html'])
     58        self.assertEqual(touched_tests, ['test.html'])
    5959
    6060    def test_expected_touched_test(self):
     
    6363        fs.write_text_file('/test.checkout/LayoutTests/test.html', 'This is a test')
    6464        fs, touched_tests = self.touched_files(paths, fs)
    65         self.assertItemsEqual(touched_tests, ['test.html'])
     65        self.assertEqual(touched_tests, ['test.html'])
    6666
    6767    def test_platform_expected_touched_test(self):
     
    7070        fs.write_text_file('/test.checkout/LayoutTests/test.html', 'This is a test')
    7171        fs, touched_tests = self.touched_files(paths, fs)
    72         self.assertItemsEqual(touched_tests, ['test.html'])
     72        self.assertEqual(touched_tests, ['test.html'])
    7373
    7474    def test_platform_duplicate_touched_test(self):
     
    7777        fs.write_text_file('/test.checkout/LayoutTests/test2.html', 'This is a test')
    7878        fs, touched_tests = self.touched_files(paths, fs)
    79         self.assertItemsEqual(touched_tests, ['test1.html', 'test2.html'])
     79        self.assertEqual(sorted(touched_tests), sorted(['test1.html', 'test2.html']))
    8080
    8181    def test_touched_but_skipped_test(self):
     
    9393
    9494        touched_tests = LayoutTestFinder(port, optparse.Values({'skipped': 'always', 'skip_failing_tests': False, 'http': True})).find_touched_tests(paths)
    95         self.assertItemsEqual(touched_tests, ['test0.html', 'test2.html'])
     95        self.assertEqual(sorted(touched_tests), sorted(['test0.html', 'test2.html']))
  • trunk/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_runner.py

    r239989 r252443  
    3434
    3535from webkitpy.common import message_pool
     36from webkitpy.common.iteration_compatibility import iteritems
    3637from webkitpy.layout_tests.controllers import single_test_runner
    3738from webkitpy.layout_tests.models.test_run_results import TestRunResults
     
    332333        post_test_output = driver.do_post_tests_work()
    333334        if post_test_output:
    334             for test_name, doc_list in post_test_output.world_leaks_dict.iteritems():
     335            for test_name, doc_list in iteritems(post_test_output.world_leaks_dict):
    335336                additional_results.append(test_results.TestResult(test_name, [test_failures.FailureDocumentLeak(doc_list)]))
    336337        return additional_results
     
    537538            tests_by_dir[directory].append(test_input)
    538539
    539         for directory, test_inputs in tests_by_dir.iteritems():
     540        for directory, test_inputs in iteritems(tests_by_dir):
    540541            shard = TestShard(directory, test_inputs)
    541542            shards.append(shard)
  • trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py

    r249652 r252443  
    4545from webkitpy.common.checkout.scm.detection import SCMDetector
    4646from webkitpy.common.net.file_uploader import FileUploader
     47from webkitpy.common.iteration_compatibility import iteritems, itervalues
    4748from webkitpy.layout_tests.controllers.layout_test_finder import LayoutTestFinder
    4849from webkitpy.layout_tests.controllers.layout_test_runner import LayoutTestRunner
     
    219220
    220221        # Check to make sure we're not skipping every test.
    221         if not sum([len(tests) for tests in tests_to_run_by_device.itervalues()]):
     222        if not sum([len(tests) for tests in itervalues(tests_to_run_by_device)]):
    222223            _log.critical('No tests to run.')
    223224            return test_run_results.RunDetails(exit_code=-1)
    224225
    225         needs_http = any((self._is_http_test(test) and not self._needs_web_platform_test(test)) for tests in tests_to_run_by_device.itervalues() for test in tests)
    226         needs_web_platform_test_server = any(self._needs_web_platform_test(test) for tests in tests_to_run_by_device.itervalues() for test in tests)
    227         needs_websockets = any(self._is_websocket_test(test) for tests in tests_to_run_by_device.itervalues() for test in tests)
     226        needs_http = any((self._is_http_test(test) and not self._needs_web_platform_test(test)) for tests in itervalues(tests_to_run_by_device) for test in tests)
     227        needs_web_platform_test_server = any(self._needs_web_platform_test(test) for tests in itervalues(tests_to_run_by_device) for test in tests)
     228        needs_websockets = any(self._is_websocket_test(test) for tests in itervalues(tests_to_run_by_device) for test in tests)
    228229        self._runner = LayoutTestRunner(self._options, self._port, self._printer, self._results_directory, self._test_is_slow,
    229230                                        needs_http=needs_http, needs_web_platform_test_server=needs_web_platform_test_server, needs_websockets=needs_websockets)
     
    428429        """
    429430        crashed_processes = []
    430         for test, result in run_results.unexpected_results_by_name.iteritems():
     431        for test, result in run_results.unexpected_results_by_name.items():
    431432            if (result.type != test_expectations.CRASH):
    432433                continue
     
    438439        sample_files = self._port.look_for_new_samples(crashed_processes, start_time)
    439440        if sample_files:
    440             for test, sample_file in sample_files.iteritems():
     441            for test, sample_file in sample_files.items():
    441442                writer = TestResultWriter(self._port._filesystem, self._port, self._port.results_directory(), test)
    442443                writer.copy_sample_file(sample_file)
     
    444445        crash_logs = self._port.look_for_new_crash_logs(crashed_processes, start_time)
    445446        if crash_logs:
    446             for test, crash_log in crash_logs.iteritems():
     447            for test, crash_log in crash_logs.items():
    447448                writer = TestResultWriter(self._port._filesystem, self._port, self._port.results_directory(), test)
    448449                writer.write_crash_log(crash_log)
     
    492493
    493494        results_trie = {}
    494         for result in results.results_by_name.itervalues():
     495        for result in itervalues(results.results_by_name):
    495496            if result.type == test_expectations.SKIP:
    496497                continue
     
    646647                stats[result.test_name] = {'results': (_worker_number(result.worker_name), result.test_number, result.pid, int(result.test_run_time * 1000), int(result.total_run_time * 1000))}
    647648        stats_trie = {}
    648         for name, value in stats.iteritems():
     649        for name, value in iteritems(stats):
    649650            json_results_generator.add_path_to_trie(name, value, stats_trie)
    650651        return stats_trie
  • trunk/Tools/Scripts/webkitpy/port/base.py

    r252058 r252443  
    501501            if not self._filesystem.exists(baseline_path):
    502502                return None
    503         text = self._filesystem.read_binary_file(baseline_path)
     503        text = decode_for(self._filesystem.read_binary_file(baseline_path), str)
    504504        return text.replace("\r\n", "\n")
    505505
  • trunk/Tools/Scripts/webkitpy/port/mock_drt.py

    r233651 r252443  
    4949    sys.path.append(script_dir)
    5050
     51from webkitpy.common.unicode_compatibility import decode_for
    5152from webkitpy.common.system.systemhost import SystemHost
    5253from webkitpy.port.driver import DriverInput, DriverOutput, DriverProxy
     
    231232                self._stdout.write('Content-Type: image/png\n')
    232233                self._stdout.write('Content-Length: %s\n' % len(output.image))
    233                 self._stdout.write(output.image)
     234                self._stdout.write(decode_for(output.image, str))
    234235        self._stdout.write('#EOF\n')
    235236        self._stdout.flush()
Note: See TracChangeset for help on using the changeset viewer.