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 identi
| 503 | self.exc_msg)) |
| 504 | |
| 505 | class DocTest: |
| 506 | """ |
| 507 | A collection of doctest examples that should be run in a single |
| 508 | namespace. Each `DocTest` defines the following attributes: |
| 509 | |
| 510 | - examples: the list of examples. |
| 511 | |
| 512 | - globs: The namespace (aka globals) that the examples should |
| 513 | be run in. |
| 514 | |
| 515 | - name: A name identifying the DocTest (typically, the name of |
| 516 | the object whose docstring this DocTest was extracted from). |
| 517 | |
| 518 | - filename: The name of the file that this DocTest was extracted |
| 519 | from, or `None` if the filename is unknown. |
| 520 | |
| 521 | - lineno: The line number within filename where this DocTest |
| 522 | begins, or `None` if the line number is unavailable. This |
| 523 | line number is zero-based, with respect to the beginning of |
| 524 | the file. |
| 525 | |
| 526 | - docstring: The string that the examples were extracted from, |
| 527 | or `None` if the string is unavailable. |
| 528 | """ |
| 529 | def __init__(self, examples, globs, name, filename, lineno, docstring): |
| 530 | """ |
| 531 | Create a new DocTest containing the given examples. The |
| 532 | DocTest's globals are initialized with a copy of `globs`. |
| 533 | """ |
| 534 | assert not isinstance(examples, str), \ |
| 535 | "DocTest no longer accepts str; use DocTestParser instead" |
| 536 | self.examples = examples |
| 537 | self.docstring = docstring |
| 538 | self.globs = globs.copy() |
| 539 | self.name = name |
| 540 | self.filename = filename |
| 541 | self.lineno = lineno |
| 542 | |
| 543 | def __repr__(self): |
| 544 | if len(self.examples) == 0: |
| 545 | examples = 'no examples' |
| 546 | elif len(self.examples) == 1: |
| 547 | examples = '1 example' |
| 548 | else: |
| 549 | examples = '%d examples' % len(self.examples) |
| 550 | return ('<%s %s from %s:%s (%s)>' % |
| 551 | (self.__class__.__name__, |
| 552 | self.name, self.filename, self.lineno, examples)) |
| 553 | |
| 554 | def __eq__(self, other): |
| 555 | if type(self) is not type(other): |
| 556 | return NotImplemented |
| 557 | |
| 558 | return self.examples == other.examples and \ |
| 559 | self.docstring == other.docstring and \ |
| 560 | self.globs == other.globs and \ |
| 561 | self.name == other.name and \ |
| 562 | self.filename == other.filename and \ |