Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 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. | |
| 4 | |
| 5 """Tests for the Chromium Performance Dashboard data format implementation.""" | |
| 6 | |
| 7 import imp | |
| 8 import json | |
| 9 import os.path | |
| 10 import sys | |
| 11 import unittest | |
| 12 | |
| 13 try: | |
| 14 imp.find_module("devtoolslib") | |
| 15 except ImportError: | |
| 16 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| 17 | |
| 18 from devtoolslib.perf_dashboard import ChartDataRecorder | |
| 19 | |
| 20 class ChartDataRecorderTest(unittest.TestCase): | |
| 21 """Tests the chart data recorder.""" | |
| 22 | |
| 23 def test_empty(self): | |
| 24 """Tests chart data with no charts.""" | |
| 25 recorder = ChartDataRecorder() | |
| 26 result = json.loads(recorder.get_json()) | |
| 27 self.assertEquals(0, len(result)) | |
| 28 | |
| 29 def test_one_chart(self): | |
| 30 """Tests chart data with two samples in one chart.""" | |
| 31 recorder = ChartDataRecorder() | |
| 32 recorder.record_scalar('chart', 'val1', 'ms', 1) | |
| 33 recorder.record_scalar('chart', 'val2', 'ms', 2) | |
| 34 | |
| 35 result = json.loads(recorder.get_json()) | |
| 36 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.
| |
| 37 self.assertEquals(2, len(result['chart'])) | |
| 38 self.assertEquals('scalar', result['chart'][0]['type']) | |
| 39 self.assertEquals('val1', result['chart'][0]['name']) | |
| 40 self.assertEquals('ms', result['chart'][0]['units']) | |
| 41 self.assertEquals(1, result['chart'][0]['value']) | |
| 42 self.assertEquals('scalar', result['chart'][1]['type']) | |
| 43 self.assertEquals('val2', result['chart'][1]['name']) | |
| 44 self.assertEquals('ms', result['chart'][1]['units']) | |
| 45 self.assertEquals(2, result['chart'][1]['value']) | |
| 46 | |
| 47 def test_two_charts(self): | |
| 48 """Tests chart data with two samples over two charts.""" | |
| 49 recorder = ChartDataRecorder() | |
| 50 recorder.record_scalar('chart1', 'val1', 'ms', 1) | |
| 51 recorder.record_scalar('chart2', 'val2', 'ms', 2) | |
| 52 | |
| 53 result = json.loads(recorder.get_json()) | |
| 54 self.assertEquals(2, len(result)) | |
| 55 self.assertEquals(1, len(result['chart1'])) | |
| 56 self.assertEquals(1, len(result['chart2'])) | |
| 57 self.assertEquals('scalar', result['chart1'][0]['type']) | |
| 58 self.assertEquals('val1', result['chart1'][0]['name']) | |
| 59 self.assertEquals('ms', result['chart1'][0]['units']) | |
| 60 self.assertEquals(1, result['chart1'][0]['value']) | |
| 61 self.assertEquals('scalar', result['chart2'][0]['type']) | |
| 62 self.assertEquals('val2', result['chart2'][0]['name']) | |
| 63 self.assertEquals('ms', result['chart2'][0]['units']) | |
| 64 self.assertEquals(2, result['chart2'][0]['value']) | |
| OLD | NEW |