| OLD | NEW |
| 1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # found in the LICENSE file. |
| 4 # modification, are permitted provided that the following conditions | |
| 5 # are met: | |
| 6 # | |
| 7 # 1. Redistributions of source code must retain the above | |
| 8 # copyright notice, this list of conditions and the following | |
| 9 # disclaimer. | |
| 10 # 2. Redistributions in binary form must reproduce the above | |
| 11 # copyright notice, this list of conditions and the following | |
| 12 # disclaimer in the documentation and/or other materials | |
| 13 # provided with the distribution. | |
| 14 # | |
| 15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY | |
| 16 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE | |
| 19 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | |
| 20 # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 22 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
| 24 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF | |
| 25 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
| 26 # SUCH DAMAGE. | |
| 27 | 4 |
| 28 import unittest | 5 import unittest |
| 29 | 6 |
| 30 from webkitpy.common.host_mock import MockHost | 7 from webkitpy.common.host_mock import MockHost |
| 31 from webkitpy.common.system.executive_mock import MockExecutive, ScriptError | 8 from webkitpy.common.system.executive_mock import MockExecutive |
| 32 from webkitpy.common.system.filesystem_mock import MockFileSystem | |
| 33 from webkitpy.w3c.test_importer import TestImporter | 9 from webkitpy.w3c.test_importer import TestImporter |
| 34 | 10 |
| 35 | 11 |
| 36 FAKE_SOURCE_REPO_DIR = '/blink' | |
| 37 | |
| 38 FAKE_FILES = { | |
| 39 '/mock-checkout/third_party/Webkit/LayoutTests/external/OWNERS': '', | |
| 40 '/blink/w3c/dir/has_shebang.txt': '#!', | |
| 41 '/blink/w3c/dir/README.txt': '', | |
| 42 '/blink/w3c/dir/OWNERS': '', | |
| 43 '/blink/w3c/dir/reftest.list': '', | |
| 44 '/blink/w3c/dir1/OWNERS': '', | |
| 45 '/blink/w3c/dir1/reftest.list': '', | |
| 46 '/mock-checkout/third_party/WebKit/LayoutTests/external/README.txt': '', | |
| 47 '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations': '', | |
| 48 } | |
| 49 | |
| 50 | |
| 51 class TestImporterTest(unittest.TestCase): | 12 class TestImporterTest(unittest.TestCase): |
| 52 | 13 |
| 53 def test_import_dir_with_no_tests(self): | 14 def test_generate_email_list(self): |
| 15 importer = TestImporter(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 importer.generate_email_list(changed_files, directory_to_owner), |
| 29 ['someone@gmail.com']) |
| 30 |
| 31 def test_parse_directory_owners(self): |
| 32 importer = TestImporter(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 importer.parse_directory_owners(data_file), |
| 40 {'foo/bar': 'charizard@gmail.com', 'foo/baz': 'blastoise@gmail.com'}
) |
| 41 |
| 42 def test_update_test_expectations(self): |
| 54 host = MockHost() | 43 host = MockHost() |
| 55 host.executive = MockExecutive(exception=ScriptError('error')) | 44 host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTests/Tes
tExpectations'] = ( |
| 56 host.filesystem = MockFileSystem(files=FAKE_FILES) | 45 'Bug(test) some/test/a.html [ Failure ]\n' |
| 57 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, 'destination') | 46 'Bug(test) some/test/b.html [ Failure ]\n' |
| 58 importer.do_import() # No exception raised. | 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 importer = TestImporter(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 importer.update_all_test_expectations_files(deleted_tests, renamed_test_
pairs) |
| 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')) |
| 59 | 62 |
| 60 def test_path_too_long_true(self): | 63 # Tests for protected methods - pylint: disable=protected-access |
| 64 |
| 65 def test_commit_changes(self): |
| 61 host = MockHost() | 66 host = MockHost() |
| 62 host.filesystem = MockFileSystem(files=FAKE_FILES) | 67 importer = TestImporter(host) |
| 63 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) | 68 importer._has_changes = lambda: True |
| 64 self.assertTrue(importer.path_too_long(FAKE_SOURCE_REPO_DIR + '/' + ('x'
* 150) + '.html')) | 69 importer._commit_changes('dummy message') |
| 70 self.assertEqual( |
| 71 host.executive.calls, |
| 72 [['git', 'commit', '--all', '-F', '-']]) |
| 65 | 73 |
| 66 def test_path_too_long_false(self): | 74 def test_commit_message(self): |
| 75 importer = TestImporter(MockHost()) |
| 76 self.assertEqual( |
| 77 importer._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): |
| 67 host = MockHost() | 83 host = MockHost() |
| 68 host.filesystem = MockFileSystem(files=FAKE_FILES) | 84 host.executive = MockExecutive(output='Last commit message\n\n') |
| 69 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) | 85 importer = TestImporter(host) |
| 70 self.assertFalse(importer.path_too_long(FAKE_SOURCE_REPO_DIR + '/x.html'
)) | 86 description = importer._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']]) |
| 71 | 93 |
| 72 def test_does_not_import_owner_files(self): | 94 def test_cl_description_with_environ_variables(self): |
| 73 host = MockHost() | 95 host = MockHost() |
| 74 host.filesystem = MockFileSystem(files=FAKE_FILES) | 96 host.executive = MockExecutive(output='Last commit message\n') |
| 75 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) | 97 importer = TestImporter(host) |
| 76 importer.find_importable_tests() | 98 importer.host.environ['BUILDBOT_MASTERNAME'] = 'my.master' |
| 99 importer.host.environ['BUILDBOT_BUILDERNAME'] = 'b' |
| 100 importer.host.environ['BUILDBOT_BUILDNUMBER'] = '123' |
| 101 description = importer._cl_description() |
| 77 self.assertEqual( | 102 self.assertEqual( |
| 78 importer.import_list, | 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 importer = TestImporter(host) |
| 114 description = importer._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 importer = TestImporter(host) |
| 126 importer._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 TestImporter._generate_manifest would invoke the script. |
| 133 host = MockHost() |
| 134 importer = TestImporter(host) |
| 135 importer._generate_manifest( |
| 136 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt') |
| 137 self.assertEqual( |
| 138 host.executive.calls, |
| 79 [ | 139 [ |
| 80 { | 140 [ |
| 81 'copy_list': [ | 141 '/mock-checkout/third_party/WebKit/Tools/Scripts/webkitpy/th
irdparty/wpt/wpt/manifest', |
| 82 {'dest': 'has_shebang.txt', 'src': '/blink/w3c/dir/has_s
hebang.txt'}, | 142 '--work', |
| 83 {'dest': 'README.txt', 'src': '/blink/w3c/dir/README.txt
'} | 143 '--tests-root', |
| 84 ], | 144 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt' |
| 85 'dirname': '/blink/w3c/dir', | 145 ], |
| 86 'jstests': 0, | 146 [ |
| 87 'reftests': 0, | 147 'git', |
| 88 'total_tests': 0, | 148 'add', |
| 89 } | 149 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt/
MANIFEST.json' |
| 150 ] |
| 90 ]) | 151 ]) |
| 91 | |
| 92 def test_does_not_import_reftestlist_file(self): | |
| 93 host = MockHost() | |
| 94 host.filesystem = MockFileSystem(files=FAKE_FILES) | |
| 95 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) | |
| 96 importer.find_importable_tests() | |
| 97 self.assertEqual( | |
| 98 importer.import_list, | |
| 99 [ | |
| 100 { | |
| 101 'copy_list': [ | |
| 102 {'dest': 'has_shebang.txt', 'src': '/blink/w3c/dir/has_s
hebang.txt'}, | |
| 103 {'dest': 'README.txt', 'src': '/blink/w3c/dir/README.txt
'} | |
| 104 ], | |
| 105 'dirname': '/blink/w3c/dir', | |
| 106 'jstests': 0, | |
| 107 'reftests': 0, | |
| 108 'total_tests': 0, | |
| 109 } | |
| 110 ]) | |
| 111 | |
| 112 def test_files_with_shebang_are_made_executable(self): | |
| 113 host = MockHost() | |
| 114 host.filesystem = MockFileSystem(files=FAKE_FILES) | |
| 115 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) | |
| 116 importer.do_import() | |
| 117 self.assertEqual( | |
| 118 host.filesystem.executable_files, | |
| 119 set(['/mock-checkout/third_party/WebKit/LayoutTests/external/blink/w
3c/dir/has_shebang.txt'])) | |
| 120 | |
| 121 def test_ref_test_with_ref_is_copied(self): | |
| 122 host = MockHost() | |
| 123 host.filesystem = MockFileSystem(files={ | |
| 124 '/blink/w3c/dir1/my-ref-test.html': '<html><head><link rel="match" h
ref="ref-file.html" />test</head></html>', | |
| 125 '/blink/w3c/dir1/ref-file.html': '<html><head>test</head></html>', | |
| 126 '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations
': '', | |
| 127 '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in'
: '', | |
| 128 }) | |
| 129 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) | |
| 130 importer.find_importable_tests() | |
| 131 self.assertEqual( | |
| 132 importer.import_list, | |
| 133 [ | |
| 134 { | |
| 135 'copy_list': [ | |
| 136 {'src': '/blink/w3c/dir1/ref-file.html', 'dest': 'ref-fi
le.html'}, | |
| 137 {'src': '/blink/w3c/dir1/ref-file.html', 'dest': 'my-ref
-test-expected.html', 'reference_support_info': {}}, | |
| 138 {'src': '/blink/w3c/dir1/my-ref-test.html', 'dest': 'my-
ref-test.html'} | |
| 139 ], | |
| 140 'dirname': '/blink/w3c/dir1', | |
| 141 'jstests': 0, | |
| 142 'reftests': 1, | |
| 143 'total_tests': 1 | |
| 144 } | |
| 145 ]) | |
| 146 | |
| 147 def test_ref_test_without_ref_is_skipped(self): | |
| 148 host = MockHost() | |
| 149 host.filesystem = MockFileSystem(files={ | |
| 150 '/blink/w3c/dir1/my-ref-test.html': '<html><head><link rel="match" h
ref="not-here.html" /></head></html>', | |
| 151 '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations
': '', | |
| 152 '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in'
: '', | |
| 153 }) | |
| 154 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) | |
| 155 importer.find_importable_tests() | |
| 156 self.assertEqual(importer.import_list, []) | |
| 157 | |
| 158 def test_should_try_to_convert_positive_cases(self): | |
| 159 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.css', 'Layou
tTests/external/csswg-test/x')) | |
| 160 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.htm', 'Layou
tTests/external/csswg-test/x')) | |
| 161 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.html', 'Layo
utTests/external/csswg-test/x')) | |
| 162 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.xht', 'Layou
tTests/external/csswg-test/x')) | |
| 163 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.xhtml', 'Lay
outTests/external/csswg-test/x')) | |
| 164 | |
| 165 def test_should_not_try_to_convert_js_test(self): | |
| 166 self.assertFalse(TestImporter.should_try_to_convert({'is_jstest': True},
'foo.html', 'LayoutTests/external/csswg-test/x')) | |
| 167 | |
| 168 def test_should_not_try_to_convert_test_in_wpt(self): | |
| 169 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.html', 'Lay
outTests/external/wpt/foo')) | |
| 170 | |
| 171 def test_should_not_try_to_convert_other_file_types(self): | |
| 172 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.bar', 'Layo
utTests/external/csswg-test/x')) | |
| 173 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.js', 'Layou
tTests/external/csswg-test/x')) | |
| 174 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.md', 'Layou
tTests/external/csswg-test/x')) | |
| 175 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.png', 'Layo
utTests/external/csswg-test/x')) | |
| 176 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.svg', 'Layo
utTests/external/csswg-test/x')) | |
| 177 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.svgz', 'Lay
outTests/external/csswg-test/x')) | |
| OLD | NEW |