/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 bzrlib/tests/test_lsprof.py

  • Committer: Martin Pool
  • Date: 2007-06-26 10:15:29 UTC
  • mto: This revision was merged to the branch mainline in revision 2555.
  • Revision ID: mbp@sourcefrog.net-20070626101529-omfq0howuazwtr3s
Remove BzrTestBase alias (little used)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for profiling data collection."""
18
18
 
24
24
from bzrlib import tests
25
25
 
26
26
 
27
 
class _LSProfFeature(tests.Feature):
 
27
class LSProf(tests.Feature):
28
28
 
29
29
    def available(self):
30
30
        try:
35
35
            return True
36
36
 
37
37
 
38
 
LSProfFeature = _LSProfFeature()
39
 
 
40
 
 
41
38
_TXT_HEADER = "   CallCount    Recursive    Total(ms)   " + \
42
39
    "Inline(ms) module:lineno(function)\n"
43
40
 
56
53
 
57
54
class TestStatsSave(tests.TestCaseInTempDir):
58
55
 
59
 
    _test_needs_features = [LSProfFeature]
60
 
 
61
56
    def setUp(self):
 
57
        self.requireFeature(LSProf())
62
58
        super(tests.TestCaseInTempDir, self).setUp()
63
59
        self.stats = _collect_stats()
64
60
 
65
61
    def _tempfile(self, ext):
66
62
        dir = self.test_dir
67
 
        return bzrlib.osutils.pathjoin(dir, "tmp_profile_data." + ext)
 
63
        return os.path.join(dir, "tmp_profile_data." + ext)
68
64
 
69
65
    def test_stats_save_to_txt(self):
70
66
        f = self._tempfile("txt")
77
73
        self.stats.save(f)
78
74
        lines = open(f).readlines()
79
75
        self.assertEqual(lines[0], "events: Ticks\n")
80
 
        f = bzrlib.osutils.pathjoin(self.test_dir, "callgrind.out.foo")
81
 
        self.stats.save(f)
82
 
        lines = open(f).readlines()
83
 
        self.assertEqual(lines[0], "events: Ticks\n")
84
76
        # Test explicit format nommination
85
77
        f2 = self._tempfile("txt")
86
78
        self.stats.save(f2, format="callgrind")
92
84
        self.stats.save(f)
93
85
        data1 = cPickle.load(open(f))
94
86
        self.assertEqual(type(data1), bzrlib.lsprof.Stats)
95
 
 
96
 
 
97
 
class TestBzrProfiler(tests.TestCase):
98
 
 
99
 
    _test_needs_features = [LSProfFeature]
100
 
 
101
 
    def test_start_call_stuff_stop(self):
102
 
        profiler = bzrlib.lsprof.BzrProfiler()
103
 
        profiler.start()
104
 
        try:
105
 
            def a_function():
106
 
                pass
107
 
            a_function()
108
 
        finally:
109
 
            stats = profiler.stop()
110
 
        stats.freeze()
111
 
        lines = [str(data) for data in stats.data]
112
 
        lines = [line for line in lines if 'a_function' in line]
113
 
        self.assertLength(1, lines)