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 from webkitpy.common.host_mock import MockHost | 6 from webkitpy.common.host_mock import MockHost |
7 from webkitpy.common.system.executive_mock import MockExecutive2 | 7 from webkitpy.common.system.executive_mock import MockExecutive2 |
8 from webkitpy.w3c.chromium_commit import ChromiumCommit | 8 from webkitpy.w3c.chromium_commit import ChromiumCommit, WPT_DIR |
9 | 9 |
10 | 10 |
11 class ChromiumCommitTest(unittest.TestCase): | 11 class ChromiumCommitTest(unittest.TestCase): |
12 | 12 |
13 def test_accepts_sha(self): | 13 def test_accepts_sha(self): |
14 chromium_commit = ChromiumCommit(MockHost(), sha='deadbeefcafe') | 14 chromium_commit = ChromiumCommit(MockHost(), sha='deadbeefcafe') |
15 | 15 |
16 self.assertEqual(chromium_commit.sha, 'deadbeefcafe') | 16 self.assertEqual(chromium_commit.sha, 'deadbeefcafe') |
17 self.assertIsNone(chromium_commit.position) | 17 self.assertIsNone(chromium_commit.position) |
18 | 18 |
19 def test_derives_sha_from_position(self): | 19 def test_derives_sha_from_position(self): |
20 host = MockHost() | 20 host = MockHost() |
21 host.executive = MockExecutive2(output='deadbeefcafe') | 21 host.executive = MockExecutive2(output='deadbeefcafe') |
22 pos = 'Cr-Commit-Position: refs/heads/master@{#789}' | 22 pos = 'Cr-Commit-Position: refs/heads/master@{#789}' |
23 chromium_commit = ChromiumCommit(host, position=pos) | 23 chromium_commit = ChromiumCommit(host, position=pos) |
24 | 24 |
25 self.assertEqual(chromium_commit.position, 'refs/heads/master@{#789}') | 25 self.assertEqual(chromium_commit.position, 'refs/heads/master@{#789}') |
26 self.assertEqual(chromium_commit.sha, 'deadbeefcafe') | 26 self.assertEqual(chromium_commit.sha, 'deadbeefcafe') |
| 27 |
| 28 def test_filtered_changed_files_blacklist(self): |
| 29 host = MockHost() |
| 30 |
| 31 fake_files = ['file1', 'MANIFEST.json', 'file3'] |
| 32 qualified_fake_files = [WPT_DIR + f for f in fake_files] |
| 33 |
| 34 stub_commands = { |
| 35 'diff-tree': '\n'.join(qualified_fake_files), |
| 36 'crrev-parse': 'fake rev', |
| 37 } |
| 38 |
| 39 def mock_command(args): |
| 40 if args[1] in stub_commands: |
| 41 return stub_commands[args[1]] |
| 42 else: |
| 43 raise Exception('Unexpected command called: %s' % args) |
| 44 |
| 45 host.executive = MockExecutive2(run_command_fn=mock_command) |
| 46 pos = 'Cr-Commit-Position: refs/heads/master@{#789}' |
| 47 chromium_commit = ChromiumCommit(host, position=pos) |
| 48 |
| 49 files = chromium_commit.filtered_changed_files() |
| 50 |
| 51 expected_files = ['file1', 'file3'] |
| 52 qualified_expected_files = [WPT_DIR + f for f in expected_files] |
| 53 |
| 54 self.assertEqual(files, qualified_expected_files) |
OLD | NEW |