Commit f633d337 authored by ojan@chromium.org's avatar ojan@chromium.org

Minor cleanups to flakytests.py

-Pass -f instead of setting EDITOR.
-Put a message at the top of FlakyTests saying it's autogenerated.
-Add a test that goes through the upload codepath.
-Have ExecutiveMock log calls to run_and_throw_if_fail.

Review URL: https://codereview.chromium.org/312103005

git-svn-id: svn://svn.chromium.org/blink/trunk@175821 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent e41ee281
......@@ -83,6 +83,7 @@ class MockExecutive(object):
return running_pids
def run_and_throw_if_fail(self, args, quiet=False, cwd=None, env=None):
self.calls.append(args)
if self._should_log:
env_string = ""
if env:
......
......@@ -46,6 +46,17 @@ class FlakyTests(AbstractDeclarativeCommand):
'eseidel@chromium.org',
]
COMMIT_MESSAGE = (
'Update FlakyTests to match current flakiness dashboard results\n\n'
'Automatically generated using:\n'
'webkit-patch update-flaky-tests\n\n'
'R=%s\n')
FLAKY_TEST_CONTENTS = (
'# This file is generated by webkit-patch update-flaky-tests from the flakiness dashboard data.\n'
'# Manual changes will be overwritten.\n\n'
'%s\n')
def __init__(self):
options = [
optparse.make_option('--upload', action='store_true',
......@@ -82,23 +93,12 @@ class FlakyTests(AbstractDeclarativeCommand):
print "No gardener, and --reviewers not specified, not bothering."
return 1
commit_message = """Update FlakyTests to match current flakiness dashboard results
Automatically generated using:
webkit-patch update-flaky-tests
R=%s
""" % ','.join(reviewer_emails)
commit_message = self.COMMIT_MESSAGE % ','.join(reviewer_emails)
git_cmd = ['git', 'commit', '-m', commit_message,
tool.filesystem.join(tool.scm().checkout_root, flaky_tests_path)]
tool.executive.run_and_throw_if_fail(git_cmd)
# FIXME: There must be a cleaner way to avoid the editor!
# Silence the editor.
os.environ['EDITOR'] = 'true'
git_cmd = ['git', 'cl', 'upload', '--send-mail',
git_cmd = ['git', 'cl', 'upload', '--send-mail', '-f',
'--cc', ','.join(self.ALWAYS_CC)]
tool.executive.run_and_throw_if_fail(git_cmd)
......@@ -116,7 +116,8 @@ R=%s
# in existing TestExpectations. We could certainly load existing TestExpecations
# and filter accordingly, or update existing TestExpectations instead of FlakyTests.
flaky_tests_path = fs.join(port.layout_tests_dir(), 'FlakyTests')
fs.write_text_file(flaky_tests_path, TestExpectations.list_to_string(lines))
flaky_tests_contents = self.FLAKY_TEST_CONTENTS % TestExpectations.list_to_string(lines)
fs.write_text_file(flaky_tests_path, flaky_tests_contents)
print "Updated %s" % flaky_tests_path
if options.upload:
......
......@@ -2,11 +2,12 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import flakytests
from webkitpy.common.checkout.scm.scm_mock import MockSCM
from webkitpy.tool.commands.commandtest import CommandsTest
from webkitpy.tool.mocktool import MockTool, MockOptions
import flakytests
class FakeBotTestExpectations(object):
def expectation_lines(self, only_ignore_very_flaky=False):
......@@ -18,6 +19,11 @@ class FakeBotTestExpectationsFactory(object):
return FakeBotTestExpectations()
class ChangedExpectationsMockSCM(MockSCM):
def changed_files(self):
return ['LayoutTests/FlakyTests']
class FlakyTestsTest(CommandsTest):
def test_simple(self):
command = flakytests.FlakyTests()
......@@ -27,9 +33,32 @@ class FlakyTestsTest(CommandsTest):
def test_integration(self):
command = flakytests.FlakyTests()
tool = MockTool()
command.expectations_factory = FakeBotTestExpectationsFactory
options = MockOptions(upload=True)
expected_stdout = """Updated /mock-checkout/third_party/WebKit/LayoutTests/FlakyTests
LayoutTests/FlakyTests is not changed, not uploading.
"""
self.assert_execute_outputs(command, options=options, expected_stdout=expected_stdout)
self.assert_execute_outputs(command, options=options, tool=tool, expected_stdout=expected_stdout)
port = tool.port_factory.get()
self.assertEqual(tool.filesystem.read_text_file(tool.filesystem.join(port.layout_tests_dir(), 'FlakyTests')), command.FLAKY_TEST_CONTENTS % '')
def test_integration_uploads(self):
command = flakytests.FlakyTests()
tool = MockTool()
tool.scm = ChangedExpectationsMockSCM
command.expectations_factory = FakeBotTestExpectationsFactory
reviewer = 'foo@chromium.org'
options = MockOptions(upload=True, reviewers=reviewer)
expected_stdout = """Updated /mock-checkout/third_party/WebKit/LayoutTests/FlakyTests
"""
self.assert_execute_outputs(command, options=options, tool=tool, expected_stdout=expected_stdout)
self.assertEqual(tool.executive.calls,
[
['git', 'commit', '-m', command.COMMIT_MESSAGE % reviewer, '/mock-checkout/third_party/WebKit/LayoutTests/FlakyTests'],
['git', 'cl', 'upload', '--send-mail', '-f', '--cc', 'ojan@chromium.org,dpranke@chromium.org,eseidel@chromium.org'],
])
port = tool.port_factory.get()
self.assertEqual(tool.filesystem.read_text_file(tool.filesystem.join(port.layout_tests_dir(), 'FlakyTests')), command.FLAKY_TEST_CONTENTS % '')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment