Skip to content
Snippets Groups Projects
Commit fdd1f2667336 authored by Marcin Kasperski's avatar Marcin Kasperski
Browse files

Workaround for some subtle doctest <-> mercurial incompatibility (py3, hg >=...

Workaround for some subtle doctest <-> mercurial incompatibility (py3, hg >= 5.5). Impacts only tests.
parent 2e7eebc335d5
No related branches found
No related tags found
Loading
1.5.2
~~~~~~~~~~~~
Fixed various incompatibilities with Mercurial 6.0 (without
dropping support for older versions). Tested against hg 6.0
and various late 5.*.
Fixed test failures for mercurial ≥ 5.5 (some doctest <-> mercurial
incompatibility). No impact for actual code.
Officially tested for mercurials 5.5, … , 6.0.
1.5.1
~~~~~~~~~~~~
......
import doctest
import sys
orig_stdout = sys.stdout
sys.stdout = doctest._SpoofOut()
class FakeBuffer:
def __init__(self, ioobj):
self._ioobj = ioobj
def write(self, *args, **kwargs):
# Typowo jestesmy wołani z memoryview, to nie jest obsługiwane
args = tuple(
item.tobytes().decode() if isinstance(item, memoryview) else item
for item in args)
# sys.stderr.write(repr(args))
# sys.stderr.write(repr(kwargs))
return self._ioobj.write(*args, **kwargs)
# There is an error with high characters, byte vs char len.
doctest._SpoofOut.buffer = property(lambda self: FakeBuffer(self))
from mercurial.ui import ui
uio = ui()
uio.write(b"Hej")
uio.write(b"Kup sobie klej")
uio.write(u"Żółw".encode('utf-8')) # somewhat breaks
orig_stdout.write("Aggregated data:\n")
orig_stdout.write(sys.stdout.getvalue())
......@@ -11,6 +11,37 @@
USING_PY3 = sys.version_info >= (3, 0, 0)
# There is strange problem with py3 mercurials ≥ 5.5: doctests
# crash with
#
# Failed example:
# import mercurial.ui; uio = mercurial.ui.ui()
# …
# File "…/site-packages/mercurial/utils/procutil.py", line 147, in <module>
# stdout = _make_write_all(sys.stdout.buffer)
# AttributeError: '_SpoofOut' object has no attribute 'buffer'
#
# This can be tested separately with
# import doctest
# import sys
# sys.stdout = doctest._SpoofOut()
# from mercurial.ui import ui # crashes
#
# and is cause by doctest submitting fake object as sys.stdout. Not sure who
# is guilty, but this .buffer is to know how to .write(…), so let's tech def __iter__(self):
if USING_PY3:
if not hasattr(doctest._SpoofOut, 'buffer'):
class FakeBuffer:
def __init__(self, ioobj):
self._ioobj = ioobj
def write(self, *args, **kwargs):
args = tuple(
item.tobytes().decode() if isinstance(item, memoryview) else item
for item in args)
return self._ioobj.write(*args, **kwargs)
doctest._SpoofOut.buffer = property(lambda self: FakeBuffer(self))
# IMPORTANT NOTE:
#
# As I wanted doctests to be readable, most of them assume
......
......@@ -23,6 +23,7 @@
py36: python3.6
py37: python3.7
py38: python3.8
py39: python3.9
deps =
py26: unittest2
hg27: Mercurial>=2.7,<2.8
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment