(cls)
| 33 | |
| 34 | @classmethod |
| 35 | def do_profiling(cls): |
| 36 | results = [] |
| 37 | prof = cls.profilerclass(timer, 0.001) |
| 38 | start_timer = timer() |
| 39 | prof.runctx("testfunc()", globals(), locals()) |
| 40 | results.append(timer() - start_timer) |
| 41 | for methodname in cls.methodnames: |
| 42 | s = StringIO() |
| 43 | stats = pstats.Stats(prof, stream=s) |
| 44 | stats.strip_dirs().sort_stats("stdname") |
| 45 | getattr(stats, methodname)() |
| 46 | output = s.getvalue().splitlines() |
| 47 | mod_name = testfunc.__module__.rsplit('.', 1)[1] |
| 48 | # Only compare against stats originating from the test file. |
| 49 | # Prevents outside code (e.g., the io module) from causing |
| 50 | # unexpected output. |
| 51 | output = [line.rstrip() for line in output if mod_name in line] |
| 52 | results.append('\n'.join(output)) |
| 53 | return results |
| 54 | |
| 55 | def test_cprofile(self): |
| 56 | results = self.do_profiling() |
no test coverage detected