Divide the given string into examples and intervening text, and return them as a list of alternating Examples and strings. Line numbers for the Examples are 0-based. The optional argument `name` is a name identifying this string, and is only used for er
(self, string, name='<string>')
| 628 | _IS_BLANK_OR_COMMENT = re.compile(r'^[ ]*(#.*)?$').match |
| 629 | |
| 630 | def parse(self, string, name='<string>'): |
| 631 | """ |
| 632 | Divide the given string into examples and intervening text, |
| 633 | and return them as a list of alternating Examples and strings. |
| 634 | Line numbers for the Examples are 0-based. The optional |
| 635 | argument `name` is a name identifying this string, and is only |
| 636 | used for error messages. |
| 637 | """ |
| 638 | string = string.expandtabs() |
| 639 | # If all lines begin with the same indentation, then strip it. |
| 640 | min_indent = self._min_indent(string) |
| 641 | if min_indent > 0: |
| 642 | string = '\n'.join([l[min_indent:] for l in string.split('\n')]) |
| 643 | |
| 644 | output = [] |
| 645 | charno, lineno = 0, 0 |
| 646 | # Find all doctest examples in the string: |
| 647 | for m in self._EXAMPLE_RE.finditer(string): |
| 648 | # Add the pre-example text to `output`. |
| 649 | output.append(string[charno:m.start()]) |
| 650 | # Update lineno (lines before this example) |
| 651 | lineno += string.count('\n', charno, m.start()) |
| 652 | # Extract info from the regexp match. |
| 653 | (source, options, want, exc_msg) = \ |
| 654 | self._parse_example(m, name, lineno) |
| 655 | # Create an Example, and add it to the list. |
| 656 | if not self._IS_BLANK_OR_COMMENT(source): |
| 657 | output.append( Example(source, want, exc_msg, |
| 658 | lineno=lineno, |
| 659 | indent=min_indent+len(m.group('indent')), |
| 660 | options=options) ) |
| 661 | # Update lineno (lines inside this example) |
| 662 | lineno += string.count('\n', m.start(), m.end()) |
| 663 | # Update charno. |
| 664 | charno = m.end() |
| 665 | # Add any remaining post-example text to `output`. |
| 666 | output.append(string[charno:]) |
| 667 | return output |
| 668 | |
| 669 | def get_doctest(self, string, globs, name, filename, lineno): |
| 670 | """ |
no test coverage detected