py3: work around bytes/unicode divergence in parsedate()
authorYuya Nishihara <yuya@tcha.org>
Wed, 27 Sep 2017 19:27:41 +0900
changeset 34363 b76937fafe8a
parent 34362 7508a7dc95c1
child 34364 880e47351d1a
py3: work around bytes/unicode divergence in parsedate()
mercurial/util.py
tests/test-doctest.py
--- a/mercurial/util.py	Wed Sep 27 19:13:43 2017 +0900
+++ b/mercurial/util.py	Wed Sep 27 19:27:41 2017 +0900
@@ -2056,12 +2056,12 @@
     The date may be a "unixtime offset" string or in one of the specified
     formats. If the date already is a (unixtime, offset) tuple, it is returned.
 
-    >>> parsedate(b' today ') == parsedate(\
-                                  datetime.date.today().strftime('%b %d'))
+    >>> parsedate(b' today ') == parsedate(
+    ...     datetime.date.today().strftime('%b %d').encode('ascii'))
     True
-    >>> parsedate(b'yesterday ') == parsedate((datetime.date.today() -\
-                                               datetime.timedelta(days=1)\
-                                              ).strftime('%b %d'))
+    >>> parsedate(b'yesterday ') == parsedate(
+    ...     (datetime.date.today() - datetime.timedelta(days=1)
+    ...      ).strftime('%b %d').encode('ascii'))
     True
     >>> now, tz = makedate()
     >>> strnow, strtz = parsedate(b'now')
@@ -2083,10 +2083,12 @@
     if date == 'now' or date == _('now'):
         return makedate()
     if date == 'today' or date == _('today'):
-        date = datetime.date.today().strftime('%b %d')
+        date = datetime.date.today().strftime(r'%b %d')
+        date = encoding.strtolocal(date)
     elif date == 'yesterday' or date == _('yesterday'):
         date = (datetime.date.today() -
-                datetime.timedelta(days=1)).strftime('%b %d')
+                datetime.timedelta(days=1)).strftime(r'%b %d')
+        date = encoding.strtolocal(date)
 
     try:
         when, offset = map(int, date.split(' '))
--- a/tests/test-doctest.py	Wed Sep 27 19:13:43 2017 +0900
+++ b/tests/test-doctest.py	Wed Sep 27 19:27:41 2017 +0900
@@ -69,7 +69,7 @@
 testmod('mercurial.templater')
 testmod('mercurial.ui')
 testmod('mercurial.url')
-testmod('mercurial.util', py3=False)  # py3: multiple bytes/unicode issues
+testmod('mercurial.util')
 testmod('mercurial.util', testtarget='platform')
 testmod('hgext.convert.convcmd')
 testmod('hgext.convert.cvsps')