Build a mock open side effect using a dictionary of content for the files.

  :param string_d: keys are file names, values are string file contents
  :param stream_d: keys are file names, values are stream of contents

def build_mock_open_side_effect(string_d, stream_d):
  """
  Build a mock open side effect using a dictionary of content for the files.

  :param string_d: keys are file names, values are string file contents
  :param stream_d: keys are file names, values are stream of contents
  """
  assert(len(set(string_d.keys()).intersection(set(stream_d.keys()))) == 0)

  def mock_open_side_effect(*args, **kwargs):
    if args[0] in string_d:
      return StringIO.StringIO(string_d[args[0]])
    elif args[0] in stream_d:
      return stream_d[args[0]]
    else:
      raise IOError("No such file: " + args[0])
  return mock_open_side_effect