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

Class DocTest

Lib/doctest.py:532–603  ·  view source on GitHub ↗

A collection of doctest examples that should be run in a single namespace. Each `DocTest` defines the following attributes: - examples: the list of examples. - globs: The namespace (aka globals) that the examples should be run in. - name: A name identifying the

Source from the content-addressed store, hash-verified

530 self.exc_msg))
531
532class DocTest:
533 """
534 A collection of doctest examples that should be run in a single
535 namespace. Each `DocTest` defines the following attributes:
536
537 - examples: the list of examples.
538
539 - globs: The namespace (aka globals) that the examples should
540 be run in.
541
542 - name: A name identifying the DocTest (typically, the name of
543 the object whose docstring this DocTest was extracted from).
544
545 - filename: The name of the file that this DocTest was extracted
546 from, or `None` if the filename is unknown.
547
548 - lineno: The line number within filename where this DocTest
549 begins, or `None` if the line number is unavailable. This
550 line number is zero-based, with respect to the beginning of
551 the file.
552
553 - docstring: The string that the examples were extracted from,
554 or `None` if the string is unavailable.
555 """
556 def __init__(self, examples, globs, name, filename, lineno, docstring):
557 """
558 Create a new DocTest containing the given examples. The
559 DocTest's globals are initialized with a copy of `globs`.
560 """
561 assert not isinstance(examples, str), \
562 "DocTest no longer accepts str; use DocTestParser instead"
563 self.examples = examples
564 self.docstring = docstring
565 self.globs = globs.copy()
566 self.name = name
567 self.filename = filename
568 self.lineno = lineno
569
570 def __repr__(self):
571 if len(self.examples) == 0:
572 examples = 'no examples'
573 elif len(self.examples) == 1:
574 examples = '1 example'
575 else:
576 examples = '%d examples' % len(self.examples)
577 return ('<%s %s from %s:%s (%s)>' %
578 (self.__class__.__name__,
579 self.name, self.filename, self.lineno, examples))
580
581 def __eq__(self, other):
582 if type(self) is not type(other):
583 return NotImplemented
584
585 return self.examples == other.examples and \
586 self.docstring == other.docstring and \
587 self.globs == other.globs and \
588 self.name == other.name and \
589 self.filename == other.filename and \

Callers 1

get_doctestMethod · 0.85

Calls

no outgoing calls

Tested by 1

get_doctestMethod · 0.68