Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_importer_unittest.py

Issue 2633933002: Directly use TestImporter in DepsUpdater instead of invoking script. (Closed)
Patch Set: Rebased Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions 4 # modification, are permitted provided that the following conditions
5 # are met: 5 # are met:
6 # 6 #
7 # 1. Redistributions of source code must retain the above 7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following 8 # copyright notice, this list of conditions and the following
9 # disclaimer. 9 # disclaimer.
10 # 2. Redistributions in binary form must reproduce the above 10 # 2. Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following 11 # copyright notice, this list of conditions and the following
12 # disclaimer in the documentation and/or other materials 12 # disclaimer in the documentation and/or other materials
13 # provided with the distribution. 13 # provided with the distribution.
14 # 14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY 15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
16 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE 18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
19 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 19 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
20 # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
24 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 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 25 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 # SUCH DAMAGE. 26 # SUCH DAMAGE.
27 27
28 import optparse
29 import unittest 28 import unittest
30 29
31 from webkitpy.common.host_mock import MockHost 30 from webkitpy.common.host_mock import MockHost
32 from webkitpy.common.system.executive_mock import MockExecutive, ScriptError 31 from webkitpy.common.system.executive_mock import MockExecutive, ScriptError
33 from webkitpy.common.system.filesystem_mock import MockFileSystem 32 from webkitpy.common.system.filesystem_mock import MockFileSystem
34 from webkitpy.w3c.test_importer import TestImporter 33 from webkitpy.w3c.test_importer import TestImporter
35 34
36 35
37 FAKE_SOURCE_REPO_DIR = '/blink' 36 FAKE_SOURCE_REPO_DIR = '/blink'
38 37
39 FAKE_FILES = { 38 FAKE_FILES = {
40 '/mock-checkout/third_party/Webkit/LayoutTests/w3c/OWNERS': '', 39 '/mock-checkout/third_party/Webkit/LayoutTests/imported/OWNERS': '',
41 '/blink/w3c/dir/has_shebang.txt': '#!', 40 '/blink/w3c/dir/has_shebang.txt': '#!',
42 '/blink/w3c/dir/README.txt': '', 41 '/blink/w3c/dir/README.txt': '',
43 '/blink/w3c/dir/OWNERS': '', 42 '/blink/w3c/dir/OWNERS': '',
44 '/blink/w3c/dir/reftest.list': '', 43 '/blink/w3c/dir/reftest.list': '',
45 '/blink/w3c/dir1/OWNERS': '', 44 '/blink/w3c/dir1/OWNERS': '',
46 '/blink/w3c/dir1/reftest.list': '', 45 '/blink/w3c/dir1/reftest.list': '',
47 '/mock-checkout/third_party/WebKit/LayoutTests/w3c/README.txt': '', 46 '/mock-checkout/third_party/WebKit/LayoutTests/imported/README.txt': '',
jeffcarp 2017/01/18 20:43:42 Should this be `external` now?
qyearsley 2017/01/18 23:10:58 Yep! Now changed.
48 '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations': '', 47 '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations': '',
49 } 48 }
50 49
51 50
52 class TestImporterTest(unittest.TestCase): 51 class TestImporterTest(unittest.TestCase):
53 52
54 @staticmethod
55 def options(**kwargs):
56 """Returns a set of option values for TestImporter."""
57 options = {
58 "overwrite": False,
59 "destination": "w3c",
60 "ignore_expectations": False,
61 "dry_run": False,
62 }
63 options.update(kwargs)
64 return optparse.Values(options)
65
66 def test_import_dir_with_no_tests(self): 53 def test_import_dir_with_no_tests(self):
67 host = MockHost() 54 host = MockHost()
68 host.executive = MockExecutive(exception=ScriptError( 55 host.executive = MockExecutive(exception=ScriptError(
69 "abort: no repository found in '/Volumes/Source/src/wk/Tools/Scripts /webkitpy/w3c'")) 56 "abort: no repository found in '/Volumes/Source/src/wk/Tools/Scripts /webkitpy/imported'"))
70 host.filesystem = MockFileSystem(files=FAKE_FILES) 57 host.filesystem = MockFileSystem(files=FAKE_FILES)
71 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) 58 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, 'destination')
72 importer.do_import() # No exception raised. 59 importer.do_import() # No exception raised.
73 60
74 def test_path_too_long_true(self): 61 def test_path_too_long_true(self):
75 importer = TestImporter(MockHost(), FAKE_SOURCE_REPO_DIR, self.options() ) 62 host = MockHost()
63 host.filesystem = MockFileSystem(files=FAKE_FILES)
64 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR)
76 self.assertTrue(importer.path_too_long(FAKE_SOURCE_REPO_DIR + '/' + ('x' * 150) + '.html')) 65 self.assertTrue(importer.path_too_long(FAKE_SOURCE_REPO_DIR + '/' + ('x' * 150) + '.html'))
77 66
78 def test_path_too_long_false(self): 67 def test_path_too_long_false(self):
79 importer = TestImporter(MockHost(), FAKE_SOURCE_REPO_DIR, self.options() ) 68 host = MockHost()
69 host.filesystem = MockFileSystem(files=FAKE_FILES)
70 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR)
80 self.assertFalse(importer.path_too_long(FAKE_SOURCE_REPO_DIR + '/x.html' )) 71 self.assertFalse(importer.path_too_long(FAKE_SOURCE_REPO_DIR + '/x.html' ))
81 72
82 def test_does_not_import_owner_files(self): 73 def test_does_not_import_owner_files(self):
83 host = MockHost() 74 host = MockHost()
84 host.filesystem = MockFileSystem(files=FAKE_FILES) 75 host.filesystem = MockFileSystem(files=FAKE_FILES)
85 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) 76 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR)
86 importer.find_importable_tests() 77 importer.find_importable_tests()
87 self.assertEqual( 78 self.assertEqual(
88 importer.import_list, 79 importer.import_list,
89 [ 80 [
90 { 81 {
91 'copy_list': [ 82 'copy_list': [
92 {'dest': 'has_shebang.txt', 'src': '/blink/w3c/dir/has_s hebang.txt'}, 83 {'dest': 'has_shebang.txt', 'src': '/blink/w3c/dir/has_s hebang.txt'},
93 {'dest': 'README.txt', 'src': '/blink/w3c/dir/README.txt '} 84 {'dest': 'README.txt', 'src': '/blink/w3c/dir/README.txt '}
94 ], 85 ],
95 'dirname': '/blink/w3c/dir', 86 'dirname': '/blink/w3c/dir',
96 'jstests': 0, 87 'jstests': 0,
97 'reftests': 0, 88 'reftests': 0,
98 'total_tests': 0, 89 'total_tests': 0,
99 } 90 }
100 ]) 91 ])
101 92
102 def test_does_not_import_reftestlist_file(self): 93 def test_does_not_import_reftestlist_file(self):
103 host = MockHost() 94 host = MockHost()
104 host.filesystem = MockFileSystem(files=FAKE_FILES) 95 host.filesystem = MockFileSystem(files=FAKE_FILES)
105 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) 96 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR)
106 importer.find_importable_tests() 97 importer.find_importable_tests()
107 self.assertEqual( 98 self.assertEqual(
108 importer.import_list, 99 importer.import_list,
109 [ 100 [
110 { 101 {
111 'copy_list': [ 102 'copy_list': [
112 {'dest': 'has_shebang.txt', 'src': '/blink/w3c/dir/has_s hebang.txt'}, 103 {'dest': 'has_shebang.txt', 'src': '/blink/w3c/dir/has_s hebang.txt'},
113 {'dest': 'README.txt', 'src': '/blink/w3c/dir/README.txt '} 104 {'dest': 'README.txt', 'src': '/blink/w3c/dir/README.txt '}
114 ], 105 ],
115 'dirname': '/blink/w3c/dir', 106 'dirname': '/blink/w3c/dir',
116 'jstests': 0, 107 'jstests': 0,
117 'reftests': 0, 108 'reftests': 0,
118 'total_tests': 0, 109 'total_tests': 0,
119 } 110 }
120 ]) 111 ])
121 112
122 def test_files_with_shebang_are_made_executable(self): 113 def test_files_with_shebang_are_made_executable(self):
123 host = MockHost() 114 host = MockHost()
124 host.filesystem = MockFileSystem(files=FAKE_FILES) 115 host.filesystem = MockFileSystem(files=FAKE_FILES)
125 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) 116 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR)
126 importer.do_import() 117 importer.do_import()
127 self.assertEqual( 118 self.assertEqual(
128 host.filesystem.executable_files, 119 host.filesystem.executable_files,
129 set(['/mock-checkout/third_party/WebKit/LayoutTests/w3c/blink/w3c/di r/has_shebang.txt'])) 120 set(['/mock-checkout/third_party/WebKit/LayoutTests/imported/blink/w 3c/dir/has_shebang.txt']))
130 121
131 def test_ref_test_with_ref_is_copied(self): 122 def test_ref_test_with_ref_is_copied(self):
132 host = MockHost() 123 host = MockHost()
133 host.filesystem = MockFileSystem(files={ 124 host.filesystem = MockFileSystem(files={
134 '/blink/w3c/dir1/my-ref-test.html': '<html><head><link rel="match" h ref="ref-file.html" />test</head></html>', 125 '/blink/w3c/dir1/my-ref-test.html': '<html><head><link rel="match" h ref="ref-file.html" />test</head></html>',
135 '/blink/w3c/dir1/ref-file.html': '<html><head>test</head></html>', 126 '/blink/w3c/dir1/ref-file.html': '<html><head>test</head></html>',
136 '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations ': '', 127 '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations ': '',
137 '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in' : '', 128 '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in' : '',
138 }) 129 })
139 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) 130 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR)
140 importer.find_importable_tests() 131 importer.find_importable_tests()
141 self.assertEqual( 132 self.assertEqual(
142 importer.import_list, 133 importer.import_list,
143 [ 134 [
144 { 135 {
145 'copy_list': [ 136 'copy_list': [
146 {'src': '/blink/w3c/dir1/ref-file.html', 'dest': 'ref-fi le.html'}, 137 {'src': '/blink/w3c/dir1/ref-file.html', 'dest': 'ref-fi le.html'},
147 {'src': '/blink/w3c/dir1/ref-file.html', 'dest': 'my-ref -test-expected.html', 'reference_support_info': {}}, 138 {'src': '/blink/w3c/dir1/ref-file.html', 'dest': 'my-ref -test-expected.html', 'reference_support_info': {}},
148 {'src': '/blink/w3c/dir1/my-ref-test.html', 'dest': 'my- ref-test.html'} 139 {'src': '/blink/w3c/dir1/my-ref-test.html', 'dest': 'my- ref-test.html'}
149 ], 140 ],
150 'dirname': '/blink/w3c/dir1', 141 'dirname': '/blink/w3c/dir1',
151 'jstests': 0, 142 'jstests': 0,
152 'reftests': 1, 143 'reftests': 1,
153 'total_tests': 1 144 'total_tests': 1
154 } 145 }
155 ]) 146 ])
156 147
157 def test_ref_test_without_ref_is_skipped(self): 148 def test_ref_test_without_ref_is_skipped(self):
158 host = MockHost() 149 host = MockHost()
159 host.filesystem = MockFileSystem(files={ 150 host.filesystem = MockFileSystem(files={
160 '/blink/w3c/dir1/my-ref-test.html': '<html><head><link rel="match" h ref="not-here.html" /></head></html>', 151 '/blink/w3c/dir1/my-ref-test.html': '<html><head><link rel="match" h ref="not-here.html" /></head></html>',
161 '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations ': '', 152 '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations ': '',
162 '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in' : '', 153 '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in' : '',
163 }) 154 })
164 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) 155 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR)
165 importer.find_importable_tests() 156 importer.find_importable_tests()
166 self.assertEqual(importer.import_list, []) 157 self.assertEqual(importer.import_list, [])
167 158
168 def test_should_try_to_convert_positive_cases(self): 159 def test_should_try_to_convert_positive_cases(self):
169 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.css', 'Layou tTests/external/csswg-test/x')) 160 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.css', 'Layou tTests/external/csswg-test/x'))
170 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.htm', 'Layou tTests/external/csswg-test/x')) 161 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.htm', 'Layou tTests/external/csswg-test/x'))
171 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.html', 'Layo utTests/external/csswg-test/x')) 162 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.html', 'Layo utTests/external/csswg-test/x'))
172 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.xht', 'Layou tTests/external/csswg-test/x')) 163 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.xht', 'Layou tTests/external/csswg-test/x'))
173 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.xhtml', 'Lay outTests/external/csswg-test/x')) 164 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.xhtml', 'Lay outTests/external/csswg-test/x'))
174 165
175 def test_should_not_try_to_convert_js_test(self): 166 def test_should_not_try_to_convert_js_test(self):
176 self.assertFalse(TestImporter.should_try_to_convert({'is_jstest': True}, 'foo.html', 'LayoutTests/external/csswg-test/x')) 167 self.assertFalse(TestImporter.should_try_to_convert({'is_jstest': True}, 'foo.html', 'LayoutTests/external/csswg-test/x'))
177 168
178 def test_should_not_try_to_convert_test_in_wpt(self): 169 def test_should_not_try_to_convert_test_in_wpt(self):
179 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.html', 'Lay outTests/external/wpt/foo')) 170 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.html', 'Lay outTests/external/wpt/foo'))
180 171
181 def test_should_not_try_to_convert_other_file_types(self): 172 def test_should_not_try_to_convert_other_file_types(self):
182 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.bar', 'Layo utTests/external/csswg-test/x')) 173 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.bar', 'Layo utTests/external/csswg-test/x'))
183 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.js', 'Layou tTests/external/csswg-test/x')) 174 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.js', 'Layou tTests/external/csswg-test/x'))
184 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.md', 'Layou tTests/external/csswg-test/x')) 175 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.md', 'Layou tTests/external/csswg-test/x'))
185 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.png', 'Layo utTests/external/csswg-test/x')) 176 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.png', 'Layo utTests/external/csswg-test/x'))
186 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.svg', 'Layo utTests/external/csswg-test/x')) 177 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.svg', 'Layo utTests/external/csswg-test/x'))
187 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.svgz', 'Lay outTests/external/csswg-test/x')) 178 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.svgz', 'Lay outTests/external/csswg-test/x'))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698