Process data block for OUTPUT token.
(self, data, output_prompt, input_lines, output,
is_doctest, decorator, image_file)
| 611 | |
| 612 | |
| 613 | def process_output(self, data, output_prompt, input_lines, output, |
| 614 | is_doctest, decorator, image_file): |
| 615 | """ |
| 616 | Process data block for OUTPUT token. |
| 617 | |
| 618 | """ |
| 619 | # Recall: `data` is the submitted output, and `output` is the processed |
| 620 | # output from `input_lines`. |
| 621 | |
| 622 | TAB = ' ' * 4 |
| 623 | |
| 624 | if is_doctest and output is not None: |
| 625 | |
| 626 | found = output # This is the processed output |
| 627 | found = found.strip() |
| 628 | submitted = data.strip() |
| 629 | |
| 630 | if self.directive is None: |
| 631 | source = 'Unavailable' |
| 632 | content = 'Unavailable' |
| 633 | else: |
| 634 | source = self.directive.state.document.current_source |
| 635 | content = self.directive.content |
| 636 | # Add tabs and join into a single string. |
| 637 | content = '\n'.join([TAB + line for line in content]) |
| 638 | |
| 639 | # Make sure the output contains the output prompt. |
| 640 | ind = found.find(output_prompt) |
| 641 | if ind < 0: |
| 642 | e = ('output does not contain output prompt\n\n' |
| 643 | 'Document source: {0}\n\n' |
| 644 | 'Raw content: \n{1}\n\n' |
| 645 | 'Input line(s):\n{TAB}{2}\n\n' |
| 646 | 'Output line(s):\n{TAB}{3}\n\n') |
| 647 | e = e.format(source, content, '\n'.join(input_lines), |
| 648 | repr(found), TAB=TAB) |
| 649 | raise RuntimeError(e) |
| 650 | found = found[len(output_prompt):].strip() |
| 651 | |
| 652 | # Handle the actual doctest comparison. |
| 653 | if decorator.strip() == '@doctest': |
| 654 | # Standard doctest |
| 655 | if found != submitted: |
| 656 | e = ('doctest failure\n\n' |
| 657 | 'Document source: {0}\n\n' |
| 658 | 'Raw content: \n{1}\n\n' |
| 659 | 'On input line(s):\n{TAB}{2}\n\n' |
| 660 | 'we found output:\n{TAB}{3}\n\n' |
| 661 | 'instead of the expected:\n{TAB}{4}\n\n') |
| 662 | e = e.format(source, content, '\n'.join(input_lines), |
| 663 | repr(found), repr(submitted), TAB=TAB) |
| 664 | raise RuntimeError(e) |
| 665 | else: |
| 666 | self.custom_doctest(decorator, input_lines, found, submitted) |
| 667 | |
| 668 | # When in verbatim mode, this holds additional submitted output |
| 669 | # to be written in the final Sphinx output. |
| 670 | # https://github.com/ipython/ipython/issues/5776 |
no test coverage detected