def GoldenFile(filename):
  """Finds the given golden file and returns a file object representing it."""

  # Search up the directory tree looking for the C++ protobuf source code.
  path = '.'
  while os.path.exists(path):
    if os.path.exists(os.path.join(path, 'src/google/protobuf')):
      # Found it.  Load the golden file from the testdata directory.
      full_path = os.path.join(path, 'src/google/protobuf/testdata', filename)
      return open(full_path, 'rb')
    path = os.path.join(path, '..')

  # Search internally.
  path = '.'
  full_path = os.path.join(path, 'third_party/py/google/protobuf/testdata',
                           filename)
  if os.path.exists(full_path):
    # Found it.  Load the golden file from the testdata directory.
    return open(full_path, 'rb')

  raise RuntimeError(
      'Could not find golden files.  This test must be run from within the '
      'protobuf source package so that it can read test data files from the '
      'C++ source tree.')
Finds the given golden file and returns a file object representing it.
deps/protobuf/python/google/protobuf/internal/test_util.py