MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / Example

Class Example

tools/python-3.11.9-amd64/Lib/doctest.py:437–503  ·  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 ru

Source from the content-addressed store, hash-verified

435## includes information about where the string was extracted from.
436
437class Example:
438 """
439 A single doctest example, consisting of source code and expected
440 output. `Example` defines the following attributes:
441
442 - source: A single Python statement, always ending with a newline.
443 The constructor adds a newline if needed.
444
445 - want: The expected output from running the source code (either
446 from stdout, or a traceback in case of exception). `want` ends
447 with a newline unless it's empty, in which case it's an empty
448 string. The constructor adds a newline if needed.
449
450 - exc_msg: The exception message generated by the example, if
451 the example is expected to generate an exception; or `None` if
452 it is not expected to generate an exception. This exception
453 message is compared against the return value of
454 `traceback.format_exception_only()`. `exc_msg` ends with a
455 newline unless it's `None`. The constructor adds a newline
456 if needed.
457
458 - lineno: The line number within the DocTest string containing
459 this Example where the Example begins. This line number is
460 zero-based, with respect to the beginning of the DocTest.
461
462 - indent: The example's indentation in the DocTest string.
463 I.e., the number of space characters that precede the
464 example's first prompt.
465
466 - options: A dictionary mapping from option flags to True or
467 False, which is used to override default options for this
468 example. Any option flags not contained in this dictionary
469 are left at their default value (as specified by the
470 DocTestRunner's optionflags). By default, no options are set.
471 """
472 def __init__(self, source, want, exc_msg=None, lineno=0, indent=0,
473 options=None):
474 # Normalize inputs.
475 if not source.endswith('\n'):
476 source += '\n'
477 if want and not want.endswith('\n'):
478 want += '\n'
479 if exc_msg is not None and not exc_msg.endswith('\n'):
480 exc_msg += '\n'
481 # Store properties.
482 self.source = source
483 self.want = want
484 self.lineno = lineno
485 self.indent = indent
486 if options is None: options = {}
487 self.options = options
488 self.exc_msg = exc_msg
489
490 def __eq__(self, other):
491 if type(self) is not type(other):
492 return NotImplemented
493
494 return self.source == other.source and \

Callers 1

parseMethod · 0.85

Calls

no outgoing calls

Tested by 1

parseMethod · 0.68