Back to index

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

List of all members.

Public Member Functions

def get_expected_output
def do_profiling
def test_cprofile
def test_calling_conventions

Static Public Attributes

 profilerclass = profile.Profile
list methodnames = ['print_stats', 'print_callers', 'print_callees']
string expected_max_output = ':0(max)'

Detailed Description

Definition at line 14 of file test_profile.py.


Member Function Documentation

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 in test.test_cprofile.CProfileTest.

Definition at line 20 of file test_profile.py.

00020 
00021     def get_expected_output(self):
00022         return _ProfileOutput

Here is the caller 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:

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 in test.test_cprofile.CProfileTest.

Definition at line 18 of file test_profile.py.

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

Definition at line 17 of file test_profile.py.

Reimplemented in test.test_cprofile.CProfileTest.

Definition at line 16 of file test_profile.py.


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