MCPcopy Index your code
hub / github.com/python/cpython / DocTest

Class DocTest

Lib/doctest.py:526–597  ·  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

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

Callers 1

get_doctestMethod · 0.85

Calls

no outgoing calls

Tested by 1

get_doctestMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…