class_docstr: Class whose instances act as a decorator for docstring testing.
  
  In practice we're only likely to need one instance ever, made below (though
  no attempt is made at turning it into a singleton, there is no need for
  that).
class_docstr_tok: ["Class","whose","instances","act","as","a","decorator","for","docstring","testing",".","In","practice","we","'re","only","likely","to","need","one","instance","ever",",","made","below","(","though","no","attempt","is","made","at","turning","it","into","a","singleton",",","there","is","no","need","for","that",")","."]
docstr: Use as a decorator: doctest a function's docstring as a unittest.
  
  This version runs normal doctests, but the idea is to make it later run
  ipython syntax instead.
docstr_tok: ["Use","as","a","decorator",":","doctest","a","function","'s","docstring","as","a","unittest",".","This","version","runs","normal","doctests",",","but","the","idea","is","to","make","it","later","run","ipython","syntax","instead","."]
code: def __call__(self, func):
      """Use as a decorator: doctest a function's docstring as a unittest.
  
      This version runs normal doctests, but the idea is to make it later run
      ipython syntax instead."""
  
      # Capture the enclosing instance with a different name, so the new
      # class below can see it without confusion regarding its own 'self'
      # that will point to the test instance at runtime
      d2u = self
  
      # Rewrite the function's docstring to have python syntax
      if func.__doc__ is not None:
          func.__doc__ = ip2py(func.__doc__)
  
      # Now, create a tester object that is a real unittest instance, so
      # normal unittest machinery (or Nose, or Trial) can find it.
      class Tester(unittest.TestCase):
          def test(self):
              # Make a new runner per function to be tested
              runner = DocTestRunner(verbose=d2u.verbose)
              for the_test in d2u.finder.find(func, func.__name__):
                  runner.run(the_test)
              failed = count_failures(runner)
              if failed:
                  # Since we only looked at a single function's docstring,
                  # failed should contain at most one item.  More than that
                  # is a case we can't handle and should error out on
                  if len(failed) > 1:
                      err = (
                          "Invalid number of test results: %s" % failed
                      )
                      raise ValueError(err)
                  # Report a normal failure.
                  self.fail("failed doctests: %s" % str(failed[0]))
  
      # Rename it so test reports have the original signature.
      Tester.__name__ = func.__name__
      return Tester
  
file_path: catboost/contrib/python/ipython/py3/IPython/testing/ipunittest.py
imports: import re
  import unittest
  from doctest import DocTestFinder, DocTestRunner, TestResults
  from IPython.terminal.interactiveshell import InteractiveShell
label_desc: Use image node_id 2 for calling the Doc2UnitTester obj's underlying member method code with example usage: obj.__call__(func) and returns: Tester