MCPcopy Create free account
hub / github.com/numpy/numpy / Checker

Class Checker

tools/refguide_check.py:660–767  ·  view source on GitHub ↗

Check the docstrings

Source from the content-addressed store, hash-verified

658 example, got)
659
660class Checker(doctest.OutputChecker):
661 """
662 Check the docstrings
663 """
664 obj_pattern = re.compile('at 0x[0-9a-fA-F]+>')
665 vanilla = doctest.OutputChecker()
666 rndm_markers = {'# random', '# Random', '#random', '#Random', "# may vary",
667 "# uninitialized", "#uninitialized"}
668 stopwords = {'plt.', '.hist', '.show', '.ylim', '.subplot(',
669 'set_title', 'imshow', 'plt.show', '.axis(', '.plot(',
670 '.bar(', '.title', '.ylabel', '.xlabel', 'set_ylim', 'set_xlim',
671 '# reformatted', '.set_xlabel(', '.set_ylabel(', '.set_zlabel(',
672 '.set(xlim=', '.set(ylim=', '.set(xlabel=', '.set(ylabel='}
673
674 def __init__(self, parse_namedtuples=True, ns=None, atol=1e-8, rtol=1e-2):
675 self.parse_namedtuples = parse_namedtuples
676 self.atol, self.rtol = atol, rtol
677 if ns is None:
678 self.ns = CHECK_NAMESPACE
679 else:
680 self.ns = ns
681
682 def check_output(self, want, got, optionflags):
683 # cut it short if they are equal
684 if want == got:
685 return True
686
687 # skip stopwords in source
688 if any(word in self._source for word in self.stopwords):
689 return True
690
691 # skip random stuff
692 if any(word in want for word in self.rndm_markers):
693 return True
694
695 # skip function/object addresses
696 if self.obj_pattern.search(got):
697 return True
698
699 # ignore comments (e.g. signal.freqresp)
700 if want.lstrip().startswith("#"):
701 return True
702
703 # try the standard doctest
704 try:
705 if self.vanilla.check_output(want, got, optionflags):
706 return True
707 except Exception:
708 pass
709
710 # OK then, convert strings to objects
711 try:
712 a_want = eval(want, dict(self.ns))
713 a_got = eval(got, dict(self.ns))
714 except Exception:
715 # Maybe we're printing a numpy array? This produces invalid python
716 # code: `print(np.arange(3))` produces "[0 1 2]" w/o commas between
717 # values. So, reinsert commas and retry.

Callers 1

_run_doctestsFunction · 0.85

Calls 1

compileMethod · 0.45

Tested by

no test coverage detected