OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is govered by a BSD-style |
| 3 # license that can be found in the LICENSE file or at |
| 4 # https://developers.google.com/open-source/licenses/bsd |
| 5 |
| 6 """Test for monorail.framework.profiler.""" |
| 7 |
| 8 import unittest |
| 9 |
| 10 from framework import profiler |
| 11 |
| 12 |
| 13 class ProfilerTest(unittest.TestCase): |
| 14 |
| 15 def testTopLevelPhase(self): |
| 16 prof = profiler.Profiler() |
| 17 self.assertEquals(prof.current_phase.name, 'overall profile') |
| 18 self.assertEquals(prof.current_phase.parent, None) |
| 19 self.assertEquals(prof.current_phase, prof.top_phase) |
| 20 self.assertEquals(prof.next_color, 0) |
| 21 |
| 22 def testSinglePhase(self): |
| 23 prof = profiler.Profiler() |
| 24 self.assertEquals(prof.current_phase.name, 'overall profile') |
| 25 with prof.Phase('test'): |
| 26 self.assertEquals(prof.current_phase.name, 'test') |
| 27 self.assertEquals(prof.current_phase.parent.name, 'overall profile') |
| 28 self.assertEquals(prof.current_phase.name, 'overall profile') |
| 29 self.assertEquals(prof.next_color, 1) |
| 30 |
| 31 def testSubphaseExecption(self): |
| 32 prof = profiler.Profiler() |
| 33 try: |
| 34 with prof.Phase('foo'): |
| 35 with prof.Phase('bar'): |
| 36 pass |
| 37 with prof.Phase('baz'): |
| 38 raise Exception('whoops') |
| 39 except Exception as e: |
| 40 self.assertEquals(e.message, 'whoops') |
| 41 finally: |
| 42 self.assertEquals(prof.current_phase.name, 'overall profile') |
| 43 self.assertEquals( |
| 44 prof.top_phase.subphases[0].subphases[1].name, 'baz') |
| 45 |
| 46 |
| 47 if __name__ == '__main__': |
| 48 unittest.main() |
OLD | NEW |