Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: tools/telemetry/telemetry/internal/results/csv_pivot_table_output_formatter_unittest.py

Issue 1313243003: [Telemetry] Introduce SummarizableValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 StringIO 5 import StringIO
6 import unittest 6 import unittest
7 7
8 from telemetry import story 8 from telemetry import story
9 from telemetry.internal.results import csv_pivot_table_output_formatter 9 from telemetry.internal.results import csv_pivot_table_output_formatter
10 from telemetry.internal.results import page_test_results 10 from telemetry.internal.results import page_test_results
11 from telemetry import page as page_module 11 from telemetry import page as page_module
12 from telemetry.value import improvement_direction
12 from telemetry.value import scalar 13 from telemetry.value import scalar
13 14
14 15
15 def _MakeStorySet(): 16 def _MakeStorySet():
16 story_set = story.StorySet(base_dir=os.path.dirname(__file__)) 17 story_set = story.StorySet(base_dir=os.path.dirname(__file__))
17 story_set.AddStory( 18 story_set.AddStory(
18 page_module.Page('http://www.foo.com/', story_set, story_set.base_dir)) 19 page_module.Page('http://www.foo.com/', story_set, story_set.base_dir))
19 story_set.AddStory( 20 story_set.AddStory(
20 page_module.Page('http://www.bar.com/', story_set, story_set.base_dir)) 21 page_module.Page('http://www.bar.com/', story_set, story_set.base_dir))
21 return story_set 22 return story_set
(...skipping 30 matching lines...) Expand all
52 self._results.AddValue(v) 53 self._results.AddValue(v)
53 self._results.DidRunPage(page) 54 self._results.DidRunPage(page)
54 55
55 def Format(self): 56 def Format(self):
56 self._formatter.Format(self._results) 57 self._formatter.Format(self._results)
57 return self._output.getvalue() 58 return self._output.getvalue()
58 59
59 def testSimple(self): 60 def testSimple(self):
60 # Test a simple benchmark with only one value: 61 # Test a simple benchmark with only one value:
61 self.SimulateBenchmarkRun({ 62 self.SimulateBenchmarkRun({
62 self._story_set[0]: [scalar.ScalarValue(None, 'foo', 'seconds', 3)]}) 63 self._story_set[0]: [scalar.ScalarValue(
64 None, 'foo', 'seconds', 3,
65 improvement_direction=improvement_direction.DOWN)]})
63 expected = self._LINE_SEPARATOR.join([ 66 expected = self._LINE_SEPARATOR.join([
64 'story_set,page,name,value,units,run_index', 67 'story_set,page,name,value,units,run_index',
65 'story_set,http://www.foo.com/,foo,3,seconds,0', 68 'story_set,http://www.foo.com/,foo,3,seconds,0',
66 '']) 69 ''])
67 70
68 self.assertEqual(expected, self.Format()) 71 self.assertEqual(expected, self.Format())
69 72
70 def testMultiplePagesAndValues(self): 73 def testMultiplePagesAndValues(self):
71 self.SimulateBenchmarkRun({ 74 self.SimulateBenchmarkRun({
72 self._story_set[0]: [scalar.ScalarValue(None, 'foo', 'seconds', 4)], 75 self._story_set[0]: [
73 self._story_set[1]: [scalar.ScalarValue(None, 'foo', 'seconds', 3.4), 76 scalar.ScalarValue(
74 scalar.ScalarValue(None, 'bar', 'km', 10), 77 None, 'foo', 'seconds', 4,
75 scalar.ScalarValue(None, 'baz', 'count', 5)]}) 78 improvement_direction=improvement_direction.DOWN)],
79 self._story_set[1]: [
80 scalar.ScalarValue(
81 None, 'foo', 'seconds', 3.4,
82 improvement_direction=improvement_direction.DOWN),
83 scalar.ScalarValue(
84 None, 'bar', 'km', 10,
85 improvement_direction=improvement_direction.DOWN),
86 scalar.ScalarValue(
87 None, 'baz', 'count', 5,
88 improvement_direction=improvement_direction.DOWN)]})
76 89
77 # Parse CSV output into list of lists. 90 # Parse CSV output into list of lists.
78 csv_string = self.Format() 91 csv_string = self.Format()
79 lines = csv_string.split(self._LINE_SEPARATOR) 92 lines = csv_string.split(self._LINE_SEPARATOR)
80 values = [s.split(',') for s in lines[1:-1]] 93 values = [s.split(',') for s in lines[1:-1]]
81 94
82 self.assertEquals(len(values), 4) # We expect 4 value in total. 95 self.assertEquals(len(values), 4) # We expect 4 value in total.
83 self.assertEquals(len(set((v[1] for v in values))), 2) # 2 pages. 96 self.assertEquals(len(set((v[1] for v in values))), 2) # 2 pages.
84 self.assertEquals(len(set((v[2] for v in values))), 3) # 3 value names. 97 self.assertEquals(len(set((v[2] for v in values))), 3) # 3 value names.
85 98
86 def testTraceTag(self): 99 def testTraceTag(self):
87 self.MakeFormatter(trace_tag='date,option') 100 self.MakeFormatter(trace_tag='date,option')
88 self.SimulateBenchmarkRun({ 101 self.SimulateBenchmarkRun({
89 self._story_set[0]: [scalar.ScalarValue(None, 'foo', 'seconds', 3), 102 self._story_set[0]: [
90 scalar.ScalarValue(None, 'bar', 'tons', 5)]}) 103 scalar.ScalarValue(
104 None, 'foo', 'seconds', 3,
105 improvement_direction=improvement_direction.DOWN),
106 scalar.ScalarValue(
107 None, 'bar', 'tons', 5,
108 improvement_direction=improvement_direction.DOWN)]})
91 output = self.Format().split(self._LINE_SEPARATOR) 109 output = self.Format().split(self._LINE_SEPARATOR)
92 110
93 self.assertTrue(output[0].endswith(',trace_tag_0,trace_tag_1')) 111 self.assertTrue(output[0].endswith(',trace_tag_0,trace_tag_1'))
94 for line in output[1:-1]: 112 for line in output[1:-1]:
95 self.assertTrue(line.endswith(',date,option')) 113 self.assertTrue(line.endswith(',date,option'))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698