OLD | NEW |
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 page as page_module | 7 from telemetry import page as page_module |
8 from telemetry import value | 8 from telemetry import value |
9 from telemetry.page import page_set | 9 from telemetry.page import page_set |
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 |
| 12 from telemetry.value import summarizable |
11 | 13 |
12 | 14 |
13 class TestBase(unittest.TestCase): | 15 class TestBase(unittest.TestCase): |
14 def setUp(self): | 16 def setUp(self): |
15 ps = page_set.PageSet(file_path=os.path.dirname(__file__)) | 17 ps = page_set.PageSet(file_path=os.path.dirname(__file__)) |
16 ps.AddUserStory(page_module.Page("http://www.bar.com/", ps, ps.base_dir)) | 18 ps.AddUserStory(page_module.Page("http://www.bar.com/", ps, ps.base_dir)) |
17 ps.AddUserStory(page_module.Page("http://www.baz.com/", ps, ps.base_dir)) | 19 ps.AddUserStory(page_module.Page("http://www.baz.com/", ps, ps.base_dir)) |
18 ps.AddUserStory(page_module.Page("http://www.foo.com/", ps, ps.base_dir)) | 20 ps.AddUserStory(page_module.Page("http://www.foo.com/", ps, ps.base_dir)) |
19 self.page_set = ps | 21 self.page_set = ps |
20 | 22 |
21 @property | 23 @property |
22 def pages(self): | 24 def pages(self): |
23 return self.page_set.pages | 25 return self.page_set.pages |
24 | 26 |
25 class ValueTest(TestBase): | 27 class ValueTest(TestBase): |
26 def testHistogramBasic(self): | 28 def testHistogramBasic(self): |
27 page0 = self.pages[0] | 29 page0 = self.pages[0] |
28 histogram = histogram_module.HistogramValue( | 30 histogram = histogram_module.HistogramValue( |
29 page0, 'x', 'counts', | 31 page0, 'x', 'counts', |
30 raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}', | 32 raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}', |
31 important=False) | 33 important=False, improvement_direction=improvement_direction.UP) |
32 self.assertEquals( | 34 self.assertEquals( |
33 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'], | 35 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'], |
34 histogram.GetBuildbotValue()) | 36 histogram.GetBuildbotValue()) |
35 self.assertEquals(1.5, | 37 self.assertEquals(1.5, |
36 histogram.GetRepresentativeNumber()) | 38 histogram.GetRepresentativeNumber()) |
37 self.assertEquals( | 39 self.assertEquals( |
38 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'], | 40 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'], |
39 histogram.GetBuildbotValue()) | 41 histogram.GetBuildbotValue()) |
40 | 42 |
41 self.assertEquals( | 43 self.assertEquals( |
(...skipping 11 matching lines...) Expand all Loading... |
53 self.assertEquals(d, { | 55 self.assertEquals(d, { |
54 'low': 33, | 56 'low': 33, |
55 'high': 45, | 57 'high': 45, |
56 'count': 78 | 58 'count': 78 |
57 }) | 59 }) |
58 | 60 |
59 def testAsDict(self): | 61 def testAsDict(self): |
60 histogram = histogram_module.HistogramValue( | 62 histogram = histogram_module.HistogramValue( |
61 None, 'x', 'counts', | 63 None, 'x', 'counts', |
62 raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}', | 64 raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}', |
63 important=False) | 65 important=False, improvement_direction=improvement_direction.DOWN) |
64 d = histogram.AsDictWithoutBaseClassEntries() | 66 d = histogram.AsDictWithoutBaseClassEntries() |
65 | 67 |
66 self.assertEquals(['buckets'], d.keys()) | 68 self.assertEquals(['buckets'], d.keys()) |
67 self.assertTrue(isinstance(d['buckets'], list)) | 69 self.assertTrue(isinstance(d['buckets'], list)) |
68 self.assertEquals(len(d['buckets']), 1) | 70 self.assertEquals(len(d['buckets']), 1) |
69 | 71 |
70 def testFromDict(self): | 72 def testFromDict(self): |
71 d = { | 73 d = { |
72 'type': 'histogram', | 74 'type': 'histogram', |
73 'name': 'x', | 75 'name': 'x', |
74 'units': 'counts', | 76 'units': 'counts', |
75 'buckets': [{'low': 1, 'high': 2, 'count': 1}] | 77 'buckets': [{'low': 1, 'high': 2, 'count': 1}], |
| 78 'improvement_direction': 'down', |
76 } | 79 } |
77 v = value.Value.FromDict(d, {}) | 80 v = value.Value.FromDict(d, {}) |
78 | 81 |
79 self.assertTrue(isinstance(v, histogram_module.HistogramValue)) | 82 self.assertTrue(isinstance(v, histogram_module.HistogramValue)) |
80 self.assertEquals( | 83 self.assertEquals( |
81 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'], | 84 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'], |
82 v.GetBuildbotValue()) | 85 v.GetBuildbotValue()) |
| 86 self.assertEquals(improvement_direction.DOWN, v.improvement_direction) |
OLD | NEW |