summaryrefslogtreecommitdiffstats
path: root/Lib/test/libregrtest/utils.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-06-14 12:58:13 (GMT)
committerGitHub <noreply@github.com>2018-06-14 12:58:13 (GMT)
commit4ffe9c2b251f6e027b26250b7a2618e78d4edd22 (patch)
tree513f1108f7b17cfddebda68d49d5e58b47b54397 /Lib/test/libregrtest/utils.py
parentdfa9643d292dcaa14cbf3c44b8330ba2159976c0 (diff)
downloadcpython-4ffe9c2b251f6e027b26250b7a2618e78d4edd22.zip
cpython-4ffe9c2b251f6e027b26250b7a2618e78d4edd22.tar.gz
cpython-4ffe9c2b251f6e027b26250b7a2618e78d4edd22.tar.bz2
bpo-33718: regrtest: use format_duration() to display failed tests (GH-7686)
* Enhance also format_duration(): work on integers and rounds towards +infinity (math.ceil). * Write unit tests on format_duration()
Diffstat (limited to 'Lib/test/libregrtest/utils.py')
-rw-r--r--Lib/test/libregrtest/utils.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py
index 85049cb..d36bf91 100644
--- a/Lib/test/libregrtest/utils.py
+++ b/Lib/test/libregrtest/utils.py
@@ -1,19 +1,28 @@
import os.path
+import math
import textwrap
def format_duration(seconds):
- if seconds < 1.0:
- return '%.0f ms' % (seconds * 1e3)
- if seconds < 60.0:
- return '%.0f sec' % seconds
+ ms = math.ceil(seconds * 1e3)
+ seconds, ms = divmod(ms, 1000)
+ minutes, seconds = divmod(seconds, 60)
+ hours, minutes = divmod(minutes, 60)
- minutes, seconds = divmod(seconds, 60.0)
- hours, minutes = divmod(minutes, 60.0)
+ parts = []
if hours:
- return '%.0f hour %.0f min' % (hours, minutes)
- else:
- return '%.0f min %.0f sec' % (minutes, seconds)
+ parts.append('%s hour' % hours)
+ if minutes:
+ parts.append('%s min' % minutes)
+ if seconds:
+ parts.append('%s sec' % seconds)
+ if ms:
+ parts.append('%s ms' % ms)
+ if not parts:
+ return '0 ms'
+
+ parts = parts[:2]
+ return ' '.join(parts)
def removepy(names):