Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import unittest | 5 import unittest |
| 6 | 6 |
| 7 from webkitpy.common.host_mock import MockHost | 7 from webkitpy.common.host_mock import MockHost |
| 8 from webkitpy.common.system.executive_mock import MockExecutive | 8 from webkitpy.common.system.executive_mock import MockExecutive |
| 9 from webkitpy.w3c.chromium_commit import ChromiumCommit | 9 from webkitpy.w3c.chromium_commit import ChromiumCommit |
| 10 from webkitpy.w3c.common import exportable_commits_since | 10 from webkitpy.w3c.common import exportable_commits_since |
| 11 | 11 |
| 12 | 12 |
| 13 # TODO(qyearsley): Move this to executive_mock. | 13 # TODO(qyearsley): Move this to executive_mock. |
| 14 def mock_command_exec(vals): | 14 def mock_command_exec(vals): |
| 15 def run_fn(args): | 15 def run_fn(args): |
| 16 sub_command = args[1] | 16 sub_command = args[1] |
| 17 return vals.get(sub_command, '') | 17 return vals.get(sub_command, '') |
| 18 return MockExecutive(run_command_fn=run_fn) | 18 return MockExecutive(run_command_fn=run_fn) |
| 19 | 19 |
| 20 | 20 |
| 21 def mock_command_exec_strict(vals): | |
| 22 def run_fn(args): | |
| 23 sub_command = args[1] | |
| 24 return vals[sub_command] | |
| 25 return MockExecutive(run_command_fn=run_fn) | |
| 26 | |
| 27 | |
|
jeffcarp
2017/02/14 02:20:48
The only changes in the tests are the 1. addition
qyearsley
2017/02/14 05:17:34
Optional possible change to this function; since y
| |
| 21 class MockLocalWPT(object): | 28 class MockLocalWPT(object): |
| 22 | 29 |
| 23 def test_patch(self, patch, chromium_commit): # pylint: disable=unused-argu ment | 30 def test_patch(self, patch, chromium_commit): # pylint: disable=unused-argu ment |
| 24 return 'patch' | 31 return 'patch' |
| 25 | 32 |
| 26 | 33 |
| 27 class CommonTest(unittest.TestCase): | 34 class CommonTest(unittest.TestCase): |
| 28 | 35 |
| 29 def test_exportable_commits_since(self): | 36 def test_exportable_commits_since(self): |
| 30 host = MockHost() | 37 host = MockHost() |
| 31 host.executive = mock_command_exec({ | 38 host.executive = mock_command_exec({ |
| 32 'show': 'fake message', | 39 'show': 'fake message', |
| 33 'rev-list': 'badbeef8', | 40 'rev-list': 'add087a97844f4b9e307d9a216940582d96db306', |
| 34 'rev-parse': 'badbeef8', | 41 'rev-parse': 'add087a97844f4b9e307d9a216940582d96db306', |
| 35 'crrev-parse': 'badbeef8', | 42 'crrev-parse': 'add087a97844f4b9e307d9a216940582d96db306', |
| 36 'diff': 'fake diff', | 43 'diff': 'fake diff', |
| 37 'diff-tree': 'some\nfiles', | 44 'diff-tree': 'some\nfiles', |
| 38 'format-patch': 'hey I\'m a patch', | 45 'format-patch': 'hey I\'m a patch', |
| 39 'footers': 'cr-rev-position', | 46 'footers': 'cr-rev-position', |
| 40 }) | 47 }) |
| 41 | 48 |
| 42 commits = exportable_commits_since('beefcafe', host, MockLocalWPT()) | 49 commits = exportable_commits_since('beefcafe', host, MockLocalWPT()) |
| 43 self.assertEqual(len(commits), 1) | 50 self.assertEqual(len(commits), 1) |
| 44 self.assertIsInstance(commits[0], ChromiumCommit) | 51 self.assertIsInstance(commits[0], ChromiumCommit) |
| 45 self.assertEqual(host.executive.calls, [ | 52 self.assertEqual(host.executive.calls, [ |
| 46 ['git', 'rev-parse', '--show-toplevel'], | 53 ['git', 'rev-parse', '--show-toplevel'], |
| 47 ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', 'badbeef8/t hird_party/WebKit/LayoutTests/external/wpt/'], | 54 ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', |
| 48 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'badbeef 8', '--', | 55 'add087a97844f4b9e307d9a216940582d96db306/third_party/WebKit/Layout Tests/external/wpt/'], |
| 56 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'add087a 97844f4b9e307d9a216940582d96db306', '--', | |
| 49 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'], | 57 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'], |
| 50 ['git', 'format-patch', '-1', '--stdout', 'badbeef8', '--', 'some', 'files'], | 58 ['git', 'format-patch', '-1', '--stdout', 'add087a97844f4b9e307d9a21 6940582d96db306', '--', 'some', 'files'], |
| 51 ['git', 'show', '--format=%B', '--no-patch', 'badbeef8'], | 59 ['git', 'show', '--format=%B', '--no-patch', 'add087a97844f4b9e307d9 a216940582d96db306'], |
| 52 ['git', 'show', '--format=%B', '--no-patch', 'badbeef8'] | 60 ['git', 'show', '--format=%B', '--no-patch', 'add087a97844f4b9e307d9 a216940582d96db306'] |
| 53 ]) | 61 ]) |
| 54 | 62 |
| 55 def test_ignores_commits_with_noexport_true(self): | 63 def test_ignores_commits_with_noexport_true(self): |
| 56 host = MockHost() | 64 host = MockHost() |
| 57 host.executive = mock_command_exec({ | 65 host.executive = mock_command_exec({ |
| 58 'show': 'Commit message\nNOEXPORT=true', | 66 'show': 'Commit message\nNOEXPORT=true', |
| 59 'rev-list': 'badbeef8', | 67 'rev-list': 'add087a97844f4b9e307d9a216940582d96db306', |
| 60 'rev-parse': 'badbeef8', | 68 'rev-parse': 'add087a97844f4b9e307d9a216940582d96db306', |
| 61 'footers': 'cr-rev-position', | 69 'footers': 'cr-rev-position', |
| 62 }) | 70 }) |
| 63 | 71 |
| 64 commits = exportable_commits_since('beefcafe', host, MockLocalWPT()) | 72 commits = exportable_commits_since('add087a97844f4b9e307d9a216940582d96d b306', host, MockLocalWPT()) |
| 65 self.assertEqual(commits, []) | 73 self.assertEqual(commits, []) |
| 66 self.assertEqual(host.executive.calls, [ | 74 self.assertEqual(host.executive.calls, [ |
| 67 ['git', 'rev-parse', '--show-toplevel'], | 75 ['git', 'rev-parse', '--show-toplevel'], |
| 68 ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', | 76 ['git', 'rev-list', 'add087a97844f4b9e307d9a216940582d96db306..HEAD' , '--reverse', '--', |
| 69 'badbeef8/third_party/WebKit/LayoutTests/external/wpt/'], | 77 'add087a97844f4b9e307d9a216940582d96db306/third_party/WebKit/Layout Tests/external/wpt/'], |
| 70 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'badbeef 8', '--', | 78 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'add087a 97844f4b9e307d9a216940582d96db306', '--', |
| 71 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'], | 79 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'], |
| 72 ['git', 'show', '--format=%B', '--no-patch', 'badbeef8'] | 80 ['git', 'show', '--format=%B', '--no-patch', 'add087a97844f4b9e307d9 a216940582d96db306'] |
| 73 ]) | 81 ]) |
| 74 | 82 |
| 75 def test_ignores_reverted_commits_with_noexport_true(self): | 83 def test_ignores_reverted_commits_with_noexport_true(self): |
| 76 host = MockHost() | 84 host = MockHost() |
| 77 host.executive = mock_command_exec({ | 85 host.executive = mock_command_exec_strict({ |
| 78 'show': 'Commit message\n> NOEXPORT=true', | 86 'show': 'Commit message\n> NOEXPORT=true', |
| 79 'rev-list': 'badbeef8', | 87 'rev-list': 'add087a97844f4b9e307d9a216940582d96db306', |
| 80 'rev-parse': 'badbeef8', | 88 'rev-parse': 'add087a97844f4b9e307d9a216940582d96db306', |
| 81 'footers': 'cr-rev-position', | 89 'footers': 'cr-rev-position', |
| 90 'diff-tree': '', | |
| 82 }) | 91 }) |
| 83 | 92 |
| 84 commits = exportable_commits_since('beefcafe', host, MockLocalWPT()) | 93 commits = exportable_commits_since('add087a97844f4b9e307d9a216940582d96d b306', host, MockLocalWPT()) |
| 85 self.assertEqual(len(commits), 0) | 94 self.assertEqual(len(commits), 0) |
| 86 self.assertEqual(host.executive.calls, [ | 95 self.assertEqual(host.executive.calls, [ |
| 87 ['git', 'rev-parse', '--show-toplevel'], | 96 ['git', 'rev-parse', '--show-toplevel'], |
| 88 ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', | 97 ['git', 'rev-list', 'add087a97844f4b9e307d9a216940582d96db306..HEAD' , '--reverse', '--', |
| 89 'badbeef8/third_party/WebKit/LayoutTests/external/wpt/'], | 98 'add087a97844f4b9e307d9a216940582d96db306/third_party/WebKit/Layout Tests/external/wpt/'], |
| 90 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'badbeef 8', '--', | 99 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'add087a 97844f4b9e307d9a216940582d96db306', '--', |
| 91 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'], | 100 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'], |
| 92 ['git', 'show', '--format=%B', '--no-patch', 'badbeef8'] | 101 ['git', 'show', '--format=%B', '--no-patch', 'add087a97844f4b9e307d9 a216940582d96db306'] |
| 93 ]) | 102 ]) |
| 94 | 103 |
| 95 def test_ignores_commits_that_start_with_import(self): | 104 def test_ignores_commits_that_start_with_import(self): |
| 96 host = MockHost() | 105 host = MockHost() |
| 97 host.executive = mock_command_exec({ | 106 host.executive = mock_command_exec({ |
| 98 'show': 'Import rutabaga@deadbeef', | 107 'show': 'Import rutabaga@deadbeef', |
| 99 'rev-list': 'badbeef8', | 108 'rev-list': 'add087a97844f4b9e307d9a216940582d96db306', |
| 100 'rev-parse': 'badbeef8', | 109 'rev-parse': 'add087a97844f4b9e307d9a216940582d96db306', |
| 101 'footers': 'cr-rev-position', | 110 'footers': 'cr-rev-position', |
| 102 }) | 111 }) |
| 103 | 112 |
| 104 commits = exportable_commits_since('beefcafe', host, MockLocalWPT()) | 113 commits = exportable_commits_since('beefcafe', host, MockLocalWPT()) |
| 105 self.assertEqual(commits, []) | 114 self.assertEqual(commits, []) |
| 106 self.assertEqual(host.executive.calls, [ | 115 self.assertEqual(host.executive.calls, [ |
| 107 ['git', 'rev-parse', '--show-toplevel'], | 116 ['git', 'rev-parse', '--show-toplevel'], |
| 108 ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', | 117 ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', |
| 109 'badbeef8/third_party/WebKit/LayoutTests/external/wpt/'], | 118 'add087a97844f4b9e307d9a216940582d96db306/third_party/WebKit/Layout Tests/external/wpt/'], |
| 110 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'badbeef 8', '--', | 119 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'add087a 97844f4b9e307d9a216940582d96db306', '--', |
| 111 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'], | 120 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'], |
| 112 ['git', 'show', '--format=%B', '--no-patch', 'badbeef8'], | 121 ['git', 'show', '--format=%B', '--no-patch', 'add087a97844f4b9e307d9 a216940582d96db306'], |
| 113 ['git', 'show', '--format=%B', '--no-patch', 'badbeef8'], | 122 ['git', 'show', '--format=%B', '--no-patch', 'add087a97844f4b9e307d9 a216940582d96db306'], |
| 114 ]) | 123 ]) |
| OLD | NEW |