code: def test():
      examples = [
          r"""
  In [9]: pwd
  Out[9]: '/home/jdhunter/py4science/book'
  
  In [10]: cd bookdata/
  /home/jdhunter/py4science/book/bookdata
  
  In [2]: from pylab import *
  
  In [2]: ion()
  
  In [3]: im = imread('stinkbug.png')
  
  @savefig mystinkbug.png width=4in
  In [4]: imshow(im)
  Out[4]: <matplotlib.image.AxesImage object at 0x39ea850>
  
  """,
          r"""
  
  In [1]: x = 'hello world'
  
  # string methods can be
  # used to alter the string
  @doctest
  In [2]: x.upper()
  Out[2]: 'HELLO WORLD'
  
  @verbatim
  In [3]: x.st<TAB>
  x.startswith  x.strip
  """,
          r"""
  
  In [130]: url = 'http://ichart.finance.yahoo.com/table.csv?s=CROX\
     .....: &d=9&e=22&f=2009&g=d&a=1&br=8&c=2006&ignore=.csv'
  
  In [131]: print url.split('&')
  ['http://ichart.finance.yahoo.com/table.csv?s=CROX', 'd=9', 'e=22', 'f=2009', 'g=d', 'a=1', 'b=8', 'c=2006', 'ignore=.csv']
  
  In [60]: import urllib
  
  """,
          r"""\
  
  In [133]: import numpy.random
  
  @suppress
  In [134]: numpy.random.seed(2358)
  
  @doctest
  In [135]: numpy.random.rand(10,2)
  Out[135]:
  array([[ 0.64524308,  0.59943846],
         [ 0.47102322,  0.8715456 ],
         [ 0.29370834,  0.74776844],
         [ 0.99539577,  0.1313423 ],
         [ 0.16250302,  0.21103583],
         [ 0.81626524,  0.1312433 ],
         [ 0.67338089,  0.72302393],
         [ 0.7566368 ,  0.07033696],
         [ 0.22591016,  0.77731835],
         [ 0.0072729 ,  0.34273127]])
  
  """,
          r"""
  In [106]: print x
  jdh
  
  In [109]: for i in range(10):
     .....:     print i
     .....:
     .....:
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
  """,
          r"""
  
  In [144]: from pylab import *
  
  In [145]: ion()
  
  # use a semicolon to suppress the output
  @savefig test_hist.png width=4in
  In [151]: hist(np.random.randn(10000), 100);
  
  
  @savefig test_plot.png width=4in
  In [151]: plot(np.random.randn(10000), 'o');
     """,
          r"""
  # use a semicolon to suppress the output
  In [151]: plt.clf()
  
  @savefig plot_simple.png width=4in
  In [151]: plot([1,2,3])
  
  @savefig hist_simple.png width=4in
  In [151]: hist(np.random.randn(10000), 100);
  
  """,
          r"""
  # update the current fig
  In [151]: ylabel('number')
  
  In [152]: title('normal distribution')
  
  
  @savefig hist_with_text.png
  In [153]: grid(True)
  
  @doctest float
  In [154]: 0.1 + 0.2
  Out[154]: 0.3
  
  @doctest float
  In [155]: np.arange(16).reshape(4,4)
  Out[155]:
  array([[ 0,  1,  2,  3],
         [ 4,  5,  6,  7],
         [ 8,  9, 10, 11],
         [12, 13, 14, 15]])
  
  In [1]: x = np.arange(16, dtype=float).reshape(4,4)
  
  In [2]: x[0,0] = np.inf
  
  In [3]: x[0,1] = np.nan
  
  @doctest float
  In [4]: x
  Out[4]:
  array([[ inf,  nan,   2.,   3.],
         [  4.,   5.,   6.,   7.],
         [  8.,   9.,  10.,  11.],
         [ 12.,  13.,  14.,  15.]])
  
  
          """,
      ]
      # skip local-file depending first example:
      examples = examples[1:]
  
      # ipython_directive.DEBUG = True  # dbg
      # options = dict(suppress=True)  # dbg
      options = {}
      for example in examples:
          content = example.split("\n")
          IPythonDirective(
              "debug",
              arguments=None,
              options=options,
              content=content,
              lineno=0,
              content_offset=None,
              block_text=None,
              state=None,
              state_machine=None,
          )
  
imports: import atexit
  import errno
  import os
  import pathlib
  import re
  import sys
  import tempfile
  import ast
  import warnings
  import shutil
  from io import StringIO
  from docutils.parsers.rst import directives
  from docutils.parsers.rst import Directive
  from sphinx.util import logging
  from traitlets.config import Config
  from IPython import InteractiveShell
  from IPython.core.profiledir import ProfileDir
label_desc: Use image node_id 3 for calling a global function with example usage: test() without return types