~ubuntu-branches/ubuntu/trusty/python3.4/trusty-proposed

« back to all changes in this revision

Viewing changes to Lib/test/test_pstats.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-11-25 09:44:27 UTC
  • Revision ID: package-import@ubuntu.com-20131125094427-lzxj8ap5w01lmo7f
Tags: upstream-3.4~b1
ImportĀ upstreamĀ versionĀ 3.4~b1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import unittest
 
2
from test import support
 
3
from io import StringIO
 
4
import pstats
 
5
 
 
6
 
 
7
 
 
8
class AddCallersTestCase(unittest.TestCase):
 
9
    """Tests for pstats.add_callers helper."""
 
10
 
 
11
    def test_combine_results(self):
 
12
        # pstats.add_callers should combine the call results of both target
 
13
        # and source by adding the call time. See issue1269.
 
14
        # new format: used by the cProfile module
 
15
        target = {"a": (1, 2, 3, 4)}
 
16
        source = {"a": (1, 2, 3, 4), "b": (5, 6, 7, 8)}
 
17
        new_callers = pstats.add_callers(target, source)
 
18
        self.assertEqual(new_callers, {'a': (2, 4, 6, 8), 'b': (5, 6, 7, 8)})
 
19
        # old format: used by the profile module
 
20
        target = {"a": 1}
 
21
        source = {"a": 1, "b": 5}
 
22
        new_callers = pstats.add_callers(target, source)
 
23
        self.assertEqual(new_callers, {'a': 2, 'b': 5})
 
24
 
 
25
 
 
26
class StatsTestCase(unittest.TestCase):
 
27
    def setUp(self):
 
28
        stats_file = support.findfile('pstats.pck')
 
29
        self.stats = pstats.Stats(stats_file)
 
30
 
 
31
    def test_add(self):
 
32
        stream = StringIO()
 
33
        stats = pstats.Stats(stream=stream)
 
34
        stats.add(self.stats, self.stats)
 
35
 
 
36
 
 
37
def test_main():
 
38
    support.run_unittest(
 
39
        AddCallersTestCase,
 
40
        StatsTestCase,
 
41
    )
 
42
 
 
43
 
 
44
if __name__ == "__main__":
 
45
    test_main()