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

Side by Side Diff: dashboard/dashboard/pinpoint/models/quest/read_value_test.py

Issue 2996473002: [pinpoint] Add QuestGenerator object. (Closed)
Patch Set: rebase Created 3 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
OLDNEW
1 # Copyright 2017 The Chromium Authors. All rights reserved. 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 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 unittest 6 import unittest
7 7
8 import mock 8 import mock
9 9
10 from dashboard.pinpoint.models.quest import read_value 10 from dashboard.pinpoint.models.quest import read_value
11 11
12 12
13 @mock.patch('dashboard.services.isolate_service.Retrieve') 13 @mock.patch('dashboard.services.isolate_service.Retrieve')
14 class ReadValueTest(unittest.TestCase): 14 class ReadChartJsonValueTest(unittest.TestCase):
15 15
16 def testReadValue(self, retrieve): 16 def testReadChartJsonValue(self, retrieve):
17 retrieve.side_effect = ( 17 retrieve.side_effect = (
18 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 18 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
19 json.dumps({'charts': {'metric': {'test': { 19 json.dumps({'charts': {'metric': {'test': {
20 'type': 'list_of_scalar_values', 20 'type': 'list_of_scalar_values',
21 'values': [0, 1, 2], 21 'values': [0, 1, 2],
22 }}}}), 22 }}}}),
23 ) 23 )
24 24
25 execution = read_value.ReadValue('metric', 'test').Start('output hash') 25 quest = read_value.ReadChartJsonValue('metric', 'test')
26 execution = quest.Start('output hash')
26 execution.Poll() 27 execution.Poll()
27 28
28 self.assertTrue(execution.completed) 29 self.assertTrue(execution.completed)
29 self.assertFalse(execution.failed) 30 self.assertFalse(execution.failed)
30 self.assertEqual(execution.result_values, (0, 1, 2)) 31 self.assertEqual(execution.result_values, (0, 1, 2))
31 self.assertEqual(execution.result_arguments, {}) 32 self.assertEqual(execution.result_arguments, {})
32 33
33 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')] 34 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')]
34 self.assertEqual(retrieve.mock_calls, expected_calls) 35 self.assertEqual(retrieve.mock_calls, expected_calls)
35 36
36 def testReadValueWithNoTest(self, retrieve): 37 def testReadChartJsonValueWithNoTest(self, retrieve):
37 retrieve.side_effect = ( 38 retrieve.side_effect = (
38 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 39 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
39 json.dumps({'charts': {'metric': {'summary': { 40 json.dumps({'charts': {'metric': {'summary': {
40 'type': 'list_of_scalar_values', 41 'type': 'list_of_scalar_values',
41 'values': [0, 1, 2], 42 'values': [0, 1, 2],
42 }}}}), 43 }}}}),
43 ) 44 )
44 45
45 execution = read_value.ReadValue('metric', None).Start('output hash') 46 quest = read_value.ReadChartJsonValue('metric', None)
47 execution = quest.Start('output hash')
46 execution.Poll() 48 execution.Poll()
47 49
48 self.assertTrue(execution.completed) 50 self.assertTrue(execution.completed)
49 self.assertFalse(execution.failed) 51 self.assertFalse(execution.failed)
50 self.assertEqual(execution.result_values, (0, 1, 2)) 52 self.assertEqual(execution.result_values, (0, 1, 2))
51 self.assertEqual(execution.result_arguments, {}) 53 self.assertEqual(execution.result_arguments, {})
52 54
53 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')] 55 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')]
54 self.assertEqual(retrieve.mock_calls, expected_calls) 56 self.assertEqual(retrieve.mock_calls, expected_calls)
55 57
56 def testHistogram(self, retrieve): 58 def testHistogram(self, retrieve):
57 retrieve.side_effect = ( 59 retrieve.side_effect = (
58 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 60 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
59 json.dumps({'charts': {'metric': {'test': { 61 json.dumps({'charts': {'metric': {'test': {
60 'type': 'histogram', 62 'type': 'histogram',
61 'buckets': [ 63 'buckets': [
62 {'low': 0, 'count': 2}, 64 {'low': 0, 'count': 2},
63 {'low': 0, 'high': 2, 'count': 3}, 65 {'low': 0, 'high': 2, 'count': 3},
64 ], 66 ],
65 }}}}), 67 }}}}),
66 ) 68 )
67 69
68 execution = read_value.ReadValue('metric', 'test').Start('output hash') 70 quest = read_value.ReadChartJsonValue('metric', 'test')
71 execution = quest.Start('output hash')
69 execution.Poll() 72 execution.Poll()
70 73
71 self.assertEqual(execution.result_values, (0, 0, 1, 1, 1)) 74 self.assertEqual(execution.result_values, (0, 0, 1, 1, 1))
72 75
73 def testHistogramWithLargeSample(self, retrieve): 76 def testHistogramWithLargeSample(self, retrieve):
74 retrieve.side_effect = ( 77 retrieve.side_effect = (
75 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 78 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
76 json.dumps({'charts': {'metric': {'test': { 79 json.dumps({'charts': {'metric': {'test': {
77 'type': 'histogram', 80 'type': 'histogram',
78 'buckets': [ 81 'buckets': [
79 {'low': 0, 'count': 20000}, 82 {'low': 0, 'count': 20000},
80 {'low': 0, 'high': 2, 'count': 30000}, 83 {'low': 0, 'high': 2, 'count': 30000},
81 ], 84 ],
82 }}}}), 85 }}}}),
83 ) 86 )
84 87
85 execution = read_value.ReadValue('metric', 'test').Start('output hash') 88 quest = read_value.ReadChartJsonValue('metric', 'test')
89 execution = quest.Start('output hash')
86 execution.Poll() 90 execution.Poll()
87 91
88 self.assertEqual(execution.result_values, tuple([0] * 4000 + [1] * 6000)) 92 self.assertEqual(execution.result_values, tuple([0] * 4000 + [1] * 6000))
89 93
90 def testScalar(self, retrieve): 94 def testScalar(self, retrieve):
91 retrieve.side_effect = ( 95 retrieve.side_effect = (
92 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 96 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
93 json.dumps({'charts': {'metric': {'test': { 97 json.dumps({'charts': {'metric': {'test': {
94 'type': 'scalar', 98 'type': 'scalar',
95 'value': 2.5, 99 'value': 2.5,
96 }}}}), 100 }}}}),
97 ) 101 )
98 102
99 execution = read_value.ReadValue('metric', 'test').Start('output hash') 103 quest = read_value.ReadChartJsonValue('metric', 'test')
104 execution = quest.Start('output hash')
100 execution.Poll() 105 execution.Poll()
101 106
102 self.assertEqual(execution.result_values, (2.5,)) 107 self.assertEqual(execution.result_values, (2.5,))
OLDNEW
« no previous file with comments | « dashboard/dashboard/pinpoint/models/quest/read_value.py ('k') | dashboard/dashboard/pinpoint/models/quest/run_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698