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

Side by Side Diff: tools/telemetry/telemetry/value/histogram_unittest.py

Issue 1313243003: [Telemetry] Introduce SummarizableValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 import os 4 import os
5 import unittest 5 import unittest
6 6
7 from telemetry import story 7 from telemetry import story
8 from telemetry import page as page_module 8 from telemetry import page as page_module
9 from telemetry import value 9 from telemetry import value
10 from telemetry.value import histogram as histogram_module 10 from telemetry.value import histogram as histogram_module
11 from telemetry.value import improvement_direction
11 12
12 13
13 class TestBase(unittest.TestCase): 14 class TestBase(unittest.TestCase):
14 def setUp(self): 15 def setUp(self):
15 story_set = story.StorySet(base_dir=os.path.dirname(__file__)) 16 story_set = story.StorySet(base_dir=os.path.dirname(__file__))
16 story_set.AddStory( 17 story_set.AddStory(
17 page_module.Page("http://www.bar.com/", story_set, story_set.base_dir)) 18 page_module.Page("http://www.bar.com/", story_set, story_set.base_dir))
18 story_set.AddStory( 19 story_set.AddStory(
19 page_module.Page("http://www.baz.com/", story_set, story_set.base_dir)) 20 page_module.Page("http://www.baz.com/", story_set, story_set.base_dir))
20 story_set.AddStory( 21 story_set.AddStory(
21 page_module.Page("http://www.foo.com/", story_set, story_set.base_dir)) 22 page_module.Page("http://www.foo.com/", story_set, story_set.base_dir))
22 self.story_set = story_set 23 self.story_set = story_set
23 24
24 @property 25 @property
25 def pages(self): 26 def pages(self):
26 return self.story_set.stories 27 return self.story_set.stories
27 28
28 class ValueTest(TestBase): 29 class ValueTest(TestBase):
29 def testHistogramBasic(self): 30 def testHistogramBasic(self):
30 page0 = self.pages[0] 31 page0 = self.pages[0]
31 histogram = histogram_module.HistogramValue( 32 histogram = histogram_module.HistogramValue(
32 page0, 'x', 'counts', 33 page0, 'x', 'counts',
33 raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}', 34 raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}',
34 important=False) 35 important=False, improvement_direction=improvement_direction.UP)
35 self.assertEquals( 36 self.assertEquals(
36 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'], 37 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'],
37 histogram.GetBuildbotValue()) 38 histogram.GetBuildbotValue())
38 self.assertEquals(1.5, 39 self.assertEquals(1.5,
39 histogram.GetRepresentativeNumber()) 40 histogram.GetRepresentativeNumber())
40 self.assertEquals( 41 self.assertEquals(
41 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'], 42 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'],
42 histogram.GetBuildbotValue()) 43 histogram.GetBuildbotValue())
43 44
44 self.assertEquals( 45 self.assertEquals(
(...skipping 11 matching lines...) Expand all
56 self.assertEquals(d, { 57 self.assertEquals(d, {
57 'low': 33, 58 'low': 33,
58 'high': 45, 59 'high': 45,
59 'count': 78 60 'count': 78
60 }) 61 })
61 62
62 def testAsDict(self): 63 def testAsDict(self):
63 histogram = histogram_module.HistogramValue( 64 histogram = histogram_module.HistogramValue(
64 None, 'x', 'counts', 65 None, 'x', 'counts',
65 raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}', 66 raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}',
66 important=False) 67 important=False, improvement_direction=improvement_direction.DOWN)
67 d = histogram.AsDictWithoutBaseClassEntries() 68 d = histogram.AsDictWithoutBaseClassEntries()
68 69
69 self.assertEquals(['buckets'], d.keys()) 70 self.assertEquals(['buckets'], d.keys())
70 self.assertTrue(isinstance(d['buckets'], list)) 71 self.assertTrue(isinstance(d['buckets'], list))
71 self.assertEquals(len(d['buckets']), 1) 72 self.assertEquals(len(d['buckets']), 1)
72 73
73 def testFromDict(self): 74 def testFromDict(self):
74 d = { 75 d = {
75 'type': 'histogram', 76 'type': 'histogram',
76 'name': 'x', 77 'name': 'x',
77 'units': 'counts', 78 'units': 'counts',
78 'buckets': [{'low': 1, 'high': 2, 'count': 1}] 79 'buckets': [{'low': 1, 'high': 2, 'count': 1}],
80 'improvement_direction': 'down',
79 } 81 }
80 v = value.Value.FromDict(d, {}) 82 v = value.Value.FromDict(d, {})
81 83
82 self.assertTrue(isinstance(v, histogram_module.HistogramValue)) 84 self.assertTrue(isinstance(v, histogram_module.HistogramValue))
83 self.assertEquals( 85 self.assertEquals(
84 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'], 86 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'],
85 v.GetBuildbotValue()) 87 v.GetBuildbotValue())
88 self.assertEquals(improvement_direction.DOWN, v.improvement_direction)
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/value/histogram.py ('k') | tools/telemetry/telemetry/value/improvement_direction.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698