Commit d2ac4a23 authored by Quinten Yearsley's avatar Quinten Yearsley Committed by Commit Bot

Use MockGitCL in unit tests where applicable.

This simplifies rebaseline_cl_unittest and
wpt_expectations_updater_unittest.

Change-Id: I11ecc38af5fffcd3bba1def071ea63d814dd2abf
Reviewed-on: https://chromium-review.googlesource.com/581737Reviewed-by: default avatarJeff Carpenter <jeffcarp@chromium.org>
Commit-Queue: Quinten Yearsley <qyearsley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488727}
parent b7a3b140
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
from webkitpy.common.net.git_cl import GitCL from webkitpy.common.net.git_cl import GitCL
# pylint: disable=unused-argument
# TODO(qyearsley): Use this class in wpt_expectations_updater_unittest and rebaseline_cl_unittest.
class MockGitCL(object): class MockGitCL(object):
def __init__(self, host, results=None): def __init__(self, host, results=None, issue_number='1234'):
self._host = host self._host = host
self._results = results or {} self._results = results or {}
self._issue_number = issue_number
self.calls = [] self.calls = []
def run(self, args): def run(self, args):
...@@ -25,7 +26,7 @@ class MockGitCL(object): ...@@ -25,7 +26,7 @@ class MockGitCL(object):
self.run(command) self.run(command)
def get_issue_number(self): def get_issue_number(self):
return '1234' return self._issue_number
def try_job_results(self, **_): def try_job_results(self, **_):
return self._results return self._results
...@@ -33,7 +34,7 @@ class MockGitCL(object): ...@@ -33,7 +34,7 @@ class MockGitCL(object):
def wait_for_try_jobs(self, **_): def wait_for_try_jobs(self, **_):
return self._results return self._results
def latest_try_jobs(self, **_): def latest_try_jobs(self, builder_names=None):
return self.filter_latest(self._results) return self.filter_latest(self._results)
@staticmethod @staticmethod
......
...@@ -14,6 +14,7 @@ from webkitpy.tool.commands.rebaseline import AbstractParallelRebaselineCommand ...@@ -14,6 +14,7 @@ from webkitpy.tool.commands.rebaseline import AbstractParallelRebaselineCommand
from webkitpy.tool.commands.rebaseline import TestBaselineSet from webkitpy.tool.commands.rebaseline import TestBaselineSet
from webkitpy.w3c.wpt_manifest import WPTManifest from webkitpy.w3c.wpt_manifest import WPTManifest
_log = logging.getLogger(__name__) _log = logging.getLogger(__name__)
...@@ -47,9 +48,11 @@ class RebaselineCL(AbstractParallelRebaselineCommand): ...@@ -47,9 +48,11 @@ class RebaselineCL(AbstractParallelRebaselineCommand):
self.no_optimize_option, self.no_optimize_option,
self.results_directory_option, self.results_directory_option,
]) ])
self.git_cl = None
def execute(self, options, args, tool): def execute(self, options, args, tool):
self._tool = tool self._tool = tool
self.git_cl = self.git_cl or GitCL(tool)
# TODO(qyearsley): Consider calling ensure_manifest in WebKitPatch. # TODO(qyearsley): Consider calling ensure_manifest in WebKitPatch.
# See: crbug.com/698294 # See: crbug.com/698294
...@@ -58,7 +61,7 @@ class RebaselineCL(AbstractParallelRebaselineCommand): ...@@ -58,7 +61,7 @@ class RebaselineCL(AbstractParallelRebaselineCommand):
if not self.check_ok_to_run(): if not self.check_ok_to_run():
return 1 return 1
jobs = self.git_cl().latest_try_jobs(self._try_bots()) jobs = self.git_cl.latest_try_jobs(self._try_bots())
self._log_jobs(jobs) self._log_jobs(jobs)
builders_with_no_jobs = self._try_bots() - {b.builder_name for b in jobs} builders_with_no_jobs = self._try_bots() - {b.builder_name for b in jobs}
...@@ -119,21 +122,17 @@ class RebaselineCL(AbstractParallelRebaselineCommand): ...@@ -119,21 +122,17 @@ class RebaselineCL(AbstractParallelRebaselineCommand):
def _get_issue_number(self): def _get_issue_number(self):
"""Returns the current CL issue number, or None.""" """Returns the current CL issue number, or None."""
issue = self.git_cl().get_issue_number() issue = self.git_cl.get_issue_number()
if not issue.isdigit(): if not issue.isdigit():
return None return None
return int(issue) return int(issue)
def git_cl(self):
"""Returns a GitCL instance. Can be overridden for tests."""
return GitCL(self._tool)
def trigger_try_jobs(self, builders): def trigger_try_jobs(self, builders):
"""Triggers try jobs for the given builders.""" """Triggers try jobs for the given builders."""
_log.info('Triggering try jobs:') _log.info('Triggering try jobs:')
for builder in sorted(builders): for builder in sorted(builders):
_log.info(' %s', builder) _log.info(' %s', builder)
self.git_cl().trigger_try_jobs(builders) self.git_cl.trigger_try_jobs(builders)
_log.info('Once all pending try jobs have finished, please re-run\n' _log.info('Once all pending try jobs have finished, please re-run\n'
'webkit-patch rebaseline-cl to fetch new baselines.') 'webkit-patch rebaseline-cl to fetch new baselines.')
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
import json import json
import optparse import optparse
from webkitpy.common.checkout.git_mock import MockGit
from webkitpy.common.net.buildbot import Build from webkitpy.common.net.buildbot import Build
from webkitpy.common.net.git_cl import GitCL
from webkitpy.common.net.git_cl import TryJobStatus from webkitpy.common.net.git_cl import TryJobStatus
from webkitpy.common.checkout.git_mock import MockGit from webkitpy.common.net.git_cl_mock import MockGitCL
from webkitpy.common.net.layout_test_results import LayoutTestResults from webkitpy.common.net.layout_test_results import LayoutTestResults
from webkitpy.common.system.log_testing import LoggingTestCase from webkitpy.common.system.log_testing import LoggingTestCase
from webkitpy.layout_tests.builder_list import BuilderList from webkitpy.layout_tests.builder_list import BuilderList
...@@ -30,11 +30,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase): ...@@ -30,11 +30,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase):
Build('MOCK Try Linux', 6000): TryJobStatus('COMPLETED', 'FAILURE'), Build('MOCK Try Linux', 6000): TryJobStatus('COMPLETED', 'FAILURE'),
} }
# TODO(qyearsley): Add a MockGitCL class to reduce repetition below. self.command.git_cl = MockGitCL(self.tool, builds)
git_cl = GitCL(self.tool)
git_cl.get_issue_number = lambda: '11112222'
git_cl.latest_try_jobs = lambda _: builds
self.command.git_cl = lambda: git_cl
git = MockGit(filesystem=self.tool.filesystem, executive=self.tool.executive) git = MockGit(filesystem=self.tool.filesystem, executive=self.tool.executive)
git.changed_files = lambda **_: [ git.changed_files = lambda **_: [
...@@ -101,7 +97,8 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase): ...@@ -101,7 +97,8 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase):
self.mac_port.layout_tests_dir(), test) self.mac_port.layout_tests_dir(), test)
self._write(path, 'contents') self._write(path, 'contents')
self.mac_port.host.filesystem.write_text_file('/test.checkout/LayoutTests/external/wpt/MANIFEST.json', '{}') self.mac_port.host.filesystem.write_text_file(
'/test.checkout/LayoutTests/external/wpt/MANIFEST.json', '{}')
def tearDown(self): def tearDown(self):
BaseTestCase.tearDown(self) BaseTestCase.tearDown(self)
...@@ -137,9 +134,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase): ...@@ -137,9 +134,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase):
def test_execute_with_no_issue_number_aborts(self): def test_execute_with_no_issue_number_aborts(self):
# If the user hasn't uploaded a CL, an error message is printed. # If the user hasn't uploaded a CL, an error message is printed.
git_cl = GitCL(self.tool) self.command.git_cl = MockGitCL(self.tool, issue_number='None')
git_cl.get_issue_number = lambda: 'None'
self.command.git_cl = lambda: git_cl
exit_code = self.command.execute(self.command_options(), [], self.tool) exit_code = self.command.execute(self.command_options(), [], self.tool)
self.assertEqual(exit_code, 1) self.assertEqual(exit_code, 1)
self.assertLog(['ERROR: No issue number for current branch.\n']) self.assertLog(['ERROR: No issue number for current branch.\n'])
...@@ -160,10 +155,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase): ...@@ -160,10 +155,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase):
def test_execute_no_try_jobs_started_triggers_jobs(self): def test_execute_no_try_jobs_started_triggers_jobs(self):
# If there are no try jobs started yet, by default the tool will # If there are no try jobs started yet, by default the tool will
# trigger new try jobs. # trigger new try jobs.
git_cl = GitCL(self.tool) self.command.git_cl = MockGitCL(self.tool, {})
git_cl.get_issue_number = lambda: '11112222'
git_cl.latest_try_jobs = lambda _: {}
self.command.git_cl = lambda: git_cl
exit_code = self.command.execute(self.command_options(), [], self.tool) exit_code = self.command.execute(self.command_options(), [], self.tool)
self.assertEqual(exit_code, 1) self.assertEqual(exit_code, 1)
self.assertLog([ self.assertLog([
...@@ -179,10 +171,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase): ...@@ -179,10 +171,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase):
def test_execute_no_try_jobs_started_and_no_trigger_jobs(self): def test_execute_no_try_jobs_started_and_no_trigger_jobs(self):
# If there are no try jobs started yet and --no-trigger-jobs is passed, # If there are no try jobs started yet and --no-trigger-jobs is passed,
# then we just abort immediately. # then we just abort immediately.
git_cl = GitCL(self.tool) self.command.git_cl = MockGitCL(self.tool, {})
git_cl.get_issue_number = lambda: '11112222'
git_cl.latest_try_jobs = lambda _: {}
self.command.git_cl = lambda: git_cl
exit_code = self.command.execute( exit_code = self.command.execute(
self.command_options(trigger_jobs=False), [], self.tool) self.command_options(trigger_jobs=False), [], self.tool)
self.assertEqual(exit_code, 1) self.assertEqual(exit_code, 1)
...@@ -196,10 +185,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase): ...@@ -196,10 +185,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase):
Build('MOCK Try Win', 5000): TryJobStatus('COMPLETED', 'FAILURE'), Build('MOCK Try Win', 5000): TryJobStatus('COMPLETED', 'FAILURE'),
Build('MOCK Try Mac', 4000): TryJobStatus('COMPLETED', 'FAILURE'), Build('MOCK Try Mac', 4000): TryJobStatus('COMPLETED', 'FAILURE'),
} }
git_cl = GitCL(self.tool) self.command.git_cl = MockGitCL(self.tool, builds)
git_cl.get_issue_number = lambda: '11112222'
git_cl.latest_try_jobs = lambda _: builds
self.command.git_cl = lambda: git_cl
exit_code = self.command.execute(self.command_options(), [], self.tool) exit_code = self.command.execute(self.command_options(), [], self.tool)
self.assertEqual(exit_code, 1) self.assertEqual(exit_code, 1)
self.assertLog([ self.assertLog([
...@@ -218,10 +204,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase): ...@@ -218,10 +204,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase):
Build('MOCK Try Mac', 4000): TryJobStatus('STARTED'), Build('MOCK Try Mac', 4000): TryJobStatus('STARTED'),
Build('MOCK Try Linux', 6000): TryJobStatus('SCHEDULED'), Build('MOCK Try Linux', 6000): TryJobStatus('SCHEDULED'),
} }
git_cl = GitCL(self.tool) self.command.git_cl = MockGitCL(self.tool, builds)
git_cl.get_issue_number = lambda: '11112222'
git_cl.latest_try_jobs = lambda _: builds
self.command.git_cl = lambda: git_cl
exit_code = self.command.execute(self.command_options(), [], self.tool) exit_code = self.command.execute(self.command_options(), [], self.tool)
self.assertEqual(exit_code, 1) self.assertEqual(exit_code, 1)
self.assertLog([ self.assertLog([
...@@ -246,10 +229,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase): ...@@ -246,10 +229,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase):
Build('MOCK Try Mac', 4000): TryJobStatus('COMPLETED', 'FAILURE'), Build('MOCK Try Mac', 4000): TryJobStatus('COMPLETED', 'FAILURE'),
Build('MOCK Try Linux', 6000): TryJobStatus('COMPLETED', 'CANCELED'), Build('MOCK Try Linux', 6000): TryJobStatus('COMPLETED', 'CANCELED'),
} }
git_cl = GitCL(self.tool) self.command.git_cl = MockGitCL(self.tool, builds)
git_cl.get_issue_number = lambda: '11112222'
git_cl.latest_try_jobs = lambda _: builds
self.command.git_cl = lambda: git_cl
exit_code = self.command.execute(self.command_options(), [], self.tool) exit_code = self.command.execute(self.command_options(), [], self.tool)
self.assertEqual(exit_code, 1) self.assertEqual(exit_code, 1)
self.assertLog([ self.assertLog([
...@@ -269,10 +249,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase): ...@@ -269,10 +249,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase):
Build('MOCK Try Mac', 4000): TryJobStatus('COMPLETED', 'SUCCESS'), Build('MOCK Try Mac', 4000): TryJobStatus('COMPLETED', 'SUCCESS'),
Build('MOCK Try Linux', 6000): TryJobStatus('COMPLETED', 'SUCCESS'), Build('MOCK Try Linux', 6000): TryJobStatus('COMPLETED', 'SUCCESS'),
} }
git_cl = GitCL(self.tool) self.command.git_cl = MockGitCL(self.tool, builds)
git_cl.get_issue_number = lambda: '11112222'
git_cl.latest_try_jobs = lambda _: builds
self.command.git_cl = lambda: git_cl
exit_code = self.command.execute(self.command_options(), [], self.tool) exit_code = self.command.execute(self.command_options(), [], self.tool)
self.assertEqual(exit_code, 0) self.assertEqual(exit_code, 0)
self.assertLog([ self.assertLog([
...@@ -289,10 +266,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase): ...@@ -289,10 +266,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase):
Build('MOCK Try Win', 5000): TryJobStatus('COMPLETED', 'FAILURE'), Build('MOCK Try Win', 5000): TryJobStatus('COMPLETED', 'FAILURE'),
Build('MOCK Try Mac', 4000): TryJobStatus('COMPLETED', 'FAILURE'), Build('MOCK Try Mac', 4000): TryJobStatus('COMPLETED', 'FAILURE'),
} }
git_cl = GitCL(self.tool) self.command.git_cl = MockGitCL(self.tool, builds)
git_cl.get_issue_number = lambda: '11112222'
git_cl.latest_try_jobs = lambda _: builds
self.command.git_cl = lambda: git_cl
exit_code = self.command.execute( exit_code = self.command.execute(
self.command_options(trigger_jobs=False), [], self.tool) self.command_options(trigger_jobs=False), [], self.tool)
self.assertEqual(exit_code, 1) self.assertEqual(exit_code, 1)
...@@ -399,7 +373,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase): ...@@ -399,7 +373,7 @@ class RebaselineCLTest(BaseTestCase, LoggingTestCase):
# the given builders. # the given builders.
self.command.trigger_try_jobs(['MOCK Try Linux', 'MOCK Try Win']) self.command.trigger_try_jobs(['MOCK Try Linux', 'MOCK Try Win'])
self.assertEqual( self.assertEqual(
self.tool.executive.calls, self.command.git_cl.calls,
[['git', 'cl', 'try', '-m', 'tryserver.blink', [['git', 'cl', 'try', '-m', 'tryserver.blink',
'-b', 'MOCK Try Linux', '-b', 'MOCK Try Win']]) '-b', 'MOCK Try Linux', '-b', 'MOCK Try Win']])
self.assertLog([ self.assertLog([
......
...@@ -29,6 +29,7 @@ class WPTExpectationsUpdater(object): ...@@ -29,6 +29,7 @@ class WPTExpectationsUpdater(object):
def __init__(self, host): def __init__(self, host):
self.host = host self.host = host
self.port = self.host.port_factory.get() self.port = self.host.port_factory.get()
self.git_cl = GitCL(host)
self.finder = PathFinder(self.host.filesystem) self.finder = PathFinder(self.host.filesystem)
self.ports_with_no_results = set() self.ports_with_no_results = set()
self.ports_with_all_pass = set() self.ports_with_all_pass = set()
...@@ -78,11 +79,11 @@ class WPTExpectationsUpdater(object): ...@@ -78,11 +79,11 @@ class WPTExpectationsUpdater(object):
def get_issue_number(self): def get_issue_number(self):
"""Returns current CL number. Can be replaced in unit tests.""" """Returns current CL number. Can be replaced in unit tests."""
return GitCL(self.host).get_issue_number() return self.git_cl.get_issue_number()
def get_latest_try_jobs(self): def get_latest_try_jobs(self):
"""Returns the latest finished try jobs as Build objects.""" """Returns the latest finished try jobs as Build objects."""
return GitCL(self.host).latest_try_jobs(self._get_try_bots()) return self.git_cl.latest_try_jobs(self._get_try_bots())
def get_failing_results_dict(self, build): def get_failing_results_dict(self, build):
"""Returns a nested dict of failing test results. """Returns a nested dict of failing test results.
......
...@@ -9,6 +9,7 @@ from webkitpy.common.host_mock import MockHost ...@@ -9,6 +9,7 @@ from webkitpy.common.host_mock import MockHost
from webkitpy.common.net.buildbot import Build from webkitpy.common.net.buildbot import Build
from webkitpy.common.net.buildbot_mock import MockBuildBot from webkitpy.common.net.buildbot_mock import MockBuildBot
from webkitpy.common.net.git_cl import TryJobStatus from webkitpy.common.net.git_cl import TryJobStatus
from webkitpy.common.net.git_cl_mock import MockGitCL
from webkitpy.common.net.layout_test_results import LayoutTestResult, LayoutTestResults from webkitpy.common.net.layout_test_results import LayoutTestResult, LayoutTestResults
from webkitpy.common.system.log_testing import LoggingTestCase from webkitpy.common.system.log_testing import LoggingTestCase
from webkitpy.layout_tests.builder_list import BuilderList from webkitpy.layout_tests.builder_list import BuilderList
...@@ -89,14 +90,14 @@ class WPTExpectationsUpdaterTest(LoggingTestCase): ...@@ -89,14 +90,14 @@ class WPTExpectationsUpdaterTest(LoggingTestCase):
# Set up fake try job results. # Set up fake try job results.
updater = WPTExpectationsUpdater(host) updater = WPTExpectationsUpdater(host)
updater.get_latest_try_jobs = lambda: { updater.git_cl = MockGitCL(updater.host, {
Build('MOCK Try Mac10.10', 333): TryJobStatus('COMPLETED', 'FAILURE'), Build('MOCK Try Mac10.10', 333): TryJobStatus('COMPLETED', 'FAILURE'),
Build('MOCK Try Mac10.11', 111): TryJobStatus('COMPLETED', 'SUCCESS'), Build('MOCK Try Mac10.11', 111): TryJobStatus('COMPLETED', 'SUCCESS'),
Build('MOCK Try Trusty', 222): TryJobStatus('COMPLETED', 'SUCCESS'), Build('MOCK Try Trusty', 222): TryJobStatus('COMPLETED', 'SUCCESS'),
Build('MOCK Try Precise', 333): TryJobStatus('COMPLETED', 'SUCCESS'), Build('MOCK Try Precise', 333): TryJobStatus('COMPLETED', 'SUCCESS'),
Build('MOCK Try Win10', 444): TryJobStatus('COMPLETED', 'SUCCESS'), Build('MOCK Try Win10', 444): TryJobStatus('COMPLETED', 'SUCCESS'),
Build('MOCK Try Win7', 555): TryJobStatus('COMPLETED', 'SUCCESS'), Build('MOCK Try Win7', 555): TryJobStatus('COMPLETED', 'SUCCESS'),
} })
# Set up failing results for one try bot. It shouldn't matter what # Set up failing results for one try bot. It shouldn't matter what
# results are for the other builders since we shouldn't need to even # results are for the other builders since we shouldn't need to even
...@@ -567,16 +568,14 @@ class WPTExpectationsUpdaterTest(LoggingTestCase): ...@@ -567,16 +568,14 @@ class WPTExpectationsUpdaterTest(LoggingTestCase):
self.assertEqual(results, results_copy) self.assertEqual(results, results_copy)
def test_run_no_issue_number(self): def test_run_no_issue_number(self):
# TODO(qyearsley): For testing: Consider making a MockGitCL class
# and use that class to set fake return values when using git cl.
updater = WPTExpectationsUpdater(self.mock_host()) updater = WPTExpectationsUpdater(self.mock_host())
updater.get_issue_number = lambda: 'None' updater.git_cl = MockGitCL(updater.host, issue_number='None')
self.assertEqual(1, updater.run(args=[])) self.assertEqual(1, updater.run(args=[]))
self.assertLog(['ERROR: No issue on current branch.\n']) self.assertLog(['ERROR: No issue on current branch.\n'])
def test_run_no_try_results(self): def test_run_no_try_results(self):
updater = WPTExpectationsUpdater(self.mock_host()) updater = WPTExpectationsUpdater(self.mock_host())
updater.get_latest_try_jobs = lambda: [] updater.git_cl = MockGitCL(updater.host, {})
self.assertEqual(1, updater.run(args=[])) self.assertEqual(1, updater.run(args=[]))
self.assertLog(['ERROR: No try job information was collected.\n']) self.assertLog(['ERROR: No try job information was collected.\n'])
......
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