code: def test_programmatic_lightningignore(monkeypatch, caplog, tmpdir):
      path = Path(tmpdir)
      entrypoint = path / "entrypoint.py"
      entrypoint.touch()
  
      mock_client = mock.MagicMock()
      mock_client.projects_service_list_memberships.return_value = (
          V1ListMembershipsResponse(
              memberships=[
                  V1Membership(
                      name="test-project", project_id="test-project-id"
                  )
              ]
          )
      )
      mock_client.lightningapp_instance_service_list_lightningapp_instances.return_value = V1ListLightningappInstancesResponse(
          lightningapps=[]
      )
      mock_client.cloud_space_service_create_lightning_run.return_value = V1LightningRun(
          cluster_id="test"
      )
      cloud_backend = mock.MagicMock(client=mock_client)
      monkeypatch.setattr(
          backends,
          "CloudBackend",
          mock.MagicMock(return_value=cloud_backend),
      )
  
      class MyWork(LightningWork):
          def __init__(self):
              super().__init__()
              self.lightningignore += ("foo", "lightning_logs")
  
          def run(self):
              with pytest.raises(
                  RuntimeError, match="w.lightningignore` does not"
              ):
                  self.lightningignore += ("foobar",)
  
      class MyFlow(LightningFlow):
          def __init__(self):
              super().__init__()
              self.lightningignore = ("foo",)
              self.w = MyWork()
  
          def run(self):
              with pytest.raises(
                  RuntimeError, match="root.lightningignore` does not"
              ):
                  self.lightningignore = ("baz",)
              self.w.run()
  
      flow = MyFlow()
      app = LightningApp(flow)
  
      monkeypatch.setattr(app, "_update_index_file", mock.MagicMock())
  
      cloud_runtime = cloud.CloudRuntime(app=app, entrypoint=entrypoint)
      monkeypatch.setattr(
          LocalSourceCodeDir, "upload", mock.MagicMock()
      )
  
      # write some files
      write_file_of_size(path / "a.txt", 5 * 1000 * 1000)
      write_file_of_size(path / "foo.png", 4 * 1000 * 1000)
      write_file_of_size(
          path / "lightning_logs" / "foo.ckpt", 6 * 1000 * 1000
      )
      # also an actual .lightningignore file
      (path / ".lightningignore").write_text("foo.png")
  
      with mock.patch(
          "lightning.app.runners.cloud._parse_lightningignore",
          wraps=_parse_lightningignore,
      ) as parse_mock, mock.patch(
          "lightning.app.source_code.local._copytree", wraps=_copytree
      ) as copy_mock, caplog.at_level(
          logging.WARN
      ):
          cloud_runtime.dispatch()
  
      parse_mock.assert_called_once_with(
          ("foo", "foo", "lightning_logs")
      )
      assert copy_mock.mock_calls[0].kwargs["ignore_functions"][0].args[
          1
      ] == {"lightning_logs", "foo"}
  
      assert (
          f"Your application folder '{path.absolute()}' is more than 2 MB"
          in caplog.text
      )
      assert "The total size is 5.0 MB" in caplog.text
      assert "2 files were uploaded"  # a.txt and .lightningignore
      assert (
          "files:\n5.0 MB: a.txt\nPerhaps" in caplog.text
      )  # only this file appears
  
      flow.run()
  
imports: import contextlib
  import logging
  import os
  import pathlib
  import re
  import sys
  from copy import copy
  from pathlib import Path
  from unittest import mock
  from unittest.mock import MagicMock
  import pytest
  from lightning.app import BuildConfig, LightningApp, LightningFlow, LightningWork
  from lightning.app.runners import CloudRuntime, backends, cloud
  from lightning.app.source_code.copytree import _copytree, _parse_lightningignore
  from lightning.app.source_code.local import LocalSourceCodeDir
  from lightning.app.storage import Drive, Mount
  from lightning.app.testing.helpers import EmptyWork
  from lightning.app.utilities.cloud import _get_project
  from lightning.app.utilities.dependency_caching import get_hash
  from lightning.app.utilities.packaging.cloud_compute import CloudCompute
  from lightning_cloud.openapi import CloudspaceIdRunsBody, Externalv1Cluster, Externalv1LightningappInstance, Gridv1ImageSpec, IdGetBody1, ProjectIdProjectclustersbindingsBody, V1BuildSpec, V1CloudSpace, V1CloudSpaceInstanceConfig, V1ClusterSpec, V1ClusterType, V1DataConnectionMount, V1DependencyFileInfo, V1Drive, V1DriveSpec, V1DriveStatus, V1DriveType, V1EnvVar, V1GetClusterResponse, V1GetUserResponse, V1LightningappInstanceSpec, V1LightningappInstanceState, V1LightningappInstanceStatus, V1LightningAuth, V1LightningBasicAuth, V1LightningRun, V1LightningworkDrives, V1LightningworkSpec, V1ListCloudSpacesResponse, V1ListClustersResponse, V1ListLightningappInstancesResponse, V1ListMembershipsResponse, V1ListProjectClusterBindingsResponse, V1Membership, V1Metadata, V1NetworkConfig, V1PackageManager, V1ProjectClusterBinding, V1PythonDependencyInfo, V1QueueServerType, V1SourceType, V1UserFeatures, V1UserRequestedComputeConfig, V1UserRequestedFlowComputeConfig, V1Work
label_desc: Use image node_id 12 for calling a global function with example usage: test_programmatic_lightningignore(monkeypatch, caplog, tmpdir) without return types