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

Unified Diff: tools/telemetry/telemetry/results/csv_pivot_table_output_formatter_unittest.py

Issue 631213003: Add CSV export, suitable for use with "pivot tables" in spreadsheets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments (remove unnecessary default param) Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/results/csv_pivot_table_output_formatter_unittest.py
diff --git a/tools/telemetry/telemetry/results/csv_pivot_table_output_formatter_unittest.py b/tools/telemetry/telemetry/results/csv_pivot_table_output_formatter_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..124fab4e6d38e4ab2dbf41580bb6d31432cab78a
--- /dev/null
+++ b/tools/telemetry/telemetry/results/csv_pivot_table_output_formatter_unittest.py
@@ -0,0 +1,92 @@
+# Copyright 2014 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.
+import os
+import StringIO
+import unittest
+
+from telemetry.page import page_set
+from telemetry.results import csv_pivot_table_output_formatter
+from telemetry.results import page_test_results
+from telemetry.value import scalar
+
+
+def _MakePageSet():
+ ps = page_set.PageSet(file_path=os.path.dirname(__file__))
+ ps.AddPageWithDefaultRunNavigate('http://www.foo.com/')
+ ps.AddPageWithDefaultRunNavigate('http://www.bar.com/')
+ return ps
+
+
+class CsvPivotTableOutputFormatterTest(unittest.TestCase):
+
+ # The line separator used by CSV formatter.
+ _LINE_SEPARATOR = '\r\n'
+
+ def setUp(self):
+ self._output = StringIO.StringIO()
+ self._page_set = _MakePageSet()
+ self._results = page_test_results.PageTestResults()
+ self._formatter = None
+ self.MakeFormatter()
+
+ def MakeFormatter(self, trace_tag=''):
+ self._formatter = (
+ csv_pivot_table_output_formatter.CsvPivotTableOutputFormatter(
+ self._output, trace_tag))
+
+ def SimulateBenchmarkRun(self, dict_of_values):
+ """Simulate one run of a benchmark, using the supplied values.
+
+ Args:
+ dict_of_values: dictionary w/ Page instance as key, a list of Values
+ as value.
+ """
+ for page, values in dict_of_values.iteritems():
+ self._results.WillRunPage(page)
+ for v in values:
+ v.page = page
+ self._results.AddValue(v)
+ self._results.DidRunPage(page)
+
+ def Format(self):
+ self._formatter.Format(self._results)
+ return self._output.getvalue()
+
+ def testSimple(self):
+ # Test a simple benchmark with only one value:
+ self.SimulateBenchmarkRun({
+ self._page_set[0]: [scalar.ScalarValue(None, 'foo', 'seconds', 3)]})
+ expected = self._LINE_SEPARATOR.join([
+ 'page_set,page,name,value,units,run_index',
+ 'page_set,http://www.foo.com/,foo,3,seconds,0',
+ ''])
+
+ self.assertEqual(expected, self.Format())
+
+ def testMultiplePagesAndValues(self):
+ self.SimulateBenchmarkRun({
+ self._page_set[0]: [scalar.ScalarValue(None, 'foo', 'seconds', 4)],
+ self._page_set[1]: [scalar.ScalarValue(None, 'foo', 'seconds', 3.4),
+ scalar.ScalarValue(None, 'bar', 'km', 10),
+ scalar.ScalarValue(None, 'baz', 'count', 5)]})
+
+ # Parse CSV output into list of lists.
+ csv_string = self.Format()
+ lines = csv_string.split(self._LINE_SEPARATOR)
+ values = map(lambda s : s.split(','), lines[1:-1])
+
+ self.assertEquals(len(values), 4) # We expect 4 value in total.
+ self.assertEquals(len(set((v[1] for v in values))), 2) # 2 pages.
+ self.assertEquals(len(set((v[2] for v in values))), 3) # 3 value names.
+
+ def testTraceTag(self):
+ self.MakeFormatter(trace_tag='date,option')
+ self.SimulateBenchmarkRun({
+ self._page_set[0]: [scalar.ScalarValue(None, 'foo', 'seconds', 3),
+ scalar.ScalarValue(None, 'bar', 'tons', 5)]})
+ output = self.Format().split(self._LINE_SEPARATOR)
+
+ self.assertTrue(output[0].endswith(',trace_tag_0,trace_tag_1'))
+ for line in output[1:-1]:
+ self.assertTrue(line.endswith(',date,option'))

Powered by Google App Engine
This is Rietveld 408576698