| OLD | NEW |
| (Empty) |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import unittest | |
| 6 | |
| 7 from webkitpy.common.host_mock import MockHost | |
| 8 from webkitpy.common.system.executive_mock import MockExecutive | |
| 9 from webkitpy.w3c.deps_updater import DepsUpdater | |
| 10 | |
| 11 | |
| 12 class DepsUpdaterTest(unittest.TestCase): | |
| 13 | |
| 14 def test_generate_email_list(self): | |
| 15 updater = DepsUpdater(MockHost()) | |
| 16 changed_files = [ | |
| 17 'third_party/WebKit/LayoutTests/foo/bar/file.html', | |
| 18 'third_party/WebKit/LayoutTests/foo/bar/otherfile.html', | |
| 19 'third_party/WebKit/LayoutTests/foo/baz/files.html', | |
| 20 'some/non-test.file', | |
| 21 ] | |
| 22 directory_to_owner = { | |
| 23 'foo/bar': 'someone@gmail.com', | |
| 24 'foo/baz': 'not an email address', | |
| 25 'foo/bat': 'noone@gmail.com', | |
| 26 } | |
| 27 self.assertEqual( | |
| 28 updater.generate_email_list(changed_files, directory_to_owner), | |
| 29 ['someone@gmail.com']) | |
| 30 | |
| 31 def test_parse_directory_owners(self): | |
| 32 updater = DepsUpdater(MockHost()) | |
| 33 data_file = [ | |
| 34 {'notification-email': 'charizard@gmail.com', 'directory': 'foo/bar'
}, | |
| 35 {'notification-email': 'blastoise@gmail.com', 'directory': 'foo/baz'
}, | |
| 36 {'notification-email': '', 'directory': 'gol/bat'}, | |
| 37 ] | |
| 38 self.assertEqual( | |
| 39 updater.parse_directory_owners(data_file), | |
| 40 {'foo/bar': 'charizard@gmail.com', 'foo/baz': 'blastoise@gmail.com'}
) | |
| 41 | |
| 42 def test_update_test_expectations(self): | |
| 43 host = MockHost() | |
| 44 host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTests/Tes
tExpectations'] = ( | |
| 45 'Bug(test) some/test/a.html [ Failure ]\n' | |
| 46 'Bug(test) some/test/b.html [ Failure ]\n' | |
| 47 'Bug(test) some/test/c.html [ Failure ]\n') | |
| 48 host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTests/Vir
tualTestSuites'] = '[]' | |
| 49 host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTests/new
/a.html'] = '' | |
| 50 host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTests/new
/b.html'] = '' | |
| 51 updater = DepsUpdater(host) | |
| 52 deleted_tests = ['some/test/b.html'] | |
| 53 renamed_test_pairs = { | |
| 54 'some/test/a.html': 'new/a.html', | |
| 55 'some/test/c.html': 'new/c.html', | |
| 56 } | |
| 57 updater.update_all_test_expectations_files(deleted_tests, renamed_test_p
airs) | |
| 58 self.assertMultiLineEqual( | |
| 59 host.filesystem.read_text_file('/mock-checkout/third_party/WebKit/La
youtTests/TestExpectations'), | |
| 60 ('Bug(test) new/a.html [ Failure ]\n' | |
| 61 'Bug(test) new/c.html [ Failure ]\n')) | |
| 62 | |
| 63 # Tests for protected methods - pylint: disable=protected-access | |
| 64 | |
| 65 def test_commit_changes(self): | |
| 66 host = MockHost() | |
| 67 updater = DepsUpdater(host) | |
| 68 updater._has_changes = lambda: True | |
| 69 updater._commit_changes('dummy message') | |
| 70 self.assertEqual( | |
| 71 host.executive.calls, | |
| 72 [['git', 'commit', '--all', '-F', '-']]) | |
| 73 | |
| 74 def test_commit_message(self): | |
| 75 updater = DepsUpdater(MockHost()) | |
| 76 self.assertEqual( | |
| 77 updater._commit_message('aaaa', '1111'), | |
| 78 'Import 1111\n\n' | |
| 79 'Using wpt-import in Chromium aaaa.\n\n' | |
| 80 'NOEXPORT=true') | |
| 81 | |
| 82 def test_cl_description_with_empty_environ(self): | |
| 83 host = MockHost() | |
| 84 host.executive = MockExecutive(output='Last commit message\n\n') | |
| 85 updater = DepsUpdater(host) | |
| 86 description = updater._cl_description() | |
| 87 self.assertEqual( | |
| 88 description, | |
| 89 ('Last commit message\n\n' | |
| 90 'TBR=qyearsley@chromium.org\n' | |
| 91 'NOEXPORT=true')) | |
| 92 self.assertEqual(host.executive.calls, [['git', 'log', '-1', '--format=%
B']]) | |
| 93 | |
| 94 def test_cl_description_with_environ_variables(self): | |
| 95 host = MockHost() | |
| 96 host.executive = MockExecutive(output='Last commit message\n') | |
| 97 updater = DepsUpdater(host) | |
| 98 updater.host.environ['BUILDBOT_MASTERNAME'] = 'my.master' | |
| 99 updater.host.environ['BUILDBOT_BUILDERNAME'] = 'b' | |
| 100 updater.host.environ['BUILDBOT_BUILDNUMBER'] = '123' | |
| 101 description = updater._cl_description() | |
| 102 self.assertEqual( | |
| 103 description, | |
| 104 ('Last commit message\n' | |
| 105 'Build: https://build.chromium.org/p/my.master/builders/b/builds/12
3\n\n' | |
| 106 'TBR=qyearsley@chromium.org\n' | |
| 107 'NOEXPORT=true')) | |
| 108 self.assertEqual(host.executive.calls, [['git', 'log', '-1', '--format=%
B']]) | |
| 109 | |
| 110 def test_cl_description_moves_noexport_tag(self): | |
| 111 host = MockHost() | |
| 112 host.executive = MockExecutive(output='Summary\n\nNOEXPORT=true\n\n') | |
| 113 updater = DepsUpdater(host) | |
| 114 description = updater._cl_description() | |
| 115 self.assertEqual( | |
| 116 description, | |
| 117 ('Summary\n\n' | |
| 118 'TBR=qyearsley@chromium.org\n' | |
| 119 'NOEXPORT=true')) | |
| 120 | |
| 121 def test_generate_manifest_command_not_found(self): | |
| 122 # If we're updating csswg-test, then the manifest file won't be found. | |
| 123 host = MockHost() | |
| 124 host.filesystem.files = {} | |
| 125 updater = DepsUpdater(host) | |
| 126 updater._generate_manifest( | |
| 127 '/mock-checkout/third_party/WebKit/LayoutTests/external/csswg-test') | |
| 128 self.assertEqual(host.executive.calls, []) | |
| 129 | |
| 130 def test_generate_manifest_successful_run(self): | |
| 131 # This test doesn't test any aspect of the real manifest script, it just | |
| 132 # asserts that DepsUpdater._generate_manifest would invoke the script. | |
| 133 host = MockHost() | |
| 134 updater = DepsUpdater(host) | |
| 135 updater._generate_manifest( | |
| 136 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt') | |
| 137 self.assertEqual( | |
| 138 host.executive.calls, | |
| 139 [ | |
| 140 [ | |
| 141 '/mock-checkout/third_party/WebKit/Tools/Scripts/webkitpy/th
irdparty/wpt/wpt/manifest', | |
| 142 '--work', | |
| 143 '--tests-root', | |
| 144 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt' | |
| 145 ], | |
| 146 [ | |
| 147 'git', | |
| 148 'add', | |
| 149 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt/
MANIFEST.json' | |
| 150 ] | |
| 151 ]) | |
| OLD | NEW |