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
3 # found in the LICENSE file.
7 from telemetry import value
8 from telemetry.page import page_set
9 from telemetry.value import histogram as histogram_module
12 class TestBase(unittest.TestCase):
14 self.page_set = page_set.PageSet(file_path=os.path.dirname(__file__))
15 self.page_set.AddPageWithDefaultRunNavigate("http://www.bar.com/")
16 self.page_set.AddPageWithDefaultRunNavigate("http://www.baz.com/")
17 self.page_set.AddPageWithDefaultRunNavigate("http://www.foo.com/")
21 return self.page_set.pages
23 class ValueTest(TestBase):
24 def testHistogramBasic(self):
26 histogram = histogram_module.HistogramValue(
28 raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}',
31 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'],
32 histogram.GetBuildbotValue())
33 self.assertEquals(1.5,
34 histogram.GetRepresentativeNumber())
36 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'],
37 histogram.GetBuildbotValue())
40 'unimportant-histogram',
41 histogram.GetBuildbotDataType(value.SUMMARY_RESULT_OUTPUT_CONTEXT))
42 histogram.important = True
45 histogram.GetBuildbotDataType(value.SUMMARY_RESULT_OUTPUT_CONTEXT))
47 def testBucketAsDict(self):
48 bucket = histogram_module.HistogramValueBucket(33, 45, 78)
51 self.assertEquals(d, {
58 histogram = histogram_module.HistogramValue(
60 raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}',
62 d = histogram.AsDictWithoutBaseClassEntries()
64 self.assertEquals(['buckets'], d.keys())
65 self.assertTrue(isinstance(d['buckets'], list))
66 self.assertEquals(len(d['buckets']), 1)
68 def testFromDict(self):
73 'buckets': [{'low': 1, 'high': 2, 'count': 1}]
75 v = value.Value.FromDict(d, {})
77 self.assertTrue(isinstance(v, histogram_module.HistogramValue))
79 ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'],