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.
4import os
5import unittest
6
7from telemetry import value
8from telemetry.page import page_set
9from telemetry.value import histogram as histogram_module
10
11class TestBase(unittest.TestCase):
12  def setUp(self):
13    self.page_set =  page_set.PageSet.FromDict({
14      "description": "hello",
15      "archive_path": "foo.wpr",
16      "pages": [
17        {"url": "http://www.bar.com/"},
18        {"url": "http://www.baz.com/"},
19        {"url": "http://www.foo.com/"}
20        ]
21      }, os.path.dirname(__file__))
22
23  @property
24  def pages(self):
25    return self.page_set.pages
26
27class ValueTest(TestBase):
28  def testHistogramBasic(self):
29    page0 = self.pages[0]
30    histogram = histogram_module.HistogramValue(
31        page0, 'x', 'counts',
32        raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}',
33        important=False)
34    self.assertEquals(
35      ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'],
36      histogram.GetBuildbotValue())
37    self.assertEquals(1.5,
38                      histogram.GetRepresentativeNumber())
39    self.assertEquals(
40      ['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'],
41      histogram.GetBuildbotValue())
42
43    self.assertEquals(
44        'unimportant-histogram',
45        histogram.GetBuildbotDataType(value.SUMMARY_RESULT_OUTPUT_CONTEXT))
46    histogram.important = True
47    self.assertEquals(
48        'histogram',
49        histogram.GetBuildbotDataType(value.SUMMARY_RESULT_OUTPUT_CONTEXT))
50