| OLD | NEW |
| 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/external/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/external/README.txt': '', |
| 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('error')) |
| 69 "abort: no repository found in '/Volumes/Source/src/wk/Tools/Scripts
/webkitpy/w3c'")) | |
| 70 host.filesystem = MockFileSystem(files=FAKE_FILES) | 56 host.filesystem = MockFileSystem(files=FAKE_FILES) |
| 71 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) | 57 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, 'destination') |
| 72 importer.do_import() # No exception raised. | 58 importer.do_import() # No exception raised. |
| 73 | 59 |
| 74 def test_path_too_long_true(self): | 60 def test_path_too_long_true(self): |
| 75 importer = TestImporter(MockHost(), FAKE_SOURCE_REPO_DIR, self.options()
) | 61 host = MockHost() |
| 62 host.filesystem = MockFileSystem(files=FAKE_FILES) |
| 63 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) |
| 76 self.assertTrue(importer.path_too_long(FAKE_SOURCE_REPO_DIR + '/' + ('x'
* 150) + '.html')) | 64 self.assertTrue(importer.path_too_long(FAKE_SOURCE_REPO_DIR + '/' + ('x'
* 150) + '.html')) |
| 77 | 65 |
| 78 def test_path_too_long_false(self): | 66 def test_path_too_long_false(self): |
| 79 importer = TestImporter(MockHost(), FAKE_SOURCE_REPO_DIR, self.options()
) | 67 host = MockHost() |
| 68 host.filesystem = MockFileSystem(files=FAKE_FILES) |
| 69 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) |
| 80 self.assertFalse(importer.path_too_long(FAKE_SOURCE_REPO_DIR + '/x.html'
)) | 70 self.assertFalse(importer.path_too_long(FAKE_SOURCE_REPO_DIR + '/x.html'
)) |
| 81 | 71 |
| 82 def test_does_not_import_owner_files(self): | 72 def test_does_not_import_owner_files(self): |
| 83 host = MockHost() | 73 host = MockHost() |
| 84 host.filesystem = MockFileSystem(files=FAKE_FILES) | 74 host.filesystem = MockFileSystem(files=FAKE_FILES) |
| 85 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) | 75 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) |
| 86 importer.find_importable_tests() | 76 importer.find_importable_tests() |
| 87 self.assertEqual( | 77 self.assertEqual( |
| 88 importer.import_list, | 78 importer.import_list, |
| 89 [ | 79 [ |
| 90 { | 80 { |
| 91 'copy_list': [ | 81 'copy_list': [ |
| 92 {'dest': 'has_shebang.txt', 'src': '/blink/w3c/dir/has_s
hebang.txt'}, | 82 {'dest': 'has_shebang.txt', 'src': '/blink/w3c/dir/has_s
hebang.txt'}, |
| 93 {'dest': 'README.txt', 'src': '/blink/w3c/dir/README.txt
'} | 83 {'dest': 'README.txt', 'src': '/blink/w3c/dir/README.txt
'} |
| 94 ], | 84 ], |
| 95 'dirname': '/blink/w3c/dir', | 85 'dirname': '/blink/w3c/dir', |
| 96 'jstests': 0, | 86 'jstests': 0, |
| 97 'reftests': 0, | 87 'reftests': 0, |
| 98 'total_tests': 0, | 88 'total_tests': 0, |
| 99 } | 89 } |
| 100 ]) | 90 ]) |
| 101 | 91 |
| 102 def test_does_not_import_reftestlist_file(self): | 92 def test_does_not_import_reftestlist_file(self): |
| 103 host = MockHost() | 93 host = MockHost() |
| 104 host.filesystem = MockFileSystem(files=FAKE_FILES) | 94 host.filesystem = MockFileSystem(files=FAKE_FILES) |
| 105 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) | 95 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) |
| 106 importer.find_importable_tests() | 96 importer.find_importable_tests() |
| 107 self.assertEqual( | 97 self.assertEqual( |
| 108 importer.import_list, | 98 importer.import_list, |
| 109 [ | 99 [ |
| 110 { | 100 { |
| 111 'copy_list': [ | 101 'copy_list': [ |
| 112 {'dest': 'has_shebang.txt', 'src': '/blink/w3c/dir/has_s
hebang.txt'}, | 102 {'dest': 'has_shebang.txt', 'src': '/blink/w3c/dir/has_s
hebang.txt'}, |
| 113 {'dest': 'README.txt', 'src': '/blink/w3c/dir/README.txt
'} | 103 {'dest': 'README.txt', 'src': '/blink/w3c/dir/README.txt
'} |
| 114 ], | 104 ], |
| 115 'dirname': '/blink/w3c/dir', | 105 'dirname': '/blink/w3c/dir', |
| 116 'jstests': 0, | 106 'jstests': 0, |
| 117 'reftests': 0, | 107 'reftests': 0, |
| 118 'total_tests': 0, | 108 'total_tests': 0, |
| 119 } | 109 } |
| 120 ]) | 110 ]) |
| 121 | 111 |
| 122 def test_files_with_shebang_are_made_executable(self): | 112 def test_files_with_shebang_are_made_executable(self): |
| 123 host = MockHost() | 113 host = MockHost() |
| 124 host.filesystem = MockFileSystem(files=FAKE_FILES) | 114 host.filesystem = MockFileSystem(files=FAKE_FILES) |
| 125 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) | 115 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) |
| 126 importer.do_import() | 116 importer.do_import() |
| 127 self.assertEqual( | 117 self.assertEqual( |
| 128 host.filesystem.executable_files, | 118 host.filesystem.executable_files, |
| 129 set(['/mock-checkout/third_party/WebKit/LayoutTests/w3c/blink/w3c/di
r/has_shebang.txt'])) | 119 set(['/mock-checkout/third_party/WebKit/LayoutTests/external/blink/w
3c/dir/has_shebang.txt'])) |
| 130 | 120 |
| 131 def test_ref_test_with_ref_is_copied(self): | 121 def test_ref_test_with_ref_is_copied(self): |
| 132 host = MockHost() | 122 host = MockHost() |
| 133 host.filesystem = MockFileSystem(files={ | 123 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>', | 124 '/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>', | 125 '/blink/w3c/dir1/ref-file.html': '<html><head>test</head></html>', |
| 136 '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations
': '', | 126 '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations
': '', |
| 137 '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in'
: '', | 127 '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in'
: '', |
| 138 }) | 128 }) |
| 139 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) | 129 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) |
| 140 importer.find_importable_tests() | 130 importer.find_importable_tests() |
| 141 self.assertEqual( | 131 self.assertEqual( |
| 142 importer.import_list, | 132 importer.import_list, |
| 143 [ | 133 [ |
| 144 { | 134 { |
| 145 'copy_list': [ | 135 'copy_list': [ |
| 146 {'src': '/blink/w3c/dir1/ref-file.html', 'dest': 'ref-fi
le.html'}, | 136 {'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': {}}, | 137 {'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'} | 138 {'src': '/blink/w3c/dir1/my-ref-test.html', 'dest': 'my-
ref-test.html'} |
| 149 ], | 139 ], |
| 150 'dirname': '/blink/w3c/dir1', | 140 'dirname': '/blink/w3c/dir1', |
| 151 'jstests': 0, | 141 'jstests': 0, |
| 152 'reftests': 1, | 142 'reftests': 1, |
| 153 'total_tests': 1 | 143 'total_tests': 1 |
| 154 } | 144 } |
| 155 ]) | 145 ]) |
| 156 | 146 |
| 157 def test_ref_test_without_ref_is_skipped(self): | 147 def test_ref_test_without_ref_is_skipped(self): |
| 158 host = MockHost() | 148 host = MockHost() |
| 159 host.filesystem = MockFileSystem(files={ | 149 host.filesystem = MockFileSystem(files={ |
| 160 '/blink/w3c/dir1/my-ref-test.html': '<html><head><link rel="match" h
ref="not-here.html" /></head></html>', | 150 '/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
': '', | 151 '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations
': '', |
| 162 '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in'
: '', | 152 '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in'
: '', |
| 163 }) | 153 }) |
| 164 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) | 154 importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) |
| 165 importer.find_importable_tests() | 155 importer.find_importable_tests() |
| 166 self.assertEqual(importer.import_list, []) | 156 self.assertEqual(importer.import_list, []) |
| 167 | 157 |
| 168 def test_should_try_to_convert_positive_cases(self): | 158 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')) | 159 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')) | 160 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')) | 161 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')) | 162 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')) | 163 self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.xhtml', 'Lay
outTests/external/csswg-test/x')) |
| 174 | 164 |
| 175 def test_should_not_try_to_convert_js_test(self): | 165 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')) | 166 self.assertFalse(TestImporter.should_try_to_convert({'is_jstest': True},
'foo.html', 'LayoutTests/external/csswg-test/x')) |
| 177 | 167 |
| 178 def test_should_not_try_to_convert_test_in_wpt(self): | 168 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')) | 169 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.html', 'Lay
outTests/external/wpt/foo')) |
| 180 | 170 |
| 181 def test_should_not_try_to_convert_other_file_types(self): | 171 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')) | 172 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')) | 173 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')) | 174 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')) | 175 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')) | 176 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')) | 177 self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.svgz', 'Lay
outTests/external/csswg-test/x')) |
| OLD | NEW |