OLD | NEW |
1 # Copyright (C) 2010, 2012 Google Inc. All rights reserved. | 1 # Copyright (C) 2010, 2012 Google Inc. 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 are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 from webkitpy.layout_tests.views import printing | 45 from webkitpy.layout_tests.views import printing |
46 | 46 |
47 | 47 |
48 def get_options(args): | 48 def get_options(args): |
49 print_options = printing.print_options() | 49 print_options = printing.print_options() |
50 option_parser = optparse.OptionParser(option_list=print_options) | 50 option_parser = optparse.OptionParser(option_list=print_options) |
51 return option_parser.parse_args(args) | 51 return option_parser.parse_args(args) |
52 | 52 |
53 | 53 |
54 class TestUtilityFunctions(unittest.TestCase): | 54 class TestUtilityFunctions(unittest.TestCase): |
| 55 |
55 def test_print_options(self): | 56 def test_print_options(self): |
56 options, args = get_options([]) | 57 options, args = get_options([]) |
57 self.assertIsNotNone(options) | 58 self.assertIsNotNone(options) |
58 | 59 |
59 | 60 |
60 class FakeRunResults(object): | 61 class FakeRunResults(object): |
| 62 |
61 def __init__(self, total=1, expected=1, unexpected=0, fake_results=None): | 63 def __init__(self, total=1, expected=1, unexpected=0, fake_results=None): |
62 fake_results = fake_results or [] | 64 fake_results = fake_results or [] |
63 self.total = total | 65 self.total = total |
64 self.expected = expected | 66 self.expected = expected |
65 self.expected_failures = 0 | 67 self.expected_failures = 0 |
66 self.unexpected = unexpected | 68 self.unexpected = unexpected |
67 self.expected_skips = 0 | 69 self.expected_skips = 0 |
68 self.results_by_name = {} | 70 self.results_by_name = {} |
69 total_run_time = 0 | 71 total_run_time = 0 |
70 for result in fake_results: | 72 for result in fake_results: |
71 self.results_by_name[result.shard_name] = result | 73 self.results_by_name[result.shard_name] = result |
72 total_run_time += result.total_run_time | 74 total_run_time += result.total_run_time |
73 self.run_time = total_run_time + 1 | 75 self.run_time = total_run_time + 1 |
74 | 76 |
75 | 77 |
76 class FakeShard(object): | 78 class FakeShard(object): |
| 79 |
77 def __init__(self, shard_name, total_run_time): | 80 def __init__(self, shard_name, total_run_time): |
78 self.shard_name = shard_name | 81 self.shard_name = shard_name |
79 self.total_run_time = total_run_time | 82 self.total_run_time = total_run_time |
80 | 83 |
81 | 84 |
82 class Testprinter(unittest.TestCase): | 85 class Testprinter(unittest.TestCase): |
| 86 |
83 def assertEmpty(self, stream): | 87 def assertEmpty(self, stream): |
84 self.assertFalse(stream.getvalue()) | 88 self.assertFalse(stream.getvalue()) |
85 | 89 |
86 def assertNotEmpty(self, stream): | 90 def assertNotEmpty(self, stream): |
87 self.assertTrue(stream.getvalue()) | 91 self.assertTrue(stream.getvalue()) |
88 | 92 |
89 def assertWritten(self, stream, contents): | 93 def assertWritten(self, stream, contents): |
90 self.assertEqual(stream.buflist, contents) | 94 self.assertEqual(stream.buflist, contents) |
91 | 95 |
92 def reset(self, stream): | 96 def reset(self, stream): |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 printer._options.debug_rwt_logging = True | 154 printer._options.debug_rwt_logging = True |
151 | 155 |
152 run_results = FakeRunResults() | 156 run_results = FakeRunResults() |
153 run_results.results_by_name = { | 157 run_results.results_by_name = { |
154 "slowShard": FakeShard("slowShard", 16), | 158 "slowShard": FakeShard("slowShard", 16), |
155 "borderlineShard": FakeShard("borderlineShard", 15), | 159 "borderlineShard": FakeShard("borderlineShard", 15), |
156 "fastShard": FakeShard("fastShard", 1), | 160 "fastShard": FakeShard("fastShard", 1), |
157 } | 161 } |
158 | 162 |
159 printer._print_directory_timings(run_results) | 163 printer._print_directory_timings(run_results) |
160 self.assertWritten(err, ['Time to process slowest subdirectories:\n', '
slowShard took 16.0 seconds to run 1 tests.\n', '\n']) | 164 self.assertWritten(err, ['Time to process slowest subdirectories:\n', |
| 165 ' slowShard took 16.0 seconds to run 1 tests.\
n', '\n']) |
161 | 166 |
162 printer, err = self.get_printer() | 167 printer, err = self.get_printer() |
163 printer._options.debug_rwt_logging = True | 168 printer._options.debug_rwt_logging = True |
164 | 169 |
165 run_results.results_by_name = { | 170 run_results.results_by_name = { |
166 "borderlineShard": FakeShard("borderlineShard", 15), | 171 "borderlineShard": FakeShard("borderlineShard", 15), |
167 "fastShard": FakeShard("fastShard", 1), | 172 "fastShard": FakeShard("fastShard", 1), |
168 } | 173 } |
169 | 174 |
170 printer._print_directory_timings(run_results) | 175 printer._print_directory_timings(run_results) |
(...skipping 16 matching lines...) Expand all Loading... |
187 # With times: | 192 # With times: |
188 fake_shards = [FakeShard("foo", 1), FakeShard("bar", 2)] | 193 fake_shards = [FakeShard("foo", 1), FakeShard("bar", 2)] |
189 run_test(1, 1, 0, fake_shards, ["The test ran as expected in 5.00s (2.00
s in rwt, 1x).\n", "\n"]) | 194 run_test(1, 1, 0, fake_shards, ["The test ran as expected in 5.00s (2.00
s in rwt, 1x).\n", "\n"]) |
190 run_test(2, 1, 1, fake_shards, ["\n", "1 test ran as expected, 1 didn't
in 5.00s (2.00s in rwt, 1x):\n", "\n"]) | 195 run_test(2, 1, 1, fake_shards, ["\n", "1 test ran as expected, 1 didn't
in 5.00s (2.00s in rwt, 1x):\n", "\n"]) |
191 run_test(3, 2, 1, fake_shards, ["\n", "2 tests ran as expected, 1 didn't
in 5.00s (2.00s in rwt, 1x):\n", "\n"]) | 196 run_test(3, 2, 1, fake_shards, ["\n", "2 tests ran as expected, 1 didn't
in 5.00s (2.00s in rwt, 1x):\n", "\n"]) |
192 run_test(3, 2, 0, fake_shards, ["\n", "2 tests ran as expected (1 didn't
run) in 5.00s (2.00s in rwt, 1x).\n", "\n"]) | 197 run_test(3, 2, 0, fake_shards, ["\n", "2 tests ran as expected (1 didn't
run) in 5.00s (2.00s in rwt, 1x).\n", "\n"]) |
193 | 198 |
194 def test_test_status_line(self): | 199 def test_test_status_line(self): |
195 printer, _ = self.get_printer() | 200 printer, _ = self.get_printer() |
196 printer._meter.number_of_columns = lambda: 80 | 201 printer._meter.number_of_columns = lambda: 80 |
197 actual = printer._test_status_line('fast/dom/HTMLFormElement/associated-
elements-after-index-assertion-fail1.html', ' passed') | 202 actual = printer._test_status_line( |
| 203 'fast/dom/HTMLFormElement/associated-elements-after-index-assertion-
fail1.html', ' passed') |
198 self.assertEqual(80, len(actual)) | 204 self.assertEqual(80, len(actual)) |
199 self.assertEqual(actual, '[0/0] fast/dom/HTMLFormElement/associa...after
-index-assertion-fail1.html passed') | 205 self.assertEqual(actual, '[0/0] fast/dom/HTMLFormElement/associa...after
-index-assertion-fail1.html passed') |
200 | 206 |
201 printer._meter.number_of_columns = lambda: 89 | 207 printer._meter.number_of_columns = lambda: 89 |
202 actual = printer._test_status_line('fast/dom/HTMLFormElement/associated-
elements-after-index-assertion-fail1.html', ' passed') | 208 actual = printer._test_status_line( |
| 209 'fast/dom/HTMLFormElement/associated-elements-after-index-assertion-
fail1.html', ' passed') |
203 self.assertEqual(89, len(actual)) | 210 self.assertEqual(89, len(actual)) |
204 self.assertEqual(actual, '[0/0] fast/dom/HTMLFormElement/associated-...e
nts-after-index-assertion-fail1.html passed') | 211 self.assertEqual(actual, '[0/0] fast/dom/HTMLFormElement/associated-...e
nts-after-index-assertion-fail1.html passed') |
205 | 212 |
206 printer._meter.number_of_columns = lambda: sys.maxint | 213 printer._meter.number_of_columns = lambda: sys.maxint |
207 actual = printer._test_status_line('fast/dom/HTMLFormElement/associated-
elements-after-index-assertion-fail1.html', ' passed') | 214 actual = printer._test_status_line( |
| 215 'fast/dom/HTMLFormElement/associated-elements-after-index-assertion-
fail1.html', ' passed') |
208 self.assertEqual(90, len(actual)) | 216 self.assertEqual(90, len(actual)) |
209 self.assertEqual(actual, '[0/0] fast/dom/HTMLFormElement/associated-elem
ents-after-index-assertion-fail1.html passed') | 217 self.assertEqual(actual, '[0/0] fast/dom/HTMLFormElement/associated-elem
ents-after-index-assertion-fail1.html passed') |
210 | 218 |
211 printer._meter.number_of_columns = lambda: 18 | 219 printer._meter.number_of_columns = lambda: 18 |
212 actual = printer._test_status_line('fast/dom/HTMLFormElement/associated-
elements-after-index-assertion-fail1.html', ' passed') | 220 actual = printer._test_status_line( |
| 221 'fast/dom/HTMLFormElement/associated-elements-after-index-assertion-
fail1.html', ' passed') |
213 self.assertEqual(18, len(actual)) | 222 self.assertEqual(18, len(actual)) |
214 self.assertEqual(actual, '[0/0] f...l passed') | 223 self.assertEqual(actual, '[0/0] f...l passed') |
215 | 224 |
216 printer._meter.number_of_columns = lambda: 10 | 225 printer._meter.number_of_columns = lambda: 10 |
217 actual = printer._test_status_line('fast/dom/HTMLFormElement/associated-
elements-after-index-assertion-fail1.html', ' passed') | 226 actual = printer._test_status_line( |
| 227 'fast/dom/HTMLFormElement/associated-elements-after-index-assertion-
fail1.html', ' passed') |
218 self.assertEqual(actual, '[0/0] associated-elements-after-index-assertio
n-fail1.html passed') | 228 self.assertEqual(actual, '[0/0] associated-elements-after-index-assertio
n-fail1.html passed') |
219 | 229 |
220 def test_details(self): | 230 def test_details(self): |
221 printer, err = self.get_printer(['--details']) | 231 printer, err = self.get_printer(['--details']) |
222 result = self.get_result('passes/image.html') | 232 result = self.get_result('passes/image.html') |
223 printer.print_started_test('passes/image.html') | 233 printer.print_started_test('passes/image.html') |
224 printer.print_finished_test(result, expected=False, exp_str='', got_str=
'') | 234 printer.print_finished_test(result, expected=False, exp_str='', got_str=
'') |
225 self.assertNotEmpty(err) | 235 self.assertNotEmpty(err) |
226 | 236 |
227 def test_print_found(self): | 237 def test_print_found(self): |
(...skipping 14 matching lines...) Expand all Loading... |
242 printer.print_finished_test(result, expected=True, exp_str='', got_str='
') | 252 printer.print_finished_test(result, expected=True, exp_str='', got_str='
') |
243 | 253 |
244 printer.print_started_test('passes/text.html') | 254 printer.print_started_test('passes/text.html') |
245 result = self.get_result('passes/text.html') | 255 result = self.get_result('passes/text.html') |
246 printer.print_finished_test(result, expected=True, exp_str='', got_str='
') | 256 printer.print_finished_test(result, expected=True, exp_str='', got_str='
') |
247 | 257 |
248 # Only the first test's start should be printed. | 258 # Only the first test's start should be printed. |
249 lines = err.buflist | 259 lines = err.buflist |
250 self.assertEqual(len(lines), 1) | 260 self.assertEqual(len(lines), 1) |
251 self.assertTrue(lines[0].endswith('passes/image.html\n')) | 261 self.assertTrue(lines[0].endswith('passes/image.html\n')) |
OLD | NEW |