code: def test_rich_progress_bar_keyboard_interrupt(tmp_path):
      """Test to ensure that when the user keyboard interrupts, we close the progress bar."""
  
      class TestModel(BoringModel):
          def on_train_start(self) -> None:
              raise KeyboardInterrupt
  
      model = TestModel()
  
      with mock.patch(
          "lightning.pytorch.callbacks.progress.rich_progress.Progress.stop",
          autospec=True,
      ) as mock_progress_stop:
          progress_bar = RichProgressBar()
          trainer = Trainer(
              default_root_dir=tmp_path,
              fast_dev_run=True,
              callbacks=progress_bar,
          )
  
          trainer.fit(model)
      mock_progress_stop.assert_called_once()
  
imports: import pickle
  from collections import defaultdict
  from unittest import mock
  from unittest.mock import DEFAULT, Mock
  import pytest
  from lightning.pytorch import Trainer
  from lightning.pytorch.callbacks import ProgressBar, RichProgressBar
  from lightning.pytorch.callbacks.progress.rich_progress import RichProgressBarTheme
  from lightning.pytorch.demos.boring_classes import BoringModel, RandomDataset, RandomIterableDataset
  from lightning.pytorch.loggers import CSVLogger
  from lightning.pytorch.loggers.logger import DummyLogger
  from tests_pytorch.helpers.runif import RunIf
  from torch.utils.data import DataLoader
label_desc: Use image node_id 6 for calling a global function with example usage: test_rich_progress_bar_keyboard_interrupt(tmp_path) without return types