/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_lsprof.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 18:10:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521181028-zn04pdfw0od9hfj3
Rename brzlib => breezy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import cPickle
21
21
import threading
22
22
 
23
 
import brzlib
24
 
from brzlib import errors, tests
25
 
from brzlib.tests import (
 
23
import breezy
 
24
from breezy import errors, tests
 
25
from breezy.tests import (
26
26
    features,
27
27
    )
28
28
 
38
38
 
39
39
def _collect_stats():
40
40
    "Collect and return some dummy profile data."
41
 
    from brzlib.lsprof import profile
 
41
    from breezy.lsprof import profile
42
42
    ret, stats = profile(_junk_callable)
43
43
    return stats
44
44
 
53
53
 
54
54
    def _tempfile(self, ext):
55
55
        dir = self.test_dir
56
 
        return brzlib.osutils.pathjoin(dir, "tmp_profile_data." + ext)
 
56
        return breezy.osutils.pathjoin(dir, "tmp_profile_data." + ext)
57
57
 
58
58
    def test_stats_save_to_txt(self):
59
59
        f = self._tempfile("txt")
66
66
        self.stats.save(f)
67
67
        lines = open(f).readlines()
68
68
        self.assertEqual(lines[0], "events: Ticks\n")
69
 
        f = brzlib.osutils.pathjoin(self.test_dir, "callgrind.out.foo")
 
69
        f = breezy.osutils.pathjoin(self.test_dir, "callgrind.out.foo")
70
70
        self.stats.save(f)
71
71
        lines = open(f).readlines()
72
72
        self.assertEqual(lines[0], "events: Ticks\n")
80
80
        f = self._tempfile("pkl")
81
81
        self.stats.save(f)
82
82
        data1 = cPickle.load(open(f))
83
 
        self.assertEqual(type(data1), brzlib.lsprof.Stats)
 
83
        self.assertEqual(type(data1), breezy.lsprof.Stats)
84
84
 
85
85
 
86
86
class TestBzrProfiler(tests.TestCase):
88
88
    _test_needs_features = [features.lsprof_feature]
89
89
 
90
90
    def test_start_call_stuff_stop(self):
91
 
        profiler = brzlib.lsprof.BzrProfiler()
 
91
        profiler = breezy.lsprof.BzrProfiler()
92
92
        profiler.start()
93
93
        try:
94
94
            def a_function():
103
103
 
104
104
    def test_block_0(self):
105
105
        # When profiler_block is 0, reentrant profile requests fail.
106
 
        self.overrideAttr(brzlib.lsprof.BzrProfiler, 'profiler_block', 0)
 
106
        self.overrideAttr(breezy.lsprof.BzrProfiler, 'profiler_block', 0)
107
107
        inner_calls = []
108
108
        def inner():
109
 
            profiler = brzlib.lsprof.BzrProfiler()
 
109
            profiler = breezy.lsprof.BzrProfiler()
110
110
            self.assertRaises(errors.BzrError, profiler.start)
111
111
            inner_calls.append(True)
112
 
        brzlib.lsprof.profile(inner)
 
112
        breezy.lsprof.profile(inner)
113
113
        self.assertLength(1, inner_calls)
114
114
 
115
115
    def test_block_1(self):
125
125
        def profiled():
126
126
            calls.append('profiled')
127
127
        def do_profile():
128
 
            brzlib.lsprof.profile(profiled)
 
128
            breezy.lsprof.profile(profiled)
129
129
            calls.append('after_profiled')
130
130
        thread = threading.Thread(target=do_profile)
131
 
        brzlib.lsprof.BzrProfiler.profiler_lock.acquire()
 
131
        breezy.lsprof.BzrProfiler.profiler_lock.acquire()
132
132
        try:
133
133
            try:
134
134
                thread.start()
135
135
            finally:
136
 
                brzlib.lsprof.BzrProfiler.profiler_lock.release()
 
136
                breezy.lsprof.BzrProfiler.profiler_lock.release()
137
137
        finally:
138
138
            thread.join()
139
139
        self.assertLength(2, calls)