Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / py_trace_event / src / trace_event_impl / log_io_test.py
1 # Copyright 2011 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.
4 import os
5 import sys
6 import tempfile
7 import unittest
8
9
10 from .log import *
11 from .parsed_trace_events import *
12
13 class LogIOTest(unittest.TestCase):
14   def test_enable_with_file(self):
15     file = tempfile.NamedTemporaryFile()
16     trace_enable(open(file.name, 'w+'))
17     trace_disable()
18     e = ParsedTraceEvents(trace_filename = file.name)
19     file.close()
20     self.assertTrue(len(e) > 0)
21
22   def test_enable_with_filename(self):
23     file = tempfile.NamedTemporaryFile()
24     trace_enable(file.name)
25     trace_disable()
26     e = ParsedTraceEvents(trace_filename = file.name)
27     file.close()
28     self.assertTrue(len(e) > 0)
29
30   def test_enable_with_implicit_filename(self):
31     expected_filename = "%s.json" % sys.argv[0]
32     def do_work():
33       file = tempfile.NamedTemporaryFile()
34       trace_enable()
35       trace_disable()
36       e = ParsedTraceEvents(trace_filename = expected_filename)
37       file.close()
38       self.assertTrue(len(e) > 0)
39     try:
40       do_work()
41     finally:
42       if os.path.exists(expected_filename):
43         os.unlink(expected_filename)