Changeset 58285 in webkit


Ignore:
Timestamp:
Apr 26, 2010 9:21:33 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-04-26 Eric Seidel <eric@webkit.org>

Reviewed by Adam Barth.

Refactor results.html generation out into a new method and test it
https://bugs.webkit.org/show_bug.cgi?id=38164

Hopefully this results in no change in functionality.

  • Scripts/webkitpy/layout_tests/run_webkit_tests.py:
  • Scripts/webkitpy/layout_tests/run_webkit_tests_unittest.py:
Location:
trunk/WebKitTools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r58282 r58285  
     12010-04-26  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Refactor results.html generation out into a new method and test it
     6        https://bugs.webkit.org/show_bug.cgi?id=38164
     7
     8        Hopefully this results in no change in functionality.
     9
     10        * Scripts/webkitpy/layout_tests/run_webkit_tests.py:
     11        * Scripts/webkitpy/layout_tests/run_webkit_tests_unittest.py:
     12
    1132010-04-26  Adam Barth  <abarth@webkit.org>
    214
  • trunk/WebKitTools/Scripts/webkitpy/layout_tests/run_webkit_tests.py

    r58183 r58285  
    14051405            print "-" * 78
    14061406
     1407    def _results_html(self, test_files, failures, title="Test Failures", override_time=None):
     1408        """
     1409        test_files = a list of file paths
     1410        failures = dictionary mapping test paths to failure objects
     1411        title = title printed at top of test
     1412        override_time = current time (used by unit tests)
     1413        """
     1414        page = """<html>
     1415  <head>
     1416    <title>Layout Test Results (%(time)s)</title>
     1417  </head>
     1418  <body>
     1419    <h2>%(title)s (%(time)s)</h2>
     1420        """ % {'title': title, 'time': override_time or time.asctime()}
     1421
     1422        for test_file in sorted(test_files):
     1423            test_name = self._port.relative_test_filename(test_file)
     1424            test_url = self._port.filename_to_uri(test_file)
     1425            page += u"<p><a href='%s'>%s</a><br />\n" % (test_url, test_name)
     1426            test_failures = failures.get(test_file, [])
     1427            for failure in test_failures:
     1428                page += u"&nbsp;&nbsp;%s<br/>" % failure.result_html_output(test_name)
     1429            page += "</p>\n"
     1430        page += "</body></html>\n"
     1431        return page
     1432
    14071433    def _write_results_html_file(self, result_summary):
    14081434        """Write results.html which is a summary of tests that failed.
     
    14171443        # test failures
    14181444        if self._options.full_results_html:
     1445            results_title = "Test Failures"
    14191446            test_files = result_summary.failures.keys()
    14201447        else:
     1448            results_title = "Unexpected Test Failures"
    14211449            unexpected_failures = self._get_failures(result_summary,
    14221450                include_crashes=True)
     
    14271455        out_filename = os.path.join(self._options.results_directory,
    14281456                                    "results.html")
    1429         # FIXME: This should be re-written to prepare the string first
    1430         # so that the "open" call can be wrapped in a with statement.
    1431         out_file = codecs.open(out_filename, "w", "utf-8")
    1432         # header
    1433         if self._options.full_results_html:
    1434             h2 = "Test Failures"
    1435         else:
    1436             h2 = "Unexpected Test Failures"
    1437         out_file.write("<html><head><title>Layout Test Results (%(time)s)"
    1438                        "</title></head><body><h2>%(h2)s (%(time)s)</h2>\n"
    1439                        % {'h2': h2, 'time': time.asctime()})
    1440 
    1441         test_files.sort()
    1442         for test_file in test_files:
    1443             test_failures = result_summary.failures.get(test_file, [])
    1444             out_file.write(u"<p><a href='%s'>%s</a><br />\n"
    1445                            % (self._port.filename_to_uri(test_file),
    1446                               self._port.relative_test_filename(test_file)))
    1447             for failure in test_failures:
    1448                 out_file.write(u"&nbsp;&nbsp;%s<br/>"
    1449                                % failure.result_html_output(
    1450                                  self._port.relative_test_filename(test_file)))
    1451             out_file.write("</p>\n")
    1452 
    1453         # footer
    1454         out_file.write("</body></html>\n")
    1455         out_file.close()
     1457        with codecs.open(out_filename, "w", "utf-8") as results_file:
     1458            html = self._results_html(test_files, result_summary.failures, results_title)
     1459            results_file.write(html)
     1460
    14561461        return True
    14571462
  • trunk/WebKitTools/Scripts/webkitpy/layout_tests/run_webkit_tests_unittest.py

    r57872 r58285  
    3636import webkitpy.layout_tests.run_webkit_tests as run_webkit_tests
    3737
     38from webkitpy.thirdparty.mock import Mock
     39
    3840
    3941def passing_run(args):
     
    5860
    5961
     62class TestRunnerTest(unittest.TestCase):
     63    def test_results_html(self):
     64        mock_port = Mock()
     65        mock_port.relative_test_filename = lambda name: name
     66        mock_port.filename_to_uri = lambda name: name
     67
     68        runner = run_webkit_tests.TestRunner(port=mock_port, options=Mock(), meter=Mock())
     69        expected_html = u"""<html>
     70  <head>
     71    <title>Layout Test Results (time)</title>
     72  </head>
     73  <body>
     74    <h2>Title (time)</h2>
     75        <p><a href='test_path'>test_path</a><br />
     76</p>
     77</body></html>
     78"""
     79        html = runner._results_html(["test_path"], {}, "Title", override_time="time")
     80        self.assertEqual(html, expected_html)
     81
     82
    6083class DryrunTest(unittest.TestCase):
    6184    def test_basics(self):
Note: See TracChangeset for help on using the changeset viewer.