comparison mercurial/revsetlang.py @ 45886:18489e26d9a0

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
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 20 Nov 2020 13:24:45 -0800
parents 0fc8b066928a
children 89a2afe31e82
comparison
equal deleted inserted replaced
45885:600aec73f309 45886:18489e26d9a0
556 def _parsewith(spec, lookup=None, syminitletters=None): 556 def _parsewith(spec, lookup=None, syminitletters=None):
557 """Generate a parse tree of given spec with given tokenizing options 557 """Generate a parse tree of given spec with given tokenizing options
558 558
559 >>> _parsewith(b'foo($1)', syminitletters=_aliassyminitletters) 559 >>> _parsewith(b'foo($1)', syminitletters=_aliassyminitletters)
560 ('func', ('symbol', 'foo'), ('symbol', '$1')) 560 ('func', ('symbol', 'foo'), ('symbol', '$1'))
561 >>> _parsewith(b'$1') 561 >>> from . import error
562 Traceback (most recent call last): 562 >>> from . import pycompat
563 ... 563 >>> try:
564 ParseError: ("syntax error in revset '$1'", 0) 564 ... _parsewith(b'$1')
565 >>> _parsewith(b'foo bar') 565 ... except error.ParseError as e:
566 Traceback (most recent call last): 566 ... pycompat.sysstr(e.message)
567 ... 567 ... e.location
568 ParseError: ('invalid token', 4) 568 "syntax error in revset '$1'"
569 0
570 >>> try:
571 ... _parsewith(b'foo bar')
572 ... except error.ParseError as e:
573 ... pycompat.sysstr(e.message)
574 ... e.location
575 'invalid token'
576 4
569 """ 577 """
570 if lookup and spec.startswith(b'revset(') and spec.endswith(b')'): 578 if lookup and spec.startswith(b'revset(') and spec.endswith(b')'):
571 lookup = None 579 lookup = None
572 p = parser.parser(elements) 580 p = parser.parser(elements)
573 tree, pos = p.parse( 581 tree, pos = p.parse(