| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 printer._options.quiet = True | 149 printer._options.quiet = True |
| 146 printer.print_config('/tmp') | 150 printer.print_config('/tmp') |
| 147 self.assertNotIn('Baseline search path: test-mac-leopard -> test-mac-sno
wleopard -> generic', err.getvalue()) | 151 self.assertNotIn('Baseline search path: test-mac-leopard -> test-mac-sno
wleopard -> generic', err.getvalue()) |
| 148 | 152 |
| 149 def test_print_directory_timings(self): | 153 def test_print_directory_timings(self): |
| 150 printer, err = self.get_printer() | 154 printer, err = self.get_printer() |
| 151 printer._options.debug_rwt_logging = True | 155 printer._options.debug_rwt_logging = True |
| 152 | 156 |
| 153 run_results = FakeRunResults() | 157 run_results = FakeRunResults() |
| 154 run_results.results_by_name = { | 158 run_results.results_by_name = { |
| 155 "slowShard": FakeShard("slowShard", 16), | 159 'slowShard': FakeShard('slowShard', 16), |
| 156 "borderlineShard": FakeShard("borderlineShard", 15), | 160 'borderlineShard': FakeShard('borderlineShard', 15), |
| 157 "fastShard": FakeShard("fastShard", 1), | 161 'fastShard': FakeShard('fastShard', 1), |
| 158 } | 162 } |
| 159 | 163 |
| 160 printer._print_directory_timings(run_results) | 164 printer._print_directory_timings(run_results) |
| 161 self.assertWritten(err, ['Time to process slowest subdirectories:\n', '
slowShard took 16.0 seconds to run 1 tests.\n', '\n']) | 165 self.assertWritten(err, |
| 166 ['Time to process slowest subdirectories:\n', |
| 167 ' slowShard took 16.0 seconds to run 1 tests.\n', |
| 168 '\n']) |
| 162 | 169 |
| 163 printer, err = self.get_printer() | 170 printer, err = self.get_printer() |
| 164 printer._options.debug_rwt_logging = True | 171 printer._options.debug_rwt_logging = True |
| 165 | 172 |
| 166 run_results.results_by_name = { | 173 run_results.results_by_name = { |
| 167 "borderlineShard": FakeShard("borderlineShard", 15), | 174 'borderlineShard': FakeShard('borderlineShard', 15), |
| 168 "fastShard": FakeShard("fastShard", 1), | 175 'fastShard': FakeShard('fastShard', 1), |
| 169 } | 176 } |
| 170 | 177 |
| 171 printer._print_directory_timings(run_results) | 178 printer._print_directory_timings(run_results) |
| 172 self.assertWritten(err, []) | 179 self.assertWritten(err, []) |
| 173 | 180 |
| 174 def test_print_one_line_summary(self): | 181 def test_print_one_line_summary(self): |
| 175 def run_test(total, exp, unexp, shards, result): | 182 def run_test(total, exp, unexp, shards, result): |
| 176 printer, err = self.get_printer(['--timing'] if shards else None) | 183 printer, err = self.get_printer(['--timing'] if shards else None) |
| 177 fake_results = FakeRunResults(total, exp, unexp, shards) | 184 fake_results = FakeRunResults(total, exp, unexp, shards) |
| 178 total_time = fake_results.run_time + 1 | 185 total_time = fake_results.run_time + 1 |
| 179 printer._print_one_line_summary(total_time, fake_results) | 186 printer._print_one_line_summary(total_time, fake_results) |
| 180 self.assertWritten(err, result) | 187 self.assertWritten(err, result) |
| 181 | 188 |
| 182 # Without times: | 189 # Without times: |
| 183 run_test(1, 1, 0, [], ["The test ran as expected.\n", "\n"]) | 190 run_test(1, 1, 0, [], ['The test ran as expected.\n', '\n']) |
| 184 run_test(2, 1, 1, [], ["\n", "1 test ran as expected, 1 didn't:\n", "\n"
]) | 191 run_test(2, 1, 1, [], ['\n', "1 test ran as expected, 1 didn't:\n", '\n'
]) |
| 185 run_test(3, 2, 1, [], ["\n", "2 tests ran as expected, 1 didn't:\n", "\n
"]) | 192 run_test(3, 2, 1, [], ['\n', "2 tests ran as expected, 1 didn't:\n", '\n
']) |
| 186 run_test(3, 2, 0, [], ["\n", "2 tests ran as expected (1 didn't run).\n"
, "\n"]) | 193 run_test(3, 2, 0, [], ['\n', "2 tests ran as expected (1 didn't run).\n"
, '\n']) |
| 187 | 194 |
| 188 # With times: | 195 # With times: |
| 189 fake_shards = [FakeShard("foo", 1), FakeShard("bar", 2)] | 196 fake_shards = [FakeShard('foo', 1), FakeShard('bar', 2)] |
| 190 run_test(1, 1, 0, fake_shards, ["The test ran as expected in 5.00s (2.00
s in rwt, 1x).\n", "\n"]) | 197 run_test(1, 1, 0, fake_shards, ['The test ran as expected in 5.00s (2.00
s in rwt, 1x).\n', '\n']) |
| 191 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"]) | 198 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']) |
| 192 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"]) | 199 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']) |
| 193 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"]) | 200 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']) |
| 194 | 201 |
| 195 def test_test_status_line(self): | 202 def test_test_status_line(self): |
| 196 printer, _ = self.get_printer() | 203 printer, _ = self.get_printer() |
| 197 printer._meter.number_of_columns = lambda: 80 | 204 printer._meter.number_of_columns = lambda: 80 |
| 198 actual = printer._test_status_line('fast/dom/HTMLFormElement/associated-
elements-after-index-assertion-fail1.html', ' passed') | 205 actual = printer._test_status_line( |
| 206 'fast/dom/HTMLFormElement/associated-elements-after-index-assertion-
fail1.html', |
| 207 ' passed') |
| 199 self.assertEqual(80, len(actual)) | 208 self.assertEqual(80, len(actual)) |
| 200 self.assertEqual(actual, '[0/0] fast/dom/HTMLFormElement/associa...after
-index-assertion-fail1.html passed') | 209 self.assertEqual(actual, '[0/0] fast/dom/HTMLFormElement/associa...after
-index-assertion-fail1.html passed') |
| 201 | 210 |
| 202 printer._meter.number_of_columns = lambda: 89 | 211 printer._meter.number_of_columns = lambda: 89 |
| 203 actual = printer._test_status_line('fast/dom/HTMLFormElement/associated-
elements-after-index-assertion-fail1.html', ' passed') | 212 actual = printer._test_status_line( |
| 213 'fast/dom/HTMLFormElement/associated-elements-after-index-assertion-
fail1.html', |
| 214 ' passed') |
| 204 self.assertEqual(89, len(actual)) | 215 self.assertEqual(89, len(actual)) |
| 205 self.assertEqual(actual, '[0/0] fast/dom/HTMLFormElement/associated-...e
nts-after-index-assertion-fail1.html passed') | 216 self.assertEqual(actual, '[0/0] fast/dom/HTMLFormElement/associated-...e
nts-after-index-assertion-fail1.html passed') |
| 206 | 217 |
| 207 printer._meter.number_of_columns = lambda: sys.maxint | 218 printer._meter.number_of_columns = lambda: sys.maxsize |
| 208 actual = printer._test_status_line('fast/dom/HTMLFormElement/associated-
elements-after-index-assertion-fail1.html', ' passed') | 219 actual = printer._test_status_line( |
| 220 'fast/dom/HTMLFormElement/associated-elements-after-index-assertion-
fail1.html', |
| 221 ' passed') |
| 209 self.assertEqual(90, len(actual)) | 222 self.assertEqual(90, len(actual)) |
| 210 self.assertEqual(actual, '[0/0] fast/dom/HTMLFormElement/associated-elem
ents-after-index-assertion-fail1.html passed') | 223 self.assertEqual(actual, '[0/0] fast/dom/HTMLFormElement/associated-elem
ents-after-index-assertion-fail1.html passed') |
| 211 | 224 |
| 212 printer._meter.number_of_columns = lambda: 18 | 225 printer._meter.number_of_columns = lambda: 18 |
| 213 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', |
| 228 ' passed') |
| 214 self.assertEqual(18, len(actual)) | 229 self.assertEqual(18, len(actual)) |
| 215 self.assertEqual(actual, '[0/0] f...l passed') | 230 self.assertEqual(actual, '[0/0] f...l passed') |
| 216 | 231 |
| 217 printer._meter.number_of_columns = lambda: 10 | 232 printer._meter.number_of_columns = lambda: 10 |
| 218 actual = printer._test_status_line('fast/dom/HTMLFormElement/associated-
elements-after-index-assertion-fail1.html', ' passed') | 233 actual = printer._test_status_line( |
| 234 'fast/dom/HTMLFormElement/associated-elements-after-index-assertion-
fail1.html', |
| 235 ' passed') |
| 219 self.assertEqual(actual, '[0/0] associated-elements-after-index-assertio
n-fail1.html passed') | 236 self.assertEqual(actual, '[0/0] associated-elements-after-index-assertio
n-fail1.html passed') |
| 220 | 237 |
| 221 def test_details(self): | 238 def test_details(self): |
| 222 printer, err = self.get_printer(['--details']) | 239 printer, err = self.get_printer(['--details']) |
| 223 result = self.get_result('passes/image.html') | 240 result = self.get_result('passes/image.html') |
| 224 printer.print_started_test('passes/image.html') | 241 printer.print_started_test('passes/image.html') |
| 225 printer.print_finished_test(result, expected=False, exp_str='', got_str=
'') | 242 printer.print_finished_test(result, expected=False, exp_str='', got_str=
'') |
| 226 self.assertNotEmpty(err) | 243 self.assertNotEmpty(err) |
| 227 | 244 |
| 228 def test_print_found(self): | 245 def test_print_found(self): |
| 229 printer, err = self.get_printer() | 246 printer, err = self.get_printer() |
| 230 | 247 |
| 231 printer.print_found(100, 10, 1, 1) | 248 printer.print_found(100, 10, 1, 1) |
| 232 self.assertWritten(err, ["Found 100 tests; running 10, skipping 90.\n"]) | 249 self.assertWritten(err, ['Found 100 tests; running 10, skipping 90.\n']) |
| 233 | 250 |
| 234 self.reset(err) | 251 self.reset(err) |
| 235 printer.print_found(100, 10, 2, 3) | 252 printer.print_found(100, 10, 2, 3) |
| 236 self.assertWritten(err, ["Found 100 tests; running 10 (6 times each: --r
epeat-each=2 --iterations=3), skipping 90.\n"]) | 253 self.assertWritten(err, ['Found 100 tests; running 10 (6 times each: --r
epeat-each=2 --iterations=3), skipping 90.\n']) |
| 237 | 254 |
| 238 def test_debug_rwt_logging_is_throttled(self): | 255 def test_debug_rwt_logging_is_throttled(self): |
| 239 printer, err = self.get_printer(['--debug-rwt-logging']) | 256 printer, err = self.get_printer(['--debug-rwt-logging']) |
| 240 | 257 |
| 241 result = self.get_result('passes/image.html') | 258 result = self.get_result('passes/image.html') |
| 242 printer.print_started_test('passes/image.html') | 259 printer.print_started_test('passes/image.html') |
| 243 printer.print_finished_test(result, expected=True, exp_str='', got_str='
') | 260 printer.print_finished_test(result, expected=True, exp_str='', got_str='
') |
| 244 | 261 |
| 245 printer.print_started_test('passes/text.html') | 262 printer.print_started_test('passes/text.html') |
| 246 result = self.get_result('passes/text.html') | 263 result = self.get_result('passes/text.html') |
| 247 printer.print_finished_test(result, expected=True, exp_str='', got_str='
') | 264 printer.print_finished_test(result, expected=True, exp_str='', got_str='
') |
| 248 | 265 |
| 249 # Only the first test's start should be printed. | 266 # Only the first test's start should be printed. |
| 250 lines = err.buflist | 267 lines = err.buflist |
| 251 self.assertEqual(len(lines), 1) | 268 self.assertEqual(len(lines), 1) |
| 252 self.assertTrue(lines[0].endswith('passes/image.html\n')) | 269 self.assertTrue(lines[0].endswith('passes/image.html\n')) |
| OLD | NEW |