Skip to content

Commit 23092da

Browse files
ferdnycptmcg
authored andcommitted
Doctests for pyparsing.exceptions
1 parent 0bae3cd commit 23092da

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

‎pyparsing/exceptions.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ def explain(self, depth: int = 16) -> str:
239239
Returns a multi-line string listing the ParserElements and/or function names in the
240240
exception's stack trace.
241241
242-
Example::
242+
Example:
243+
244+
.. testcode::
243245
244246
# an expression to parse 3 integers
245247
expr = pp.Word(pp.nums) * 3
@@ -249,11 +251,13 @@ def explain(self, depth: int = 16) -> str:
249251
except pp.ParseException as pe:
250252
print(pe.explain(depth=0))
251253
252-
prints::
254+
prints:
255+
256+
.. testoutput::
253257
254258
123 456 A789
255259
^
256-
ParseException: Expected W:(0-9), found 'A' (at char 8), (line:1, col:9)
260+
ParseException: Expected W:(0-9), found 'A789' (at char 8), (line:1, col:9)
257261
258262
Note: the diagnostic output will include string representations of the expressions
259263
that failed to parse. These representations will be more helpful if you use `set_name` to
@@ -276,15 +280,19 @@ class ParseException(ParseBaseException):
276280
"""
277281
Exception thrown when a parse expression doesn't match the input string
278282
279-
Example::
283+
Example:
284+
285+
.. testcode::
280286
281287
integer = Word(nums).set_name("integer")
282288
try:
283289
integer.parse_string("ABC")
284290
except ParseException as pe:
285291
print(pe, f"column: {pe.column}")
286292
287-
prints::
293+
prints:
294+
295+
.. testoutput::
288296
289297
Expected integer, found 'ABC' (at char 0), (line:1, col:1) column: 1
290298

0 commit comments

Comments
 (0)