File tree Expand file tree Collapse file tree 3 files changed +44
-10
lines changed Expand file tree Collapse file tree 3 files changed +44
-10
lines changed Original file line number Diff line number Diff line change @@ -200,7 +200,7 @@ def get_running(workers):
200
200
if (ok not in (CHILD_ERROR , INTERRUPTED )
201
201
and test_time >= PROGRESS_MIN_TIME
202
202
and not regrtest .ns .pgo ):
203
- text += ' (%.0f sec )' % test_time
203
+ text += ' (%s )' % format_duration ( test_time )
204
204
elif ok == CHILD_ERROR :
205
205
text = '%s (%s)' % (text , test_time )
206
206
running = get_running (workers )
Original file line number Diff line number Diff line change 1
1
import os .path
2
+ import math
2
3
import textwrap
3
4
4
5
5
6
def format_duration (seconds ):
6
- if seconds < 1.0 :
7
- return '%.0f ms' % ( seconds * 1e3 )
8
- if seconds < 60.0 :
9
- return '%.0f sec' % seconds
7
+ ms = math . ceil ( seconds * 1e3 )
8
+ seconds , ms = divmod ( ms , 1000 )
9
+ minutes , seconds = divmod ( seconds , 60 )
10
+ hours , minutes = divmod ( minutes , 60 )
10
11
11
- minutes , seconds = divmod (seconds , 60.0 )
12
- hours , minutes = divmod (minutes , 60.0 )
12
+ parts = []
13
13
if hours :
14
- return '%.0f hour %.0f min' % (hours , minutes )
15
- else :
16
- return '%.0f min %.0f sec' % (minutes , seconds )
14
+ parts .append ('%s hour' % hours )
15
+ if minutes :
16
+ parts .append ('%s min' % minutes )
17
+ if seconds :
18
+ parts .append ('%s sec' % seconds )
19
+ if ms :
20
+ parts .append ('%s ms' % ms )
21
+ if not parts :
22
+ return '0 ms'
23
+
24
+ parts = parts [:2 ]
25
+ return ' ' .join (parts )
17
26
18
27
19
28
def removepy (names ):
Original file line number Diff line number Diff line change 19
19
import unittest
20
20
from test import libregrtest
21
21
from test import support
22
+ from test .libregrtest import utils
22
23
23
24
24
25
Py_DEBUG = hasattr (sys , 'getobjects' )
@@ -980,5 +981,29 @@ def test_bug(self):
980
981
failed = testname , rerun = testname )
981
982
982
983
984
+ class TestUtils (unittest .TestCase ):
985
+ def test_format_duration (self ):
986
+ self .assertEqual (utils .format_duration (0 ),
987
+ '0 ms' )
988
+ self .assertEqual (utils .format_duration (1e-9 ),
989
+ '1 ms' )
990
+ self .assertEqual (utils .format_duration (10e-3 ),
991
+ '10 ms' )
992
+ self .assertEqual (utils .format_duration (1.5 ),
993
+ '1 sec 500 ms' )
994
+ self .assertEqual (utils .format_duration (1 ),
995
+ '1 sec' )
996
+ self .assertEqual (utils .format_duration (2 * 60 ),
997
+ '2 min' )
998
+ self .assertEqual (utils .format_duration (2 * 60 + 1 ),
999
+ '2 min 1 sec' )
1000
+ self .assertEqual (utils .format_duration (3 * 3600 ),
1001
+ '3 hour' )
1002
+ self .assertEqual (utils .format_duration (3 * 3600 + 2 * 60 + 1 ),
1003
+ '3 hour 2 min' )
1004
+ self .assertEqual (utils .format_duration (3 * 3600 + 1 ),
1005
+ '3 hour 1 sec' )
1006
+
1007
+
983
1008
if __name__ == '__main__' :
984
1009
unittest .main ()
You can’t perform that action at this time.
0 commit comments