code: def test_restore_after_modification(self):
      # Create a DatasetInfo
      info = dataset_info.DatasetInfo(
          builder=self._builder,
          description="A description",
          supervised_keys=("input", "output"),
          homepage="http://some-location",
          citation="some citation",
          license="some license",
      )
      info.as_proto.config_tags.extend(["foo", "bar"])
      info.download_size = 456
      filepath_template = (
          "{DATASET}-{SPLIT}.{FILEFORMAT}-{SHARD_X_OF_Y}"
      )
      info.as_proto.splits.add(
          name="train",
          num_bytes=512,
          filepath_template=filepath_template,
      )
      info.as_proto.splits.add(
          name="validation",
          num_bytes=64,
          filepath_template=filepath_template,
      )
      info.as_proto.schema.feature.add()
      info.as_proto.schema.feature.add()  # Add dynamic statistics
      info.download_checksums = {
          "url1": "some checksum",
          "url2": "some other checksum",
      }
  
      with testing.tmp_dir(self.get_temp_dir()) as tmp_dir:
          # Save it
          info.write_to_directory(tmp_dir)
  
          # If fields are not defined, then everything is restored from disk.
          restored_info = dataset_info.DatasetInfo(
              builder=self._builder
          )
          restored_info.read_from_directory(tmp_dir)
          self.assertProtoEquals(info.as_proto, restored_info.as_proto)
  
      with testing.tmp_dir(self.get_temp_dir()) as tmp_dir:
          # Save it
          info.write_to_directory(tmp_dir)
  
          # If fields are defined, then the code version is kept
          restored_info = dataset_info.DatasetInfo(
              builder=self._builder,
              supervised_keys=("input (new)", "output (new)"),
              homepage="http://some-location-new",
              citation="some citation (new)",
              redistribution_info={"license": "some license (new)"},
          )
          restored_info.download_size = 789
          restored_info.as_proto.splits.add(
              name="validation", num_bytes=288
          )
          restored_info.as_proto.schema.feature.add()
          restored_info.as_proto.schema.feature.add()
          restored_info.as_proto.schema.feature.add()
          restored_info.as_proto.schema.feature.add()  # Add dynamic statistics
          restored_info.download_checksums = {
              "url2": "some other checksum (new)",
              "url3": "some checksum (new)",
          }
  
          restored_info.read_from_directory(tmp_dir)
  
          # Even though restored_info has been restored, informations defined in
          # the code overwrite informations from the json file.
          self.assertEqual(restored_info.description, "A description")
          self.assertEqual(
              restored_info.version, utils.Version("3.0.1")
          )
          self.assertEqual(restored_info.release_notes, {})
          self.assertEqual(
              restored_info.supervised_keys,
              ("input (new)", "output (new)"),
          )
          self.assertEqual(
              restored_info.homepage, "http://some-location-new"
          )
          self.assertEqual(
              restored_info.citation, "some citation (new)"
          )
          self.assertEqual(
              restored_info.redistribution_info.license,
              "some license (new)",
          )
          self.assertEqual(restored_info.download_size, 789)
          self.assertEqual(restored_info.dataset_size, 576)
          self.assertEqual(
              len(restored_info.as_proto.schema.feature), 4
          )
          self.assertEqual(
              restored_info.download_checksums,
              {
                  "url2": "some other checksum (new)",
                  "url3": "some checksum (new)",
              },
          )
  
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 9 for calling the DatasetInfoTest obj's underlying member method code with example usage: obj.test_restore_after_modification() without return types