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

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

Issue 2206433002: Pass Host object into test_parser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_parser.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 10 matching lines...) Expand all
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 os 28 import os
29 import unittest 29 import unittest
30 30
31 from webkitpy.common.host_mock import MockHost
31 from webkitpy.common.system.outputcapture import OutputCapture 32 from webkitpy.common.system.outputcapture import OutputCapture
32 from webkitpy.w3c.test_parser import TestParser 33 from webkitpy.w3c.test_parser import TestParser
33 34
34
35 class TestParserTest(unittest.TestCase): 35 class TestParserTest(unittest.TestCase):
36 36
37 def test_analyze_test_reftest_one_match(self): 37 def test_analyze_test_reftest_one_match(self):
38 test_html = """<head> 38 test_html = """<head>
39 <link rel="match" href="green-box-ref.xht" /> 39 <link rel="match" href="green-box-ref.xht" />
40 </head> 40 </head>
41 """ 41 """
42 test_path = '/some/madeup/path/' 42 test_path = '/some/madeup/path/'
43 parser = TestParser(test_path + 'somefile.html') 43 parser = TestParser(test_path + 'somefile.html', MockHost())
44 test_info = parser.analyze_test(test_contents=test_html) 44 test_info = parser.analyze_test(test_contents=test_html)
45 45
46 self.assertNotEqual(test_info, None, 'did not find a test') 46 self.assertNotEqual(test_info, None, 'did not find a test')
47 self.assertTrue('test' in test_info.keys(), 'did not find a test file') 47 self.assertTrue('test' in test_info.keys(), 'did not find a test file')
48 self.assertTrue('reference' in test_info.keys(), 'did not find a referen ce file') 48 self.assertTrue('reference' in test_info.keys(), 'did not find a referen ce file')
49 self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct') 49 self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
50 self.assertFalse('refsupport' in test_info.keys(), 'there should be no r efsupport files for this test') 50 self.assertFalse('refsupport' in test_info.keys(), 'there should be no r efsupport files for this test')
51 self.assertFalse('jstest' in test_info.keys(), 'test should not have bee n analyzed as a jstest') 51 self.assertFalse('jstest' in test_info.keys(), 'test should not have bee n analyzed as a jstest')
52 52
53 def test_analyze_test_reftest_multiple_matches(self): 53 def test_analyze_test_reftest_multiple_matches(self):
54 test_html = """<head> 54 test_html = """<head>
55 <link rel="match" href="green-box-ref.xht" /> 55 <link rel="match" href="green-box-ref.xht" />
56 <link rel="match" href="blue-box-ref.xht" /> 56 <link rel="match" href="blue-box-ref.xht" />
57 <link rel="match" href="orange-box-ref.xht" /> 57 <link rel="match" href="orange-box-ref.xht" />
58 </head> 58 </head>
59 """ 59 """
60 oc = OutputCapture() 60 oc = OutputCapture()
61 oc.capture_output() 61 oc.capture_output()
62 try: 62 try:
63 test_path = '/some/madeup/path/' 63 test_path = '/some/madeup/path/'
64 parser = TestParser(test_path + 'somefile.html') 64 parser = TestParser(test_path + 'somefile.html', MockHost())
65 test_info = parser.analyze_test(test_contents=test_html) 65 test_info = parser.analyze_test(test_contents=test_html)
66 finally: 66 finally:
67 _, _, logs = oc.restore_output() 67 _, _, logs = oc.restore_output()
68 68
69 self.assertNotEqual(test_info, None, 'did not find a test') 69 self.assertNotEqual(test_info, None, 'did not find a test')
70 self.assertTrue('test' in test_info.keys(), 'did not find a test file') 70 self.assertTrue('test' in test_info.keys(), 'did not find a test file')
71 self.assertTrue('reference' in test_info.keys(), 'did not find a referen ce file') 71 self.assertTrue('reference' in test_info.keys(), 'did not find a referen ce file')
72 self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct') 72 self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
73 self.assertFalse('refsupport' in test_info.keys(), 'there should be no r efsupport files for this test') 73 self.assertFalse('refsupport' in test_info.keys(), 'there should be no r efsupport files for this test')
74 self.assertFalse('jstest' in test_info.keys(), 'test should not have bee n analyzed as a jstest') 74 self.assertFalse('jstest' in test_info.keys(), 'test should not have bee n analyzed as a jstest')
75 75
76 self.assertEqual(logs, 'Multiple references are not supported. Importing the first ref defined in somefile.html\n') 76 self.assertEqual(logs, 'Multiple references are not supported. Importing the first ref defined in somefile.html\n')
77 77
78 def test_analyze_test_reftest_match_and_mismatch(self): 78 def test_analyze_test_reftest_match_and_mismatch(self):
79 test_html = """<head> 79 test_html = """<head>
80 <link rel="match" href="green-box-ref.xht" /> 80 <link rel="match" href="green-box-ref.xht" />
81 <link rel="match" href="blue-box-ref.xht" /> 81 <link rel="match" href="blue-box-ref.xht" />
82 <link rel="mismatch" href="orange-box-notref.xht" /> 82 <link rel="mismatch" href="orange-box-notref.xht" />
83 </head> 83 </head>
84 """ 84 """
85 oc = OutputCapture() 85 oc = OutputCapture()
86 oc.capture_output() 86 oc.capture_output()
87 87
88 try: 88 try:
89 test_path = '/some/madeup/path/' 89 test_path = '/some/madeup/path/'
90 parser = TestParser(test_path + 'somefile.html') 90 parser = TestParser(test_path + 'somefile.html', MockHost())
91 test_info = parser.analyze_test(test_contents=test_html) 91 test_info = parser.analyze_test(test_contents=test_html)
92 finally: 92 finally:
93 _, _, logs = oc.restore_output() 93 _, _, logs = oc.restore_output()
94 94
95 self.assertNotEqual(test_info, None, 'did not find a test') 95 self.assertNotEqual(test_info, None, 'did not find a test')
96 self.assertTrue('test' in test_info.keys(), 'did not find a test file') 96 self.assertTrue('test' in test_info.keys(), 'did not find a test file')
97 self.assertTrue('reference' in test_info.keys(), 'did not find a referen ce file') 97 self.assertTrue('reference' in test_info.keys(), 'did not find a referen ce file')
98 self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct') 98 self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
99 self.assertFalse('refsupport' in test_info.keys(), 'there should be no r efsupport files for this test') 99 self.assertFalse('refsupport' in test_info.keys(), 'there should be no r efsupport files for this test')
100 self.assertFalse('jstest' in test_info.keys(), 'test should not have bee n analyzed as a jstest') 100 self.assertFalse('jstest' in test_info.keys(), 'test should not have bee n analyzed as a jstest')
(...skipping 13 matching lines...) Expand all
114 <style type="text/css"> 114 <style type="text/css">
115 background-image: url("../../support/some-image.png") 115 background-image: url("../../support/some-image.png")
116 </style> 116 </style>
117 </head> 117 </head>
118 <body> 118 <body>
119 <div><img src="../support/black96x96.png" alt="Image download support must be en abled" /></div> 119 <div><img src="../support/black96x96.png" alt="Image download support must be en abled" /></div>
120 </body> 120 </body>
121 </html> 121 </html>
122 """ 122 """
123 test_path = '/some/madeup/path/' 123 test_path = '/some/madeup/path/'
124 parser = TestParser(test_path + 'somefile.html') 124 parser = TestParser(test_path + 'somefile.html', MockHost())
125 test_info = parser.analyze_test(test_contents=test_html, ref_contents=re f_html) 125 test_info = parser.analyze_test(test_contents=test_html, ref_contents=re f_html)
126 126
127 self.assertNotEqual(test_info, None, 'did not find a test') 127 self.assertNotEqual(test_info, None, 'did not find a test')
128 self.assertTrue('test' in test_info.keys(), 'did not find a test file') 128 self.assertTrue('test' in test_info.keys(), 'did not find a test file')
129 self.assertTrue('reference' in test_info.keys(), 'did not find a referen ce file') 129 self.assertTrue('reference' in test_info.keys(), 'did not find a referen ce file')
130 self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct') 130 self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
131 self.assertTrue('reference_support_info' in test_info.keys(), 'there sho uld be reference_support_info for this test') 131 self.assertTrue('reference_support_info' in test_info.keys(), 'there sho uld be reference_support_info for this test')
132 self.assertEquals(len(test_info['reference_support_info']['files']), 3, 'there should be 3 support files in this reference') 132 self.assertEquals(len(test_info['reference_support_info']['files']), 3, 'there should be 3 support files in this reference')
133 self.assertFalse('jstest' in test_info.keys(), 'test should not have bee n analyzed as a jstest') 133 self.assertFalse('jstest' in test_info.keys(), 'test should not have bee n analyzed as a jstest')
134 134
135 def test_analyze_jstest(self): 135 def test_analyze_jstest(self):
136 """ Tests analyze_test() using a jstest """ 136 """ Tests analyze_test() using a jstest """
137 137
138 test_html = """<head> 138 test_html = """<head>
139 <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> 139 <link href="/resources/testharness.css" rel="stylesheet" type="text/css">
140 <script src="/resources/testharness.js"></script> 140 <script src="/resources/testharness.js"></script>
141 </head> 141 </head>
142 """ 142 """
143 test_path = '/some/madeup/path/' 143 test_path = '/some/madeup/path/'
144 parser = TestParser(test_path + 'somefile.html') 144 parser = TestParser(test_path + 'somefile.html', MockHost())
145 test_info = parser.analyze_test(test_contents=test_html) 145 test_info = parser.analyze_test(test_contents=test_html)
146 146
147 self.assertNotEqual(test_info, None, 'test_info is None') 147 self.assertNotEqual(test_info, None, 'test_info is None')
148 self.assertTrue('test' in test_info.keys(), 'did not find a test file') 148 self.assertTrue('test' in test_info.keys(), 'did not find a test file')
149 self.assertFalse('reference' in test_info.keys(), 'should not have found a reference file') 149 self.assertFalse('reference' in test_info.keys(), 'should not have found a reference file')
150 self.assertFalse('refsupport' in test_info.keys(), 'there should be no r efsupport files for this test') 150 self.assertFalse('refsupport' in test_info.keys(), 'there should be no r efsupport files for this test')
151 self.assertTrue('jstest' in test_info.keys(), 'test should be a jstest') 151 self.assertTrue('jstest' in test_info.keys(), 'test should be a jstest')
152 152
153 def test_analyze_pixel_test_all_true(self): 153 def test_analyze_pixel_test_all_true(self):
154 """ Tests analyze_test() using a test that is neither a reftest or jstes t with all=False """ 154 """ Tests analyze_test() using a test that is neither a reftest or jstes t with all=False """
155 155
156 test_html = """<html> 156 test_html = """<html>
157 <head> 157 <head>
158 <title>CSS Test: DESCRIPTION OF TEST</title> 158 <title>CSS Test: DESCRIPTION OF TEST</title>
159 <link rel="author" title="NAME_OF_AUTHOR" /> 159 <link rel="author" title="NAME_OF_AUTHOR" />
160 <style type="text/css"><![CDATA[ 160 <style type="text/css"><![CDATA[
161 CSS FOR TEST 161 CSS FOR TEST
162 ]]></style> 162 ]]></style>
163 </head> 163 </head>
164 <body> 164 <body>
165 CONTENT OF TEST 165 CONTENT OF TEST
166 </body> 166 </body>
167 </html> 167 </html>
168 """ 168 """
169 # Set 'all' to True so this gets found. 169 # Set 'all' to True so this gets found.
170 options = {'all': True} 170 options = {'all': True}
171 171
172 test_path = '/some/madeup/path/' 172 test_path = '/some/madeup/path/'
173 parser = TestParser(test_path + 'somefile.html', options) 173 parser = TestParser(test_path + 'somefile.html', MockHost(), options)
174 test_info = parser.analyze_test(test_contents=test_html) 174 test_info = parser.analyze_test(test_contents=test_html)
175 175
176 self.assertNotEqual(test_info, None, 'test_info is None') 176 self.assertNotEqual(test_info, None, 'test_info is None')
177 self.assertTrue('test' in test_info.keys(), 'did not find a test file') 177 self.assertTrue('test' in test_info.keys(), 'did not find a test file')
178 self.assertFalse('reference' in test_info.keys(), 'shold not have found a reference file') 178 self.assertFalse('reference' in test_info.keys(), 'shold not have found a reference file')
179 self.assertFalse('refsupport' in test_info.keys(), 'there should be no r efsupport files for this test') 179 self.assertFalse('refsupport' in test_info.keys(), 'there should be no r efsupport files for this test')
180 self.assertFalse('jstest' in test_info.keys(), 'test should not be a jst est') 180 self.assertFalse('jstest' in test_info.keys(), 'test should not be a jst est')
181 181
182 def test_analyze_pixel_test_all_false(self): 182 def test_analyze_pixel_test_all_false(self):
183 """ Tests analyze_test() using a test that is neither a reftest or jstes t, with -all=False """ 183 """ Tests analyze_test() using a test that is neither a reftest or jstes t, with -all=False """
184 184
185 test_html = """<html> 185 test_html = """<html>
186 <head> 186 <head>
187 <title>CSS Test: DESCRIPTION OF TEST</title> 187 <title>CSS Test: DESCRIPTION OF TEST</title>
188 <link rel="author" title="NAME_OF_AUTHOR" /> 188 <link rel="author" title="NAME_OF_AUTHOR" />
189 <style type="text/css"><![CDATA[ 189 <style type="text/css"><![CDATA[
190 CSS FOR TEST 190 CSS FOR TEST
191 ]]></style> 191 ]]></style>
192 </head> 192 </head>
193 <body> 193 <body>
194 CONTENT OF TEST 194 CONTENT OF TEST
195 </body> 195 </body>
196 </html> 196 </html>
197 """ 197 """
198 # Set 'all' to False so this gets skipped. 198 # Set 'all' to False so this gets skipped.
199 options = {'all': False} 199 options = {'all': False}
200 200
201 test_path = '/some/madeup/path/' 201 test_path = '/some/madeup/path/'
202 parser = TestParser(test_path + 'somefile.html', options) 202 parser = TestParser(test_path + 'somefile.html', MockHost(), options)
203 test_info = parser.analyze_test(test_contents=test_html) 203 test_info = parser.analyze_test(test_contents=test_html)
204 204
205 self.assertEqual(test_info, None, 'test should have been skipped') 205 self.assertEqual(test_info, None, 'test should have been skipped')
206 206
207 def test_analyze_non_html_file(self): 207 def test_analyze_non_html_file(self):
208 """ Tests analyze_test() with a file that has no html""" 208 """ Tests analyze_test() with a file that has no html"""
209 # FIXME: use a mock filesystem 209 # FIXME: use a mock filesystem
210 parser = TestParser(os.path.join(os.path.dirname(__file__), 'test_parser .py')) 210 parser = TestParser(os.path.join(os.path.dirname(__file__), 'test_parser .py'), MockHost())
211 test_info = parser.analyze_test() 211 test_info = parser.analyze_test()
212 self.assertEqual(test_info, None, 'no tests should have been found in th is file') 212 self.assertEqual(test_info, None, 'no tests should have been found in th is file')
OLDNEW
« no previous file with comments | « third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_parser.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698