MCPcopy Create free account
hub / github.com/ipython/ipython / process_output

Method process_output

IPython/sphinxext/ipython_directive.py:593–671  ·  view source on GitHub ↗

Process data block for OUTPUT token.

(self, data, output_prompt, input_lines, output,
                       is_doctest, decorator, image_file)

Source from the content-addressed store, hash-verified

591
592
593 def process_output(self, data, output_prompt, input_lines, output,
594 is_doctest, decorator, image_file):
595 """
596 Process data block for OUTPUT token.
597
598 """
599 # Recall: `data` is the submitted output, and `output` is the processed
600 # output from `input_lines`.
601
602 TAB = ' ' * 4
603
604 if is_doctest and output is not None:
605
606 found = output # This is the processed output
607 found = found.strip()
608 submitted = data.strip()
609
610 if self.directive is None:
611 source = 'Unavailable'
612 content = 'Unavailable'
613 else:
614 source = self.directive.state.document.current_source
615 content = self.directive.content
616 # Add tabs and join into a single string.
617 content = '\n'.join([TAB + line for line in content])
618
619 # Make sure the output contains the output prompt.
620 ind = found.find(output_prompt)
621 if ind < 0:
622 e = ('output does not contain output prompt\n\n'
623 'Document source: {0}\n\n'
624 'Raw content: \n{1}\n\n'
625 'Input line(s):\n{TAB}{2}\n\n'
626 'Output line(s):\n{TAB}{3}\n\n')
627 e = e.format(source, content, '\n'.join(input_lines),
628 repr(found), TAB=TAB)
629 raise RuntimeError(e)
630 found = found[len(output_prompt):].strip()
631
632 # Handle the actual doctest comparison.
633 if decorator.strip() == '@doctest':
634 # Standard doctest
635 if found != submitted:
636 e = ('doctest failure\n\n'
637 'Document source: {0}\n\n'
638 'Raw content: \n{1}\n\n'
639 'On input line(s):\n{TAB}{2}\n\n'
640 'we found output:\n{TAB}{3}\n\n'
641 'instead of the expected:\n{TAB}{4}\n\n')
642 e = e.format(source, content, '\n'.join(input_lines),
643 repr(found), repr(submitted), TAB=TAB)
644 raise RuntimeError(e)
645 else:
646 self.custom_doctest(decorator, input_lines, found, submitted)
647
648 # When in verbatim mode, this holds additional submitted output
649 # to be written in the final Sphinx output.
650 # https://github.com/ipython/ipython/issues/5776

Callers 1

process_blockMethod · 0.95

Calls 3

custom_doctestMethod · 0.95
findMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected