code: def test_write_metadata(
      tmp_path: pathlib.Path,
      file_format,
  ):
      tmp_path = epath.Path(tmp_path)
  
      src_builder = testing.DummyDataset(
          data_dir=tmp_path / "origin",
          file_format=file_format,
      )
      src_builder.download_and_prepare()
  
      dst_dir = tmp_path / "copy"
      dst_dir.mkdir()
  
      # Copy all the tfrecord files, but not the dataset info
      for f in src_builder.data_path.iterdir():
          if naming.FilenameInfo.is_valid(f.name):
              f.copy(dst_dir / f.name)
  
      metadata_path = dst_dir / "dataset_info.json"
  
      if file_format is None:
          split_infos = list(src_builder.info.splits.values())
      else:
          split_infos = None  # Auto-compute split infos
  
      assert not metadata_path.exists()
      write_metadata_utils.write_metadata(
          data_dir=dst_dir,
          features=src_builder.info.features,
          split_infos=split_infos,
          description="my test description.",
      )
      assert metadata_path.exists()
  
      # After metadata are written, builder can be restored from the directory
      builder = read_only_builder.builder_from_directory(dst_dir)
      assert builder.name == "dummy_dataset"
      assert builder.version == "1.0.0"
      assert set(builder.info.splits) == {"train"}
      assert builder.info.splits["train"].num_examples == 3
      assert builder.info.description == "my test description."
  
      # Values are the same
      src_ds = src_builder.as_dataset(split="train")
      ds = builder.as_dataset(split="train")
      assert list(src_ds.as_numpy_iterator()) == list(
          ds.as_numpy_iterator()
      )
  
file_path: datasets/tensorflow_datasets/core/folder_dataset/write_metadata_utils_test.py
imports: import pathlib
  from etils import epath
  import pytest
  from tensorflow_datasets import testing
  from tensorflow_datasets.core import naming
  from tensorflow_datasets.core import read_only_builder
  from tensorflow_datasets.core.folder_dataset import write_metadata_utils
label_desc: Use image node_id 1 for calling a global function with example usage: test_write_metadata(tmp_path, file_format) without return types