| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import math | 6 import math |
| 7 import os | 7 import os |
| 8 import shutil | 8 import shutil |
| 9 import StringIO | 9 import StringIO |
| 10 import sys | 10 import sys |
| (...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 tmp_path = tempfile.mkdtemp() | 1261 tmp_path = tempfile.mkdtemp() |
| 1262 try: | 1262 try: |
| 1263 options.output_dir = tmp_path | 1263 options.output_dir = tmp_path |
| 1264 story_runner.RunBenchmark(fake_benchmark, options) | 1264 story_runner.RunBenchmark(fake_benchmark, options) |
| 1265 with open(os.path.join(tmp_path, 'results-chart.json')) as f: | 1265 with open(os.path.join(tmp_path, 'results-chart.json')) as f: |
| 1266 data = json.load(f) | 1266 data = json.load(f) |
| 1267 self.assertFalse(data['enabled']) | 1267 self.assertFalse(data['enabled']) |
| 1268 finally: | 1268 finally: |
| 1269 shutil.rmtree(tmp_path) | 1269 shutil.rmtree(tmp_path) |
| 1270 | 1270 |
| 1271 # TODO(rnephew): Refactor this test when we no longer use | |
| 1272 # expectations.PermanentlyDisableBenchmark() to disable benchmarks. | |
| 1273 def testRunBenchmarkDisabledBenchmark(self): | 1271 def testRunBenchmarkDisabledBenchmark(self): |
| 1274 fake_benchmark = FakeBenchmark() | 1272 fake_benchmark = FakeBenchmark() |
| 1275 fake_benchmark.disabled = True | 1273 fake_benchmark.disabled = True |
| 1276 options = self._GenerateBaseBrowserFinderOptions() | 1274 options = self._GenerateBaseBrowserFinderOptions() |
| 1277 tmp_path = tempfile.mkdtemp() | 1275 tmp_path = tempfile.mkdtemp() |
| 1278 try: | 1276 try: |
| 1279 options.output_dir = tmp_path | 1277 options.output_dir = tmp_path |
| 1280 story_runner.RunBenchmark(fake_benchmark, options) | 1278 story_runner.RunBenchmark(fake_benchmark, options) |
| 1281 with open(os.path.join(tmp_path, 'results-chart.json')) as f: | 1279 with open(os.path.join(tmp_path, 'results-chart.json')) as f: |
| 1282 data = json.load(f) | 1280 data = json.load(f) |
| 1283 self.assertFalse(data['enabled']) | 1281 self.assertFalse(data['enabled']) |
| 1284 finally: | 1282 finally: |
| 1285 shutil.rmtree(tmp_path) | 1283 shutil.rmtree(tmp_path) |
| 1286 | 1284 |
| 1287 # TODO(rnephew): Refactor this test when we no longer use | 1285 def testRunBenchmarkDisabledBenchmarkCanOverriddenByCommandLine(self): |
| 1288 # expectations.PermanentlyDisableBenchmark() to disable benchmarks. | |
| 1289 def testRunBenchmarkDisabledBenchmarkCannotOverriddenByCommandLine(self): | |
| 1290 fake_benchmark = FakeBenchmark() | 1286 fake_benchmark = FakeBenchmark() |
| 1291 fake_benchmark.disabled = True | 1287 fake_benchmark.disabled = True |
| 1292 options = self._GenerateBaseBrowserFinderOptions() | 1288 options = self._GenerateBaseBrowserFinderOptions() |
| 1293 options.run_disabled_tests = True | 1289 options.run_disabled_tests = True |
| 1294 temp_path = tempfile.mkdtemp() | 1290 temp_path = tempfile.mkdtemp() |
| 1295 try: | 1291 try: |
| 1296 options.output_dir = temp_path | 1292 options.output_dir = temp_path |
| 1297 story_runner.RunBenchmark(fake_benchmark, options) | 1293 story_runner.RunBenchmark(fake_benchmark, options) |
| 1298 with open(os.path.join(temp_path, 'results-chart.json')) as f: | 1294 with open(os.path.join(temp_path, 'results-chart.json')) as f: |
| 1299 data = json.load(f) | 1295 data = json.load(f) |
| 1300 self.assertFalse(data['enabled']) | 1296 self.assertTrue(data['enabled']) |
| 1301 finally: | 1297 finally: |
| 1302 shutil.rmtree(temp_path) | 1298 shutil.rmtree(temp_path) |
| 1303 | 1299 |
| 1304 def testRunBenchmark_AddsOwners_NoComponent(self): | 1300 def testRunBenchmark_AddsOwners_NoComponent(self): |
| 1305 @benchmark.Owner(emails=['alice@chromium.org']) | 1301 @benchmark.Owner(emails=['alice@chromium.org']) |
| 1306 class FakeBenchmarkWithOwner(FakeBenchmark): | 1302 class FakeBenchmarkWithOwner(FakeBenchmark): |
| 1307 def __init__(self): | 1303 def __init__(self): |
| 1308 super(FakeBenchmark, self).__init__() | 1304 super(FakeBenchmark, self).__init__() |
| 1309 self._disabled = False | 1305 self._disabled = False |
| 1310 self._story_disabled = False | 1306 self._story_disabled = False |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1405 fake_benchmark.story_disabled = True | 1401 fake_benchmark.story_disabled = True |
| 1406 options = self._GenerateBaseBrowserFinderOptions() | 1402 options = self._GenerateBaseBrowserFinderOptions() |
| 1407 tmp_path = tempfile.mkdtemp() | 1403 tmp_path = tempfile.mkdtemp() |
| 1408 try: | 1404 try: |
| 1409 options.output_dir = tmp_path | 1405 options.output_dir = tmp_path |
| 1410 rc = story_runner.RunBenchmark(fake_benchmark, options) | 1406 rc = story_runner.RunBenchmark(fake_benchmark, options) |
| 1411 # Test should return 0 since only error messages are logged. | 1407 # Test should return 0 since only error messages are logged. |
| 1412 self.assertEqual(rc, 0) | 1408 self.assertEqual(rc, 0) |
| 1413 finally: | 1409 finally: |
| 1414 shutil.rmtree(tmp_path) | 1410 shutil.rmtree(tmp_path) |
| OLD | NEW |