code: def test_metadata(checkpoint: Checkpoint):
      assert checkpoint.get_metadata() == {}
  
      # No metadata file by default.
      assert not _exists_at_fs_path(
          fs=checkpoint.filesystem,
          fs_path=str(Path(checkpoint.path) / _METADATA_FILE_NAME),
      )
  
      checkpoint.update_metadata({"foo": "bar"})
      assert checkpoint.get_metadata() == {"foo": "bar"}
  
      checkpoint.update_metadata({"foo": "baz"})
      assert checkpoint.get_metadata() == {"foo": "baz"}
  
      checkpoint.update_metadata({"x": 1})
      assert checkpoint.get_metadata() == {"foo": "baz", "x": 1}
  
      # Set metadata completely resets the metadata.
      checkpoint.set_metadata({"y": [1, 2, 3]})
      assert checkpoint.get_metadata() == {"y": [1, 2, 3]}
  
      # There should be a metadata file in the checkpoint directory.
      assert _exists_at_fs_path(
          fs=checkpoint.filesystem,
          fs_path=str(Path(checkpoint.path) / _METADATA_FILE_NAME),
      )
  
      # Non JSON serializable metadata should raise an error.
      class Test:
          pass
  
      with pytest.raises(TypeError):
          checkpoint.set_metadata({"non_json_serializable": Test()})
  
file_path: ray/python/ray/train/tests/test_checkpoint.py
imports: import os
  from pathlib import Path
  import pyarrow.fs
  import pytest
  import ray
  from ray.train._checkpoint import _CHECKPOINT_TEMP_DIR_PREFIX, _METADATA_FILE_NAME, Checkpoint, _get_del_lock_path, _list_existing_del_locks
  from ray.train._internal.storage import _exists_at_fs_path, _upload_to_fs_path
  from ray.train.tests.test_new_persistence import _create_mock_custom_fs
label_desc: Use image node_id 9 for calling a global function with example usage: test_metadata(checkpoint) without return types