Chromium Code Reviews| Index: mojo/devtools/common/devtoolslib/perf_dashboard_unittest.py |
| diff --git a/mojo/devtools/common/devtoolslib/perf_dashboard_unittest.py b/mojo/devtools/common/devtoolslib/perf_dashboard_unittest.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..09f37d4748ba26d88fe151d1b0d74413c4864899 |
| --- /dev/null |
| +++ b/mojo/devtools/common/devtoolslib/perf_dashboard_unittest.py |
| @@ -0,0 +1,64 @@ |
| +# Copyright 2015 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Tests for the Chromium Performance Dashboard data format implementation.""" |
| + |
| +import imp |
| +import json |
| +import os.path |
| +import sys |
| +import unittest |
| + |
| +try: |
| + imp.find_module("devtoolslib") |
| +except ImportError: |
| + sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| + |
| +from devtoolslib.perf_dashboard import ChartDataRecorder |
| + |
| +class ChartDataRecorderTest(unittest.TestCase): |
| + """Tests the chart data recorder.""" |
| + |
| + def test_empty(self): |
| + """Tests chart data with no charts.""" |
| + recorder = ChartDataRecorder() |
| + result = json.loads(recorder.get_json()) |
| + self.assertEquals(0, len(result)) |
| + |
| + def test_one_chart(self): |
| + """Tests chart data with two samples in one chart.""" |
| + recorder = ChartDataRecorder() |
| + recorder.record_scalar('chart', 'val1', 'ms', 1) |
| + recorder.record_scalar('chart', 'val2', 'ms', 2) |
| + |
| + result = json.loads(recorder.get_json()) |
| + self.assertEquals(1, len(result)) |
|
viettrungluu
2015/10/15 22:32:56
This seems like a very long-winded way to test the
ppi
2015/10/15 23:13:14
Done.
|
| + self.assertEquals(2, len(result['chart'])) |
| + self.assertEquals('scalar', result['chart'][0]['type']) |
| + self.assertEquals('val1', result['chart'][0]['name']) |
| + self.assertEquals('ms', result['chart'][0]['units']) |
| + self.assertEquals(1, result['chart'][0]['value']) |
| + self.assertEquals('scalar', result['chart'][1]['type']) |
| + self.assertEquals('val2', result['chart'][1]['name']) |
| + self.assertEquals('ms', result['chart'][1]['units']) |
| + self.assertEquals(2, result['chart'][1]['value']) |
| + |
| + def test_two_charts(self): |
| + """Tests chart data with two samples over two charts.""" |
| + recorder = ChartDataRecorder() |
| + recorder.record_scalar('chart1', 'val1', 'ms', 1) |
| + recorder.record_scalar('chart2', 'val2', 'ms', 2) |
| + |
| + result = json.loads(recorder.get_json()) |
| + self.assertEquals(2, len(result)) |
| + self.assertEquals(1, len(result['chart1'])) |
| + self.assertEquals(1, len(result['chart2'])) |
| + self.assertEquals('scalar', result['chart1'][0]['type']) |
| + self.assertEquals('val1', result['chart1'][0]['name']) |
| + self.assertEquals('ms', result['chart1'][0]['units']) |
| + self.assertEquals(1, result['chart1'][0]['value']) |
| + self.assertEquals('scalar', result['chart2'][0]['type']) |
| + self.assertEquals('val2', result['chart2'][0]['name']) |
| + self.assertEquals('ms', result['chart2'][0]['units']) |
| + self.assertEquals(2, result['chart2'][0]['value']) |