MCPcopy Index your code
hub / github.com/RustPython/RustPython / Example

Class Example

Lib/doctest.py:464–530  ·  view source on GitHub ↗

A single doctest example, consisting of source code and expected output. `Example` defines the following attributes: - source: A single Python statement, always ending with a newline. The constructor adds a newline if needed. - want: The expected output from running t

Source from the content-addressed store, hash-verified

462## includes information about where the string was extracted from.
463
464class Example:
465 """
466 A single doctest example, consisting of source code and expected
467 output. `Example` defines the following attributes:
468
469 - source: A single Python statement, always ending with a newline.
470 The constructor adds a newline if needed.
471
472 - want: The expected output from running the source code (either
473 from stdout, or a traceback in case of exception). `want` ends
474 with a newline unless it's empty, in which case it's an empty
475 string. The constructor adds a newline if needed.
476
477 - exc_msg: The exception message generated by the example, if
478 the example is expected to generate an exception; or `None` if
479 it is not expected to generate an exception. This exception
480 message is compared against the return value of
481 `traceback.format_exception_only()`. `exc_msg` ends with a
482 newline unless it's `None`. The constructor adds a newline
483 if needed.
484
485 - lineno: The line number within the DocTest string containing
486 this Example where the Example begins. This line number is
487 zero-based, with respect to the beginning of the DocTest.
488
489 - indent: The example's indentation in the DocTest string.
490 I.e., the number of space characters that precede the
491 example's first prompt.
492
493 - options: A dictionary mapping from option flags to True or
494 False, which is used to override default options for this
495 example. Any option flags not contained in this dictionary
496 are left at their default value (as specified by the
497 DocTestRunner's optionflags). By default, no options are set.
498 """
499 def __init__(self, source, want, exc_msg=None, lineno=0, indent=0,
500 options=None):
501 # Normalize inputs.
502 if not source.endswith('\n'):
503 source += '\n'
504 if want and not want.endswith('\n'):
505 want += '\n'
506 if exc_msg is not None and not exc_msg.endswith('\n'):
507 exc_msg += '\n'
508 # Store properties.
509 self.source = source
510 self.want = want
511 self.lineno = lineno
512 self.indent = indent
513 if options is None: options = {}
514 self.options = options
515 self.exc_msg = exc_msg
516
517 def __eq__(self, other):
518 if type(self) is not type(other):
519 return NotImplemented
520
521 return self.source == other.source and \

Callers 1

parseMethod · 0.70

Calls

no outgoing calls

Tested by 1

parseMethod · 0.56