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

Unified Diff: telemetry/telemetry/timeline/trace_data_unittest.py

Issue 2661573003: Refactor TraceData to encapsulate internal traces' representation (Closed)
Patch Set: Address Charlie's comments Created 3 years, 10 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
« no previous file with comments | « telemetry/telemetry/timeline/trace_data.py ('k') | telemetry/telemetry/timeline/trace_event_importer.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: telemetry/telemetry/timeline/trace_data_unittest.py
diff --git a/telemetry/telemetry/timeline/trace_data_unittest.py b/telemetry/telemetry/timeline/trace_data_unittest.py
index 4d057b0bbaf1b32a1ac1203726c24867af296d2b..9ecf668ad4a98235a69fd8ea10d652684a63655d 100644
--- a/telemetry/telemetry/timeline/trace_data_unittest.py
+++ b/telemetry/telemetry/timeline/trace_data_unittest.py
@@ -2,45 +2,29 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import cStringIO
import datetime
import exceptions
-import json
import os
+import shutil
import tempfile
import unittest
-import zipfile
+from tracing_build import html2trace
from telemetry.timeline import trace_data
+
class TraceDataTest(unittest.TestCase):
def testSerialize(self):
- ri = trace_data.CreateTraceDataFromRawData({'traceEvents': [1, 2, 3]})
- f = cStringIO.StringIO()
- ri.Serialize(f)
- d = f.getvalue()
-
- self.assertIn('traceEvents', d)
- self.assertIn('[1, 2, 3]', d)
-
- json.loads(d)
-
- def testSerializeZip(self):
- data = trace_data.CreateTraceDataFromRawData({'traceEvents': [1, 2, 3],
- 'powerTraceAsString': 'battor_data'})
- tf = tempfile.NamedTemporaryFile(delete=False)
- temp_name = tf.name
- tf.close()
+ test_dir = tempfile.mkdtemp()
+ trace_path = os.path.join(test_dir, 'test_trace.json')
try:
- data.Serialize(temp_name, gzip_result=True)
- self.assertTrue(zipfile.is_zipfile(temp_name))
- z = zipfile.ZipFile(temp_name, 'r')
-
- self.assertIn('powerTraceAsString', z.namelist())
- self.assertIn('traceEvents', z.namelist())
- z.close()
+ ri = trace_data.CreateTraceDataFromRawData({'traceEvents': [1, 2, 3]})
+ ri.Serialize(trace_path)
+ with open(trace_path) as f:
+ json_traces = html2trace.ReadTracesFromHTMLFilePath(f)
+ self.assertEqual(json_traces, [{'traceEvents': [1, 2, 3]}])
finally:
- os.remove(temp_name)
+ shutil.rmtree(test_dir)
def testEmptyArrayValue(self):
# We can import empty lists and empty string.
« no previous file with comments | « telemetry/telemetry/timeline/trace_data.py ('k') | telemetry/telemetry/timeline/trace_event_importer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698