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
3 # found in the LICENSE file.
9 from profile_chrome
import trace_packager
12 class TracePackagerTest(unittest
.TestCase
):
13 def testJsonTraceMerging(self
):
14 t1
= {'traceEvents': [{'ts': 123, 'ph': 'b'}]}
15 t2
= {'traceEvents': [], 'stackFrames': ['blah']}
17 # Both trace files will be merged to a third file and will get deleted in
18 # the process, so there's no need for NamedTemporaryFile to do the
20 with tempfile
.NamedTemporaryFile(delete
=False) as f1
, \
21 tempfile
.NamedTemporaryFile(delete
=False) as f2
:
22 f1
.write(json
.dumps(t1
))
23 f2
.write(json
.dumps(t2
))
27 with tempfile
.NamedTemporaryFile() as output
:
28 trace_packager
.PackageTraces([f1
.name
, f2
.name
],
32 with
open(output
.name
) as output
:
33 output
= json
.load(output
)
34 self
.assertEquals(output
['traceEvents'], t1
['traceEvents'])
35 self
.assertEquals(output
['stackFrames'], t2
['stackFrames'])