[PATCH] util: make new timedcmstats class Python 3 compatible
Martijn Pieters
mj at zopatista.com
Thu Aug 2 19:58:01 UTC 2018
# HG changeset patch
# User Martijn Pieters <mj at zopatista.com>
# Date 1533239583 -3600
# Thu Aug 02 20:53:03 2018 +0100
# Branch stable
# Node ID d7c68ee641ff02542680bdaa4bff95a348db688e
# Parent 07ca3b8354d59c70db5f10448e53d4bbfd50e72e
# EXP-Topic debugextensions
util: make new timedcmstats class Python 3 compatible
diff -r 07ca3b8354d5 -r d7c68ee641ff mercurial/util.py
--- a/mercurial/util.py Wed Aug 01 16:06:53 2018 +0200
+++ b/mercurial/util.py Thu Aug 02 20:53:03 2018 +0100
@@ -2890,9 +2890,11 @@
# the number of nested timedcm context managers.
level = attr.ib(default=1)
- def __str__(self):
+ def __bytes__(self):
return timecount(self.elapsed) if self.elapsed else '<unknown>'
+ __str__ = encoding.strmethod(__bytes__)
+
@contextlib.contextmanager
def timedcm():
"""A context manager that produces timing information for a given context.
@@ -2929,7 +2931,8 @@
result = func(*args, **kwargs)
stderr = procutil.stderr
stderr.write('%s%s: %s\n' % (
- ' ' * time_stats.level * 2, func.__name__, time_stats))
+ ' ' * time_stats.level * 2, pycompat.bytestr(func.__name__),
+ time_stats))
return result
return wrapper
diff -r 07ca3b8354d5 -r d7c68ee641ff tests/test-util.py
--- a/tests/test-util.py Wed Aug 01 16:06:53 2018 +0200
+++ b/tests/test-util.py Thu Aug 02 20:53:03 2018 +0100
@@ -70,8 +70,10 @@
def testtimedcmstatsstr(self):
stats = util.timedcmstats()
self.assertEqual(str(stats), '<unknown>')
+ self.assertEqual(bytes(stats), b'<unknown>')
stats.elapsed = 12.34
- self.assertEqual(str(stats), util.timecount(12.34))
+ self.assertEqual(str(stats), pycompat.sysstr(util.timecount(12.34)))
+ self.assertEqual(bytes(stats), util.timecount(12.34))
def testtimedcmcleanexit(self):
# timestamps 1, 4, elapsed time of 4 - 1 = 3
More information about the Mercurial-devel
mailing list