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 _init_work_dir(self):
      # Copies files in the directory.
      # If a replacement file exists for each file, copy it instead of the
      # original file.
      # Correctness of the replacement files are also checked.
  
      root_dir = self.root_dir
      work_dir = self.work_dir
      assert os.path.isdir(root_dir), root_dir
      assert os.path.isdir(work_dir), work_dir
  
      replace_dir = os.path.join(root_dir, ".testdata", "replacements")
      for dirpath, dirnames, filenames in os.walk(root_dir):
          # Skip directories starting with '.'.
          dirnames[:] = [
              dn for dn in dirnames if not dn.startswith(".")
          ]
  
          if dirpath == root_dir:
              dir_relpath = ""
          else:
              dir_relpath = os.path.relpath(dirpath, root_dir)
  
          for filename in filenames:
              relpath = os.path.join(dir_relpath, filename)
              orig_path = os.path.join(root_dir, relpath)
              dst_path = os.path.join(work_dir, relpath)
              # Check to see if the replace file exists.
              replace_path = os.path.join(replace_dir, relpath)
              if os.path.isfile(replace_path):
                  # The replace file exists: check correctness of the file
                  # comparing with the original file.
                  self._check_replace_file_correct(
                      orig_path, replace_path
                  )
                  # Copy the replace file.
                  self._copyfile(replace_path, dst_path)
              else:
                  # The replace file does not exist: copy the original file.
                  self._copyfile(orig_path, dst_path)
  
imports: import contextlib
  import os
  import re
  import shutil
  import subprocess
  import sys
  import tempfile
label_desc: Use image node_id 4 for calling the ExampleRunner obj's underlying member method code with example usage: obj._init_work_dir() without return types