code: def test_as_directory_lock_cleanup(checkpoint: Checkpoint):
      """Errors when accessing a checkpoint with `as_directory`
      shouldn't leave behind lock files.
      """
      with pytest.raises(RuntimeError):
          with checkpoint.as_directory() as checkpoint_dir:
              raise RuntimeError
  
      assert not _list_existing_del_locks(checkpoint_dir)
  
      is_local_checkpoint = isinstance(
          checkpoint.filesystem, pyarrow.fs.LocalFileSystem
      )
      if not is_local_checkpoint:
          assert not Path(checkpoint_dir).exists()
  
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 7 for calling a global function with example usage: test_as_directory_lock_cleanup(checkpoint) without return types