|
34 | 34 | TEMPDIR = os.path.abspath(TEMPDIR) |
35 | 35 |
|
36 | 36 |
|
| 37 | +def format_duration(seconds): |
| 38 | + if seconds < 1.0: |
| 39 | + return '%.0f ms' % (seconds * 1e3) |
| 40 | + if seconds < 60.0: |
| 41 | + return '%.0f sec' % seconds |
| 42 | + |
| 43 | + minutes, seconds = divmod(seconds, 60.0) |
| 44 | + return '%.0f min %.0f sec' % (minutes, seconds) |
| 45 | + |
| 46 | + |
37 | 47 | class Regrtest: |
38 | 48 | """Execute a test suite. |
39 | 49 |
|
@@ -107,27 +117,21 @@ def accumulate_result(self, test, result): |
107 | 117 | self.skipped.append(test) |
108 | 118 | self.resource_denieds.append(test) |
109 | 119 |
|
110 | | - def time_delta(self, ceil=False): |
111 | | - seconds = time.monotonic() - self.start_time |
112 | | - if ceil: |
113 | | - seconds = math.ceil(seconds) |
114 | | - else: |
115 | | - seconds = int(seconds) |
116 | | - return datetime.timedelta(seconds=seconds) |
117 | | - |
118 | 120 | def display_progress(self, test_index, test): |
119 | 121 | if self.ns.quiet: |
120 | 122 | return |
121 | 123 | if self.bad and not self.ns.pgo: |
122 | 124 | fmt = "{time} [{test_index:{count_width}}{test_count}/{nbad}] {test_name}" |
123 | 125 | else: |
124 | 126 | fmt = "{time} [{test_index:{count_width}}{test_count}] {test_name}" |
| 127 | + test_time = time.monotonic() - self.start_time |
| 128 | + test_time = datetime.timedelta(seconds=int(test_time)) |
125 | 129 | line = fmt.format(count_width=self.test_count_width, |
126 | 130 | test_index=test_index, |
127 | 131 | test_count=self.test_count, |
128 | 132 | nbad=len(self.bad), |
129 | 133 | test_name=test, |
130 | | - time=self.time_delta()) |
| 134 | + time=test_time) |
131 | 135 | print(line, flush=True) |
132 | 136 |
|
133 | 137 | def parse_args(self, kwargs): |
@@ -286,9 +290,10 @@ def display_result(self): |
286 | 290 |
|
287 | 291 | if self.ns.print_slow: |
288 | 292 | self.test_times.sort(reverse=True) |
| 293 | + print() |
289 | 294 | print("10 slowest tests:") |
290 | 295 | for time, test in self.test_times[:10]: |
291 | | - print("%s: %.1fs" % (test, time)) |
| 296 | + print("- %s: %s" % (test, format_duration(time))) |
292 | 297 |
|
293 | 298 | if self.bad: |
294 | 299 | print(count(len(self.bad), "test"), "failed:") |
@@ -342,7 +347,7 @@ def run_tests_sequential(self): |
342 | 347 | previous_test = format_test_result(test, result[0]) |
343 | 348 | test_time = time.monotonic() - start_time |
344 | 349 | if test_time >= PROGRESS_MIN_TIME: |
345 | | - previous_test = "%s in %.0f sec" % (previous_test, test_time) |
| 350 | + previous_test = "%s in %s" % (previous_test, format_duration(test_time)) |
346 | 351 | elif result[0] == PASSED: |
347 | 352 | # be quiet: say nothing if the test passed shortly |
348 | 353 | previous_test = None |
@@ -418,7 +423,9 @@ def finalize(self): |
418 | 423 | r.write_results(show_missing=True, summary=True, |
419 | 424 | coverdir=self.ns.coverdir) |
420 | 425 |
|
421 | | - print("Total duration: %s" % self.time_delta(ceil=True)) |
| 426 | + print() |
| 427 | + duration = time.monotonic() - self.start_time |
| 428 | + print("Total duration: %s" % format_duration(duration)) |
422 | 429 |
|
423 | 430 | if self.ns.runleaks: |
424 | 431 | os.system("leaks %d" % os.getpid()) |
|
0 commit comments