code: def test_file_format_save_restore(
      tmp_path: pathlib.Path,
      file_format: file_adapters.FileFormat,
  ):
      builder = testing.DummyDataset(
          data_dir=tmp_path, file_format=file_format
      )
  
      assert isinstance(
          builder.info.file_format, file_adapters.FileFormat
      )
      assert builder.info.file_format is file_format
  
      builder.download_and_prepare()
  
      # When restoring the builder, we do not provide the `file_format=`
      # yet it is correctly restored
      builder2 = testing.DummyDataset(data_dir=tmp_path)
      assert builder2.info.file_format is file_format
  
      # Explicitly passing the correct format is accepted.
      builder3 = testing.DummyDataset(
          data_dir=tmp_path, file_format=file_format
      )
      assert builder3.info.file_format is file_format
  
      # Providing an inconsistent format is rejected.
      with pytest.raises(
          ValueError, match="File format is already set to"
      ):
          different_file_format = {
              file_adapters.FileFormat.TFRECORD: file_adapters.FileFormat.RIEGELI,
              file_adapters.FileFormat.RIEGELI: file_adapters.FileFormat.TFRECORD,
          }[file_format]
          testing.DummyDataset(
              data_dir=tmp_path, file_format=different_file_format
          )
  
imports: import json
  import os
  import pathlib
  import tempfile
  import time
  from typing import Union
  import numpy
  import pytest
  import tensorflow
  from tensorflow_datasets import testing
  from tensorflow_datasets.core import dataset_builder
  from tensorflow_datasets.core import dataset_info
  from tensorflow_datasets.core import features
  from tensorflow_datasets.core import file_adapters
  from tensorflow_datasets.core import naming
  from tensorflow_datasets.core import read_only_builder
  from tensorflow_datasets.core import splits
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.proto import dataset_info_pb2
  from tensorflow_datasets.core.proto import feature_pb2
  from tensorflow_datasets.image_classification import mnist
  from tensorflow_datasets.testing.dummy_config_based_datasets.dummy_ds_1 import dummy_ds_1_dataset_builder
  from google.protobuf import text_format
label_desc: Use image node_id 1 for calling a global function with example usage: test_file_format_save_restore(tmp_path, file_format) without return types