| Index: tools/telemetry/telemetry/results/json_output_formatter_unittest.py
|
| diff --git a/tools/telemetry/telemetry/results/json_output_formatter_unittest.py b/tools/telemetry/telemetry/results/json_output_formatter_unittest.py
|
| index 8c5af58e07ecb990163c90fb75e3caaae640911e..34cf29fa741b554388168c51fc64a8772d563f9e 100644
|
| --- a/tools/telemetry/telemetry/results/json_output_formatter_unittest.py
|
| +++ b/tools/telemetry/telemetry/results/json_output_formatter_unittest.py
|
| @@ -25,12 +25,16 @@ def _HasPage(pages, page):
|
| def _HasValueNamed(values, name):
|
| return len([x for x in values if x['name'] == name]) == 1
|
|
|
| +def _NormalizePath(path):
|
| + return os.path.normcase(os.path.realpath(path))
|
| +
|
| class JsonOutputFormatterTest(unittest.TestCase):
|
| def setUp(self):
|
| self._output = StringIO.StringIO()
|
| self._page_set = _MakePageSet()
|
| - self._formatter = json_output_formatter.JsonOutputFormatter(self._output,
|
| - benchmark.BenchmarkMetadata('benchmark_name'))
|
| + self._paths = ['trace.html', 'foo.txt']
|
| + self._formatter = json_output_formatter.JsonOutputFormatter(
|
| + self._output, benchmark.BenchmarkMetadata('benchmark_name'))
|
|
|
| def testOutputAndParse(self):
|
| results = page_test_results.PageTestResults()
|
| @@ -38,7 +42,7 @@ class JsonOutputFormatterTest(unittest.TestCase):
|
| self._output.truncate(0)
|
|
|
| results.WillRunPage(self._page_set[0])
|
| - v0 = scalar.ScalarValue(results.current_page, 'foo', 'seconds', 3)
|
| + v0 = scalar.ScalarValue(self._page_set[0], 'foo', 'seconds', 3)
|
| results.AddValue(v0)
|
| results.DidRunPage(self._page_set[0])
|
|
|
| @@ -48,7 +52,7 @@ class JsonOutputFormatterTest(unittest.TestCase):
|
| def testAsDictBaseKeys(self):
|
| results = page_test_results.PageTestResults()
|
| d = json_output_formatter.ResultsAsDict(results,
|
| - self._formatter.benchmark_metadata)
|
| + self._formatter.benchmark_metadata)
|
|
|
| self.assertEquals(d['format_version'], '0.2')
|
| self.assertEquals(d['benchmark_name'], 'benchmark_name')
|
| @@ -56,12 +60,12 @@ class JsonOutputFormatterTest(unittest.TestCase):
|
| def testAsDictWithOnePage(self):
|
| results = page_test_results.PageTestResults()
|
| results.WillRunPage(self._page_set[0])
|
| - v0 = scalar.ScalarValue(results.current_page, 'foo', 'seconds', 3)
|
| + v0 = scalar.ScalarValue(self._page_set[0], 'foo', 'seconds', 3)
|
| results.AddValue(v0)
|
| results.DidRunPage(self._page_set[0])
|
|
|
| d = json_output_formatter.ResultsAsDict(results,
|
| - self._formatter.benchmark_metadata)
|
| + self._formatter.benchmark_metadata)
|
|
|
| self.assertTrue(_HasPage(d['pages'], self._page_set[0]))
|
| self.assertTrue(_HasValueNamed(d['per_page_values'], 'foo'))
|
| @@ -69,30 +73,53 @@ class JsonOutputFormatterTest(unittest.TestCase):
|
| def testAsDictWithTwoPages(self):
|
| results = page_test_results.PageTestResults()
|
| results.WillRunPage(self._page_set[0])
|
| - v0 = scalar.ScalarValue(results.current_page, 'foo', 'seconds', 3)
|
| + v0 = scalar.ScalarValue(self._page_set[0], 'foo', 'seconds', 3)
|
| results.AddValue(v0)
|
| results.DidRunPage(self._page_set[0])
|
|
|
| results.WillRunPage(self._page_set[1])
|
| - v1 = scalar.ScalarValue(results.current_page, 'bar', 'seconds', 4)
|
| + v1 = scalar.ScalarValue(self._page_set[1], 'bar', 'seconds', 4)
|
| results.AddValue(v1)
|
| results.DidRunPage(self._page_set[1])
|
|
|
| d = json_output_formatter.ResultsAsDict(results,
|
| - self._formatter.benchmark_metadata)
|
| + self._formatter.benchmark_metadata)
|
|
|
| self.assertTrue(_HasPage(d['pages'], self._page_set[0]))
|
| self.assertTrue(_HasPage(d['pages'], self._page_set[1]))
|
| self.assertTrue(_HasValueNamed(d['per_page_values'], 'foo'))
|
| self.assertTrue(_HasValueNamed(d['per_page_values'], 'bar'))
|
|
|
| + def testAsDictWithFile(self):
|
| + results = page_test_results.PageTestResults()
|
| + file0 = self._paths[0]
|
| + v = scalar.ScalarValue(None, 'foo', 'seconds', 3, paths=[file0])
|
| + results.AddSummaryValue(v)
|
| +
|
| + d = json_output_formatter.ResultsAsDict(results,
|
| + self._formatter.benchmark_metadata)
|
| + f0_id = d['summary_values'][0]['paths'][0]
|
| + absolute_path = _NormalizePath('trace.html')
|
| +
|
| + self.assertEquals(d['paths'][f0_id], absolute_path)
|
| +
|
| + def testAsDictWithoutFile(self):
|
| + results = page_test_results.PageTestResults()
|
| + v = scalar.ScalarValue(None, 'foo', 'seconds', 3)
|
| + results.AddSummaryValue(v)
|
| +
|
| + d = json_output_formatter.ResultsAsDict(results,
|
| + self._formatter.benchmark_metadata)
|
| +
|
| + self.assertNotIn('paths', d)
|
| +
|
| def testAsDictWithSummaryValueOnly(self):
|
| results = page_test_results.PageTestResults()
|
| v = scalar.ScalarValue(None, 'baz', 'seconds', 5)
|
| results.AddSummaryValue(v)
|
|
|
| d = json_output_formatter.ResultsAsDict(results,
|
| - self._formatter.benchmark_metadata)
|
| + self._formatter.benchmark_metadata)
|
|
|
| self.assertFalse(d['pages'])
|
| self.assertTrue(_HasValueNamed(d['summary_values'], 'baz'))
|
|
|