tests: make doctests not depend on str(ParseError()) format
`ParseError` implements `__bytes__`, but it doesn't implement
`__str__`, so it gets the default `__str__` implementation. The next
patch will make it so `ParseError` gets a `__str__` implementation,
which changes the format slightly. This prepares by making us not
depend on the format.
Differential Revision: https://phab.mercurial-scm.org/D9349
--- a/mercurial/revsetlang.py Fri Nov 20 09:17:38 2020 -0800
+++ b/mercurial/revsetlang.py Fri Nov 20 13:24:45 2020 -0800
@@ -558,14 +558,22 @@
>>> _parsewith(b'foo($1)', syminitletters=_aliassyminitletters)
('func', ('symbol', 'foo'), ('symbol', '$1'))
- >>> _parsewith(b'$1')
- Traceback (most recent call last):
- ...
- ParseError: ("syntax error in revset '$1'", 0)
- >>> _parsewith(b'foo bar')
- Traceback (most recent call last):
- ...
- ParseError: ('invalid token', 4)
+ >>> from . import error
+ >>> from . import pycompat
+ >>> try:
+ ... _parsewith(b'$1')
+ ... except error.ParseError as e:
+ ... pycompat.sysstr(e.message)
+ ... e.location
+ "syntax error in revset '$1'"
+ 0
+ >>> try:
+ ... _parsewith(b'foo bar')
+ ... except error.ParseError as e:
+ ... pycompat.sysstr(e.message)
+ ... e.location
+ 'invalid token'
+ 4
"""
if lookup and spec.startswith(b'revset(') and spec.endswith(b')'):
lookup = None
--- a/mercurial/templater.py Fri Nov 20 09:17:38 2020 -0800
+++ b/mercurial/templater.py Fri Nov 20 13:24:45 2020 -0800
@@ -376,14 +376,22 @@
('string', 'foo')
>>> parseexpr(b'foo(bar)')
('func', ('symbol', 'foo'), ('symbol', 'bar'))
- >>> parseexpr(b'foo(')
- Traceback (most recent call last):
- ...
- ParseError: ('not a prefix: end', 4)
- >>> parseexpr(b'"foo" "bar"')
- Traceback (most recent call last):
- ...
- ParseError: ('invalid token', 7)
+ >>> from . import error
+ >>> from . import pycompat
+ >>> try:
+ ... parseexpr(b'foo(')
+ ... except error.ParseError as e:
+ ... pycompat.sysstr(e.message)
+ ... e.location
+ 'not a prefix: end'
+ 4
+ >>> try:
+ ... parseexpr(b'"foo" "bar"')
+ ... except error.ParseError as e:
+ ... pycompat.sysstr(e.message)
+ ... e.location
+ 'invalid token'
+ 7
"""
try:
return _parseexpr(expr)