Mercurial > hg
comparison tests/test-util.py @ 39258:331ab85e910b
cleanup: make all uses of timedcm specify what they're timing
It's not used in the timing itself, but it's valuable for the trace
events we emit.
Differential Revision: https://phab.mercurial-scm.org/D4349
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 21 Aug 2018 17:15:51 -0400 |
parents | 9d49bb117dde |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
39257:497effb0a04a | 39258:331ab85e910b |
---|---|
76 self.assertEqual(bytes(stats), util.timecount(12.34)) | 76 self.assertEqual(bytes(stats), util.timecount(12.34)) |
77 | 77 |
78 def testtimedcmcleanexit(self): | 78 def testtimedcmcleanexit(self): |
79 # timestamps 1, 4, elapsed time of 4 - 1 = 3 | 79 # timestamps 1, 4, elapsed time of 4 - 1 = 3 |
80 with mocktimer([1, 3], _start_default): | 80 with mocktimer([1, 3], _start_default): |
81 with util.timedcm() as stats: | 81 with util.timedcm('pass') as stats: |
82 # actual context doesn't matter | 82 # actual context doesn't matter |
83 pass | 83 pass |
84 | 84 |
85 self.assertEqual(stats.start, 1) | 85 self.assertEqual(stats.start, 1) |
86 self.assertEqual(stats.elapsed, 3) | 86 self.assertEqual(stats.elapsed, 3) |
87 self.assertEqual(stats.level, 1) | 87 self.assertEqual(stats.level, 1) |
88 | 88 |
89 def testtimedcmnested(self): | 89 def testtimedcmnested(self): |
90 # timestamps 1, 3, 6, 10, elapsed times of 6 - 3 = 3 and 10 - 1 = 9 | 90 # timestamps 1, 3, 6, 10, elapsed times of 6 - 3 = 3 and 10 - 1 = 9 |
91 with mocktimer([1, 2, 3, 4], _start_default): | 91 with mocktimer([1, 2, 3, 4], _start_default): |
92 with util.timedcm() as outer_stats: | 92 with util.timedcm('outer') as outer_stats: |
93 with util.timedcm() as inner_stats: | 93 with util.timedcm('inner') as inner_stats: |
94 # actual context doesn't matter | 94 # actual context doesn't matter |
95 pass | 95 pass |
96 | 96 |
97 self.assertEqual(outer_stats.start, 1) | 97 self.assertEqual(outer_stats.start, 1) |
98 self.assertEqual(outer_stats.elapsed, 9) | 98 self.assertEqual(outer_stats.elapsed, 9) |
104 | 104 |
105 def testtimedcmexception(self): | 105 def testtimedcmexception(self): |
106 # timestamps 1, 4, elapsed time of 4 - 1 = 3 | 106 # timestamps 1, 4, elapsed time of 4 - 1 = 3 |
107 with mocktimer([1, 3], _start_default): | 107 with mocktimer([1, 3], _start_default): |
108 try: | 108 try: |
109 with util.timedcm() as stats: | 109 with util.timedcm('exceptional') as stats: |
110 raise ValueError() | 110 raise ValueError() |
111 except ValueError: | 111 except ValueError: |
112 pass | 112 pass |
113 | 113 |
114 self.assertEqual(stats.start, 1) | 114 self.assertEqual(stats.start, 1) |