summaryrefslogtreecommitdiff
path: root/Lib/test/libregrtest/utils.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-06-01 19:39:37 +0200
committerGitHub <noreply@github.com>2018-06-01 19:39:37 +0200
commit137e80346ff65ad917f733d9b077e530a4797ec5 (patch)
tree60112c22197521a37c7c5e21d948b1e43508edd6 /Lib/test/libregrtest/utils.py
parentf3297433e309e9591eaa3f36e1d7887e9d0620d7 (diff)
downloadcpython-git-137e80346ff65ad917f733d9b077e530a4797ec5.tar.gz
bpo-33718: Update regrtest from master (GH-7325)
* Add support.environment_altered: unused yet * VSTS: don't run tests with --fail-env-changed
Diffstat (limited to 'Lib/test/libregrtest/utils.py')
-rw-r--r--Lib/test/libregrtest/utils.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py
new file mode 100644
index 0000000000..85049cb06b
--- /dev/null
+++ b/Lib/test/libregrtest/utils.py
@@ -0,0 +1,47 @@
+import os.path
+import textwrap
+
+
+def format_duration(seconds):
+ if seconds < 1.0:
+ return '%.0f ms' % (seconds * 1e3)
+ if seconds < 60.0:
+ return '%.0f sec' % seconds
+
+ minutes, seconds = divmod(seconds, 60.0)
+ hours, minutes = divmod(minutes, 60.0)
+ if hours:
+ return '%.0f hour %.0f min' % (hours, minutes)
+ else:
+ return '%.0f min %.0f sec' % (minutes, seconds)
+
+
+def removepy(names):
+ if not names:
+ return
+ for idx, name in enumerate(names):
+ basename, ext = os.path.splitext(name)
+ if ext == '.py':
+ names[idx] = basename
+
+
+def count(n, word):
+ if n == 1:
+ return "%d %s" % (n, word)
+ else:
+ return "%d %ss" % (n, word)
+
+
+def printlist(x, width=70, indent=4, file=None):
+ """Print the elements of iterable x to stdout.
+
+ Optional arg width (default 70) is the maximum line length.
+ Optional arg indent (default 4) is the number of blanks with which to
+ begin each line.
+ """
+
+ blanks = ' ' * indent
+ # Print the sorted list: 'x' may be a '--random' list or a set()
+ print(textwrap.fill(' '.join(str(elt) for elt in sorted(x)), width,
+ initial_indent=blanks, subsequent_indent=blanks),
+ file=file)