| OLD | NEW |
| (Empty) |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import unittest | |
| 6 | |
| 7 from dashboard.pinpoint.models import quest | |
| 8 from dashboard.pinpoint.models import quest_generator | |
| 9 | |
| 10 | |
| 11 _RUN_TEST_ARGUMENTS = [ | |
| 12 'benchmark_name', '--story-filter', 'story_name', | |
| 13 '--pageset-repeat', '10', '--browser', 'release', | |
| 14 '-v', '--upload-results', '--output-format', 'chartjson', | |
| 15 '--isolated-script-test-output', '${ISOLATED_OUTDIR}/output.json', | |
| 16 '--isolated-script-test-chartjson-output', | |
| 17 '${ISOLATED_OUTDIR}/chartjson-output.json', | |
| 18 ] | |
| 19 | |
| 20 | |
| 21 class QuestGeneratorTest(unittest.TestCase): | |
| 22 | |
| 23 def testQuestGenerator(self): | |
| 24 with self.assertRaises(TypeError): | |
| 25 quest_generator.QuestGenerator({}) | |
| 26 | |
| 27 request = { | |
| 28 'target': 'telemetry_perf_tests', | |
| 29 'configuration': 'chromium-rel-mac11-pro', | |
| 30 } | |
| 31 self.assertIsInstance( | |
| 32 quest_generator.QuestGenerator(request), | |
| 33 quest_generator.TelemetryQuestGenerator) | |
| 34 | |
| 35 self.assertIsInstance( | |
| 36 quest_generator.QuestGenerator({'target': 'net_perftests'}), | |
| 37 quest_generator.GTestQuestGenerator) | |
| 38 | |
| 39 | |
| 40 class GTestQuestGeneratorTest(unittest.TestCase): | |
| 41 | |
| 42 def testQuests(self): | |
| 43 generator = quest_generator.GTestQuestGenerator() | |
| 44 self.assertEqual(generator.Quests(), ()) | |
| 45 | |
| 46 def testAsDict(self): | |
| 47 generator = quest_generator.GTestQuestGenerator() | |
| 48 self.assertEqual(generator.AsDict(), {}) | |
| 49 | |
| 50 | |
| 51 class TelemetryQuestGeneratorTest(unittest.TestCase): | |
| 52 | |
| 53 def testMissingArguments(self): | |
| 54 base_request = { | |
| 55 'configuration': 'chromium-rel-mac11-pro', | |
| 56 'target': 'telemetry_perf_tests', | |
| 57 'dimensions': '{}', | |
| 58 'benchmark': 'speedometer', | |
| 59 } | |
| 60 | |
| 61 for argument_name in ('configuration', 'target', 'benchmark'): | |
| 62 request = dict(base_request) | |
| 63 del request[argument_name] | |
| 64 with self.assertRaises(TypeError): | |
| 65 quest_generator.TelemetryQuestGenerator(request) | |
| 66 | |
| 67 def testInvalidArguments(self): | |
| 68 with self.assertRaises(ValueError): | |
| 69 quest_generator.TelemetryQuestGenerator({ | |
| 70 'configuration': 'chromium-rel-mac11-pro', | |
| 71 'target': 'telemetry_perf_tests', | |
| 72 'dimensions': 'invalid json', | |
| 73 'benchmark': 'speedometer', | |
| 74 }) | |
| 75 | |
| 76 with self.assertRaises(ValueError): | |
| 77 quest_generator.TelemetryQuestGenerator({ | |
| 78 'configuration': 'chromium-rel-mac11-pro', | |
| 79 'target': 'telemetry_perf_tests', | |
| 80 'dimensions': '{}', | |
| 81 'benchmark': 'speedometer', | |
| 82 'repeat_count': 'not a number', | |
| 83 }) | |
| 84 | |
| 85 def testQuests(self): | |
| 86 request = { | |
| 87 'configuration': 'chromium-rel-mac11-pro', | |
| 88 'target': 'telemetry_perf_tests', | |
| 89 'dimensions': '{"key": "value"}', | |
| 90 'benchmark': 'benchmark_name', | |
| 91 'story': 'story_name', | |
| 92 'metric': 'metric_name', | |
| 93 'repeat_count': '10', | |
| 94 } | |
| 95 generator = quest_generator.TelemetryQuestGenerator(request) | |
| 96 | |
| 97 expected_quests = [ | |
| 98 quest.FindIsolate('chromium-rel-mac11-pro', 'telemetry_perf_tests'), | |
| 99 quest.RunTest({'key': 'value'}, _RUN_TEST_ARGUMENTS), | |
| 100 quest.ReadChartJsonValue('metric_name', 'story_name'), | |
| 101 ] | |
| 102 self.assertEqual(generator.Quests(), expected_quests) | |
| 103 | |
| 104 def testAsDict(self): | |
| 105 request = { | |
| 106 'configuration': 'chromium-rel-mac11-pro', | |
| 107 'target': 'telemetry_perf_tests', | |
| 108 'dimensions': '{"key": "value"}', | |
| 109 'benchmark': 'page_cycler_v2_site_isolation.basic_oopif', | |
| 110 'story': 'http://www.fifa.com/', | |
| 111 'metric': 'pcv1-cold@@timeToFirstMeaningfulPaint_avg', | |
| 112 'repeat_count': '10', | |
| 113 } | |
| 114 generator = quest_generator.TelemetryQuestGenerator(request) | |
| 115 | |
| 116 expected_dict = { | |
| 117 'configuration': 'chromium-rel-mac11-pro', | |
| 118 'target': 'telemetry_perf_tests', | |
| 119 'dimensions': {'key': 'value'}, | |
| 120 'browser': 'release', | |
| 121 'benchmark': 'page_cycler_v2_site_isolation.basic_oopif', | |
| 122 'story': 'http://www.fifa.com/', | |
| 123 'metric': 'pcv1-cold@@timeToFirstMeaningfulPaint_avg', | |
| 124 'repeat_count': 10, | |
| 125 } | |
| 126 self.assertEqual(generator.AsDict(), expected_dict) | |
| OLD | NEW |