Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.test_cprofile.CProfileTest Class Reference
Inheritance diagram for test.test_cprofile.CProfileTest:
Inheritance graph
[legend]
Collaboration diagram for test.test_cprofile.CProfileTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def get_expected_output
def test_bad_counter_during_dealloc
def do_profiling
def test_cprofile
def test_calling_conventions

Static Public Attributes

 profilerclass = cProfile.Profile
string expected_max_output = "{built-in method max}"
list methodnames = ['print_stats', 'print_callers', 'print_callees']

Detailed Description

Definition at line 10 of file test_cprofile.py.


Member Function Documentation

def test.test_profile.ProfileTest.do_profiling (   cls) [inherited]

Definition at line 24 of file test_profile.py.

00024 
00025     def do_profiling(cls):
00026         results = []
00027         prof = cls.profilerclass(timer, 0.001)
00028         start_timer = timer()
00029         prof.runctx("testfunc()", globals(), locals())
00030         results.append(timer() - start_timer)
00031         for methodname in cls.methodnames:
00032             s = StringIO()
00033             stats = pstats.Stats(prof, stream=s)
00034             stats.strip_dirs().sort_stats("stdname")
00035             getattr(stats, methodname)()
00036             output = s.getvalue().splitlines()
00037             mod_name = testfunc.__module__.rsplit('.', 1)[1]
00038             # Only compare against stats originating from the test file.
00039             # Prevents outside code (e.g., the io module) from causing
00040             # unexpected output.
00041             output = [line.rstrip() for line in output if mod_name in line]
00042             results.append('\n'.join(output))
00043         return results

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from test.test_profile.ProfileTest.

Definition at line 14 of file test_cprofile.py.

00014 
00015     def get_expected_output(self):
00016         return _ProfileOutput

Here is the caller graph for this function:

Definition at line 18 of file test_cprofile.py.

00018 
00019     def test_bad_counter_during_dealloc(self):
00020         import _lsprof
00021         # Must use a file as StringIO doesn't trigger the bug.
00022         with open(TESTFN, 'w') as file:
00023             sys.stderr = file
00024             try:
00025                 obj = _lsprof.Profiler(lambda: int)
00026                 obj.enable()
00027                 obj = _lsprof.Profiler(1)
00028                 obj.disable()
00029             finally:
00030                 sys.stderr = sys.__stderr__
00031         unlink(TESTFN)
00032 

Here is the call graph for this function:

Definition at line 56 of file test_profile.py.

00056 
00057     def test_calling_conventions(self):
00058         # Issue #5330: profile and cProfile wouldn't report C functions called
00059         # with keyword arguments. We test all calling conventions.
00060         stmts = [
00061             "max([0])",
00062             "max([0], key=int)",
00063             "max([0], **dict(key=int))",
00064             "max(*([0],))",
00065             "max(*([0],), key=int)",
00066             "max(*([0],), **dict(key=int))",
00067         ]
00068         for stmt in stmts:
00069             s = StringIO()
00070             prof = self.profilerclass(timer, 0.001)
00071             prof.runctx(stmt, globals(), locals())
00072             stats = pstats.Stats(prof, stream=s)
00073             stats.print_stats()
00074             res = s.getvalue()
00075             self.assertIn(self.expected_max_output, res,
00076                 "Profiling {0!r} didn't report max:\n{1}".format(stmt, res))
00077 

Here is the call graph for this function:

def test.test_profile.ProfileTest.test_cprofile (   self) [inherited]

Definition at line 44 of file test_profile.py.

00044 
00045     def test_cprofile(self):
00046         results = self.do_profiling()
00047         expected = self.get_expected_output()
00048         self.assertEqual(results[0], 1000)
00049         for i, method in enumerate(self.methodnames):
00050             if results[i+1] != expected[method]:
00051                 print("Stats.%s output for %s doesn't fit expectation!" %
00052                       (method, self.profilerclass.__name__))
00053                 print('\n'.join(unified_diff(
00054                                   results[i+1].split('\n'),
00055                                   expected[method].split('\n'))))

Here is the call graph for this function:


Member Data Documentation

Reimplemented from test.test_profile.ProfileTest.

Definition at line 12 of file test_cprofile.py.

list test.test_profile.ProfileTest.methodnames = ['print_stats', 'print_callers', 'print_callees'] [static, inherited]

Definition at line 17 of file test_profile.py.

Reimplemented from test.test_profile.ProfileTest.

Definition at line 11 of file test_cprofile.py.


The documentation for this class was generated from the following file: