class_docstr: Example runner.
  
  A single runner can run multiple script commands.
  A runner creates a temporary directory and files in the respective example
  directory are copied there.
  All the runs are executed within the temporary directory as the current
  directory.
class_docstr_tok: ["Example","runner",".","A","single","runner","can","run","multiple","script","commands",".","A","runner","creates","a","temporary","directory","and","files","in","the","respective","example","directory","are","copied","there",".","All","the","runs","are","executed","within","the","temporary","directory","as","the","current","directory","."]
code: def run(self, script_name, args, *, output_evaluator=None):
      # Runs a command.
  
      assert (
          self.contexts is not None
      ), "__enter__ has not been called on the example runner."
      assert isinstance(script_name, str), type(script_name)
      assert isinstance(args, list), type(args)
      assert output_evaluator is None or isinstance(
          output_evaluator, OutputEvaluator
      ), type(output_evaluator)
      work_dir = self.work_dir
      script_path = os.path.join(work_dir, script_name)
      assert os.path.isfile(script_path), script_path
  
      command = [sys.executable, script_path] + args
  
      # Run the command.
      proc = subprocess.Popen(
          command, stdout=subprocess.PIPE, stderr=subprocess.PIPE
      )
      stdoutdata, stderrdata = proc.communicate()
  
      def fail(msg):
          err_fmt = """\
  {message}
  == command ==
  {command}
  == stdout ==
  {stdout}
  == stderr ==
  {stderr}
  """
          err = err_fmt.format(
              message=msg,
              command=" ".join(command),
              stdout=stdoutdata.decode("utf8"),
              stderr=stderrdata.decode("utf8"),
          )
          raise RuntimeError(err)
  
      if proc.returncode != 0:
          fail("Script exited with {}.".format(proc.returncode))
  
      if output_evaluator is not None:
          try:
              output_evaluator.check(stdoutdata)
          except RuntimeError as e:
              fail(
                  "Script output does not meet expectation:\n"
                  "{}".format(e)
              )
  
imports: import contextlib
  import os
  import re
  import shutil
  import subprocess
  import sys
  import tempfile
label_desc: Use image node_id 7 for calling the ExampleRunner obj's underlying member method code with example usage: obj.run(script_name, args) without return types