code: def test_doctest_issue4197(self):
      # To avoid having to keep two copies of the doctest module's
      # unit tests in sync, this test works by taking the source of
      # test_doctest itself, rewriting it a bit to cope with a new
      # location, and then throwing it in a zip file to make sure
      # everything still works correctly
      test_src = inspect.getsource(test_doctest)
      test_src = test_src.replace(
          "from test import test_doctest",
          "import test_zipped_doctest as test_doctest",
      )
      test_src = test_src.replace(
          "test.test_doctest", "test_zipped_doctest"
      )
      test_src = test_src.replace(
          "test.sample_doctest", "sample_zipped_doctest"
      )
      # The sample doctest files rewritten to include in the zipped version.
      sample_sources = {}
      for mod in [
          sample_doctest,
          sample_doctest_no_doctests,
          sample_doctest_no_docstrings,
      ]:
          src = inspect.getsource(mod)
          src = src.replace("test.test_doctest", "test_zipped_doctest")
          # Rewrite the module name so that, for example,
          # "test.sample_doctest" becomes "sample_zipped_doctest".
          mod_name = mod.__name__.split(".")[-1]
          mod_name = mod_name.replace("sample_", "sample_zipped_")
          sample_sources[mod_name] = src
  
      with os_helper.temp_dir() as d:
          script_name = make_script(d, "test_zipped_doctest", test_src)
          zip_name, run_name = make_zip_script(
              d, "test_zip", script_name
          )
          with zipfile.ZipFile(zip_name, "a") as z:
              for mod_name, src in sample_sources.items():
                  z.writestr(mod_name + ".py", src)
          if verbose:
              with zipfile.ZipFile(zip_name, "r") as zip_file:
                  print("Contents of %r:" % zip_name)
                  zip_file.printdir()
          os.remove(script_name)
          sys.path.insert(0, zip_name)
          import test_zipped_doctest
  
          try:
              # Some of the doc tests depend on the colocated text files
              # which aren't available to the zipped version (the doctest
              # module currently requires real filenames for non-embedded
              # tests). So we're forced to be selective about which tests
              # to run.
              # doctest could really use some APIs which take a text
              # string or a file object instead of a filename...
              known_good_tests = [
                  test_zipped_doctest.SampleClass,
                  test_zipped_doctest.SampleClass.NestedClass,
                  test_zipped_doctest.SampleClass.NestedClass.__init__,
                  test_zipped_doctest.SampleClass.__init__,
                  test_zipped_doctest.SampleClass.a_classmethod,
                  test_zipped_doctest.SampleClass.a_property,
                  test_zipped_doctest.SampleClass.a_staticmethod,
                  test_zipped_doctest.SampleClass.double,
                  test_zipped_doctest.SampleClass.get,
                  test_zipped_doctest.SampleNewStyleClass,
                  test_zipped_doctest.SampleNewStyleClass.__init__,
                  test_zipped_doctest.SampleNewStyleClass.double,
                  test_zipped_doctest.SampleNewStyleClass.get,
                  test_zipped_doctest.sample_func,
                  test_zipped_doctest.test_DocTest,
                  test_zipped_doctest.test_DocTestParser,
                  test_zipped_doctest.test_DocTestRunner.basics,
                  test_zipped_doctest.test_DocTestRunner.exceptions,
                  test_zipped_doctest.test_DocTestRunner.option_directives,
                  test_zipped_doctest.test_DocTestRunner.optionflags,
                  test_zipped_doctest.test_DocTestRunner.verbose_flag,
                  test_zipped_doctest.test_Example,
                  test_zipped_doctest.test_debug,
                  test_zipped_doctest.test_testsource,
                  test_zipped_doctest.test_trailing_space_in_test,
                  test_zipped_doctest.test_DocTestSuite,
                  test_zipped_doctest.test_DocTestFinder,
              ]
              # These tests are the ones which need access
              # to the data files, so we don't run them
              fail_due_to_missing_data_files = [
                  test_zipped_doctest.test_DocFileSuite,
                  test_zipped_doctest.test_testfile,
                  test_zipped_doctest.test_unittest_reportflags,
              ]
  
              for obj in known_good_tests:
                  _run_object_doctest(obj, test_zipped_doctest)
          finally:
              del sys.modules["test_zipped_doctest"]
  
imports: import test.support
  import os
  import os.path
  import sys
  import textwrap
  import zipfile
  import zipimport
  import doctest
  import inspect
  import linecache
  import unittest
  from test.support import os_helper
  from test.support.script_helper import spawn_python, kill_python, assert_python_ok, make_script, make_zip_script
  from test import test_doctest, sample_doctest, sample_doctest_no_doctests, sample_doctest_no_docstrings
label_desc: Use image node_id 4 for calling the ZipSupportTests obj's underlying member method code with example usage: obj.test_doctest_issue4197() without return types