code: def test_cp_cloud_to_local(tmpdir, monkeypatch):
      error_and_exit = MagicMock()
      monkeypatch.setattr(cp, "_error_and_exit", error_and_exit)
  
      client = MagicMock()
      client.projects_service_list_memberships.return_value = (
          V1ListMembershipsResponse(
              memberships=[V1Membership(name="project-0")]
          )
      )
  
      clusters = MagicMock()
      clusters.clusters = [MagicMock()]
      client.projects_service_list_project_cluster_bindings.return_value = (
          clusters
      )
  
      client.lightningapp_instance_service_list_lightningapp_instances.return_value = V1ListLightningappInstancesResponse(
          lightningapps=[
              Externalv1LightningappInstance(
                  name="app-name-0", id="app-id-0"
              )
          ]
      )
  
      artifacts = [
          V1LightningappInstanceArtifact(
              filename=".file_1.txt",
              url="http://foo.bar/file_1.txt",
              size_bytes=123,
          ),
          V1LightningappInstanceArtifact(
              filename=".folder_1/file_2.txt",
              url="http://foo.bar/folder_1/file_2.txt",
              size_bytes=123,
          ),
          V1LightningappInstanceArtifact(
              filename=".folder_2/folder_3/file_3.txt",
              url="http://foo.bar/folder_2/folder_3/file_3.txt",
              size_bytes=123,
          ),
          V1LightningappInstanceArtifact(
              filename=".folder_4/file_4.txt",
              url="http://foo.bar/folder_4/file_4.txt",
              size_bytes=123,
          ),
      ]
  
      client.lightningapp_instance_service_list_project_artifacts.return_value = V1ListLightningappInstanceArtifactsResponse(
          artifacts=artifacts
      )
  
      monkeypatch.setattr(
          cp, "LightningClient", MagicMock(return_value=client)
      )
  
      assert cd("/", verify=False) == "/"
      cp.cp(str(tmpdir), "r:.")
      assert (
          error_and_exit._mock_call_args_list[0].args[0]
          == "Uploading files at the project level isn't allowed yet."
      )
  
      assert (
          cd("/project-0/app-name-0", verify=False)
          == "/project-0/app-name-0"
      )
  
      download_file = MagicMock()
      monkeypatch.setattr(cp, "_download_file", download_file)
  
      cp.cp("r:.", str(tmpdir))
  
      assert len(download_file.call_args_list) == 4
      for i, call in enumerate(download_file.call_args_list):
          assert call.args[0] == PosixPath(
              tmpdir / artifacts[i].filename
          )
          assert call.args[1] == artifacts[i].url
  
      # cleanup
      os.remove(_CD_FILE)
  
file_path: pytorch-lightning/tests/tests_app/cli/test_cp.py
imports: import os
  import sys
  from pathlib import PosixPath
  from unittest.mock import MagicMock
  import pytest
  from lightning.app.cli.commands import cp
  from lightning.app.cli.commands.cd import _CD_FILE, cd
  from lightning_cloud.openapi import Externalv1Cluster, Externalv1LightningappInstance, V1CloudSpace, V1ClusterDriver, V1ClusterSpec, V1GetClusterResponse, V1KubernetesClusterDriver, V1LightningappInstanceArtifact, V1LightningappInstanceSpec, V1ListCloudSpacesResponse, V1ListClustersResponse, V1ListLightningappInstanceArtifactsResponse, V1ListLightningappInstancesResponse, V1ListMembershipsResponse, V1ListProjectClusterBindingsResponse, V1Membership, V1ProjectClusterBinding, V1UploadProjectArtifactResponse
label_desc: Use image node_id 2 for calling a global function with example usage: test_cp_cloud_to_local(tmpdir, monkeypatch) without return types