code: def test_repository_lightningignore_unpackage(tmp_path, monkeypatch):
      """.lightningignore behaves similarly to the gitignore standard."""
      lorem_ipsum = (
          "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
      )
  
      cache_path = tmp_path / "cache"
      source_path = tmp_path / "source"
      source_path.mkdir()
  
      # set cache location to temp dir
  
      lightningignore = """
      # Ignore on all levels
      *.pyc
      *__pycache__/
      build/
      .env
      # Ignore wildcard on one level
      ./*.txt
      /*.md
      ./one-level/*.txt
      /one-level/*.md
      # Ignore only relative
      ./downloads
      /relative_downloads
      # nested
      /nested//level/
      /nested/level/
      """
      (source_path / ".lightningignore").write_text(lightningignore)
  
      # Dir structure
      (source_path / "include.py").write_text(lorem_ipsum)
      (source_path / "exclude.pyc").write_text(lorem_ipsum)
      (source_path / "__pycache__").mkdir()
      (source_path / "__pycache__" / "exclude.py").write_text(
          lorem_ipsum
      )  # Even tho it's .py it's in excluded __pycache__ directory
      (source_path / "__pycache__" / "exclude.pyc").write_text(
          lorem_ipsum
      )  # Even tho it's .py it's in excluded __pycache__ directory
      (source_path / "build.py").write_text(
          lorem_ipsum
      )  # Common prefix with excluded build but it's not it
      (
          source_path / "builds"
      ).mkdir()  # Common prefix with excluded build but it's not excluded
      (source_path / "builds" / "include.py").write_text(lorem_ipsum)
      (
          source_path / "builds" / "__pycache__"
      ).mkdir()  # Recursively excluded
      (
          source_path / "builds" / "__pycache__" / "exclude.py"
      ).write_text(lorem_ipsum)
      (source_path / "build").mkdir()  # Recursively excluded
      (source_path / "build" / "exclude.db").write_text(lorem_ipsum)
      (source_path / ".env").write_text(
          lorem_ipsum
      )  # No issues with handling hidden (.dot) files
      (source_path / "downloads").mkdir()  # exclude
      (source_path / "downloads" / "something.jpeg").write_text(
          lorem_ipsum
      )
      (source_path / "relative_downloads").mkdir()  # exclude
      (
          source_path / "relative_downloads" / "something.jpeg"
      ).write_text(lorem_ipsum)
      (source_path / "include").mkdir()  # include
      (source_path / "include" / "exclude.pyc").write_text(
          lorem_ipsum
      )  # exclude because of *.pyc rule
      (source_path / "include" / "include.py").write_text(
          lorem_ipsum
      )  # include
      (
          source_path / "include" / "downloads"
      ).mkdir()  # include because it was excluded only relative to root
      (
          source_path / "include" / "downloads" / "something.jpeg"
      ).write_text(lorem_ipsum)
      (
          source_path / "include" / "relative_downloads"
      ).mkdir()  # include because it was excluded only relative to root
      (
          source_path
          / "include"
          / "relative_downloads"
          / "something.jpeg"
      ).write_text(lorem_ipsum)
      (source_path / "exclude.txt").write_text(lorem_ipsum)
      (source_path / "exclude.md").write_text(lorem_ipsum)
      (source_path / "one-level").mkdir()
      (source_path / "one-level" / "exclude.txt").write_text(
          lorem_ipsum
      )
      (source_path / "one-level" / "exclude.md").write_text(lorem_ipsum)
      (source_path / "one-level" / "include.py").write_text(lorem_ipsum)
      (source_path / "nested").mkdir()
      (source_path / "nested" / "include.py").write_text(lorem_ipsum)
      (source_path / "nested" / "level").mkdir()
      (source_path / "nested" / "level" / "exclude.py").write_text(
          lorem_ipsum
      )
  
      # create repo object
      repository = LocalSourceCodeDir(path=source_path)
      repository.cache_location = cache_path
      repository.package()
  
      unpackage_path = tmp_path / "unpackage"
  
      with tarfile.open(repository.package_path) as f:
          f.extractall(unpackage_path)
  
      assert (unpackage_path / "include.py").exists()
      assert not (
          unpackage_path / "exclude.pyc"
      ).exists()  # Excluded by *.pyc
      assert not (unpackage_path / "__pycache__").exists()
      assert not (
          unpackage_path / "__pycache__" / "exclude.py"
      ).exists()  # Even tho it's .py it's in excluded __pycache__ directory
      assert not (
          unpackage_path / "__pycache__" / "exclude.pyc"
      ).exists()  # Even tho it's .py it's in excluded __pycache__ directory
      assert (
          unpackage_path / "build.py"
      ).exists()  # Common prefix with excluded build but it's not it
      assert (unpackage_path / "builds" / "include.py").exists()
      assert not (
          unpackage_path / "builds" / "__pycache__"
      ).exists()  # Recursively excluded
      assert not (
          unpackage_path / "builds" / "__pycache__" / "exclude.py"
      ).exists()
      assert not (
          unpackage_path / "build"
      ).exists()  # Recursively excluded
      assert not (unpackage_path / "build" / "exclude.db").exists()
      assert not (
          unpackage_path / ".env"
      ).exists()  # No issues with handling hidden (.dot) files
      assert not (unpackage_path / "downloads").mkdir()  # exclude
      assert not (
          unpackage_path / "downloads" / "something.jpeg"
      ).exists()
      assert not (
          unpackage_path / "relative_downloads"
      ).mkdir()  # exclude
      assert not (
          unpackage_path / "relative_downloads" / "something.jpeg"
      ).exists()
      assert not (
          unpackage_path / "include" / "exclude.pyc"
      ).exists()  # exclude because of *.pyc rule
      assert (
          unpackage_path / "include" / "include.py"
      ).exists()  # include
      assert (
          unpackage_path / "include" / "downloads" / "something.jpeg"
      ).exists()  # include because it was excluded only relative to root
      assert (
          unpackage_path
          / "include"
          / "relative_downloads"
          / "something.jpeg"
      ).exists()  # include because it was excluded only relative to root
      assert not (unpackage_path / "exclude.txt").exists()
      assert not (unpackage_path / "exclude.md").exists()
      assert not (unpackage_path / "one-level" / "exclude.txt").exists()
      assert not (unpackage_path / "one-level" / "exclude.md").exists()
      assert (unpackage_path / "one-level" / "include.py").exists()
      assert (unpackage_path / "nested" / "include.py").exists()
      assert not (
          unpackage_path / "nested" / "level" / "exclude.py"
      ).exists()
  
file_path: pytorch-lightning/tests/tests_app/source_code/test_local.py
imports: import os
  import sys
  import tarfile
  import uuid
  from pathlib import Path
  from unittest import mock
  import pytest
  from lightning.app.source_code import LocalSourceCodeDir
label_desc: Use image node_id 8 for calling a global function with example usage: test_repository_lightningignore_unpackage(tmp_path, monkeypatch) without return types