MCPcopy Index your code
hub / github.com/ipython/ipython / _init_checker_class

Function _init_checker_class

IPython/testing/plugin/pytest_ipdoctest.py:726–812  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

724
725
726def _init_checker_class() -> Type["IPDoctestOutputChecker"]:
727 import doctest
728 import re
729 from .ipdoctest import IPDoctestOutputChecker
730
731 class LiteralsOutputChecker(IPDoctestOutputChecker):
732 # Based on doctest_nose_plugin.py from the nltk project
733 # (https://github.com/nltk/nltk) and on the "numtest" doctest extension
734 # by Sebastien Boisgerault (https://github.com/boisgera/numtest).
735
736 _unicode_literal_re = re.compile(r"(\W|^)[uU]([rR]?[\'\"])", re.UNICODE)
737 _bytes_literal_re = re.compile(r"(\W|^)[bB]([rR]?[\'\"])", re.UNICODE)
738 _number_re = re.compile(
739 r"""
740 (?P<number>
741 (?P<mantissa>
742 (?P<integer1> [+-]?\d*)\.(?P<fraction>\d+)
743 |
744 (?P<integer2> [+-]?\d+)\.
745 )
746 (?:
747 [Ee]
748 (?P<exponent1> [+-]?\d+)
749 )?
750 |
751 (?P<integer3> [+-]?\d+)
752 (?:
753 [Ee]
754 (?P<exponent2> [+-]?\d+)
755 )
756 )
757 """,
758 re.VERBOSE,
759 )
760
761 def check_output(self, want: str, got: str, optionflags: int) -> bool:
762 if super().check_output(want, got, optionflags):
763 return True
764
765 allow_unicode = optionflags & _get_allow_unicode_flag()
766 allow_bytes = optionflags & _get_allow_bytes_flag()
767 allow_number = optionflags & _get_number_flag()
768
769 if not allow_unicode and not allow_bytes and not allow_number:
770 return False
771
772 def remove_prefixes(regex: Pattern[str], txt: str) -> str:
773 return re.sub(regex, r"\1\2", txt)
774
775 if allow_unicode:
776 want = remove_prefixes(self._unicode_literal_re, want)
777 got = remove_prefixes(self._unicode_literal_re, got)
778
779 if allow_bytes:
780 want = remove_prefixes(self._bytes_literal_re, want)
781 got = remove_prefixes(self._bytes_literal_re, got)
782
783 if allow_number:

Callers 1

_get_checkerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…