Patchwork [06,of,11] doctest: do not embed non-ascii characters in docstring

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 4, 2017, 3:08 p.m.
Message ID <cf6af65e933cb3048568.1504537705@mimosa>
Download mbox | patch
Permalink /patch/23661/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 4, 2017, 3:08 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1504421237 -32400
#      Sun Sep 03 15:47:17 2017 +0900
# Node ID cf6af65e933cb3048568e403ca473eee34351c6b
# Parent  d0acccb529936f589ed988f47812ad4963c6c1f0
doctest: do not embed non-ascii characters in docstring

Since the outer docstring is parsed as a unicode on Python 3, we have to
either double-escape or construct non-ascii string from ascii string.

Patch

diff --git a/mercurial/encoding.py b/mercurial/encoding.py
--- a/mercurial/encoding.py
+++ b/mercurial/encoding.py
@@ -247,6 +247,7 @@  def trim(s, width, ellipsis='', leftside
     If 'leftside' is True, left side of string 's' is trimmed.
     'ellipsis' is always placed at trimmed side.
 
+    >>> from .node import bin
     >>> ellipsis = b'+++'
     >>> from . import encoding
     >>> encoding.encoding = b'utf-8'
@@ -285,7 +286,7 @@  def trim(s, width, ellipsis='', leftside
     +++
     >>> print trim(t, 4, ellipsis=ellipsis, leftside=True)
     +++
-    >>> t = b'\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa' # invalid byte sequence
+    >>> t = bin(b'112233445566778899aa') # invalid byte sequence
     >>> print trim(t, 12, ellipsis=ellipsis)
     \x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa
     >>> print trim(t, 10, ellipsis=ellipsis)
diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -95,7 +95,7 @@  def _buildencodefun():
     >>> dec(b'hello~3aworld~3f')
     'hello:world?'
 
-    >>> enc(b'the\x07quick\xADshot')
+    >>> enc(b'the\\x07quick\\xADshot')
     'the~07quick~adshot'
     >>> dec(b'the~07quick~adshot')
     'the\\x07quick\\xadshot'
@@ -154,7 +154,7 @@  def _buildlowerencodefun():
     'hello'
     >>> f(b'hello:world?')
     'hello~3aworld~3f'
-    >>> f(b'the\x07quick\xADshot')
+    >>> f(b'the\\x07quick\\xADshot')
     'the~07quick~adshot'
     '''
     cmap = dict([(chr(x), chr(x)) for x in xrange(127)])