code: def test_sweep_scheduler_base_scheduler_states(
      user, relay_server, sweep_config, monkeypatch
  ):
      _patch_wandb_run(monkeypatch)
      with relay_server():
          _entity = user
          _project = "test-project"
          api = internal.Api()
          sweep_id = wandb.sweep(
              sweep_config, entity=_entity, project=_project
          )
  
          def mock_run_complete_scheduler(self, *args, **kwargs):
              self.state = SchedulerState.COMPLETED
  
          def mock_get_run_state(*args, **kwargs):
              if args[2] == "sweep-scheduler":
                  return "running"
              return "finished"
  
          api.get_run_state = mock_get_run_state
  
          monkeypatch.setattr(
              "wandb.sdk.launch.sweeps.scheduler.Scheduler._update_run_states",
              mock_run_complete_scheduler,
          )
  
          monkeypatch.setattr(
              "wandb.sdk.launch.sweeps.scheduler.Scheduler._try_load_executable",
              lambda _: True,
          )
  
          _scheduler = Scheduler(
              api, sweep_id=sweep_id, entity=_entity, project=_project
          )
          assert _scheduler.state == SchedulerState.PENDING
          assert _scheduler.is_alive is True
          _scheduler.start()
          assert _scheduler.state == SchedulerState.COMPLETED
          assert _scheduler.is_alive is False
  
          def mock_run_raise_keyboard_interupt(*args, **kwargs):
              raise KeyboardInterrupt
  
          monkeypatch.setattr(
              "wandb.sdk.launch.sweeps.scheduler.Scheduler._update_run_states",
              mock_run_raise_keyboard_interupt,
          )
  
          sweep_id = wandb.sweep(
              sweep_config, entity=_entity, project=_project
          )
          _scheduler = Scheduler(
              api, sweep_id=sweep_id, entity=_entity, project=_project
          )
          _scheduler.start()
          assert _scheduler.state == SchedulerState.STOPPED
          assert _scheduler.is_alive is False
  
          def mock_run_raise_exception(*args, **kwargs):
              raise Exception("Generic exception")
  
          sweep_id = wandb.sweep(
              sweep_config, entity=_entity, project=_project
          )
          _scheduler = Scheduler(
              api, sweep_id=sweep_id, entity=_entity, project=_project
          )
          _scheduler._update_run_states = mock_run_raise_exception
          with pytest.raises(Exception) as e:
              _scheduler.start()
          assert "Generic exception" in str(e.value)
          assert _scheduler.state == SchedulerState.FAILED
          assert _scheduler.is_alive is False
  
          def mock_run_exit(self, *args, **kwargs):
              self.exit()
  
          monkeypatch.setattr(
              "wandb.sdk.launch.sweeps.scheduler.Scheduler._update_run_states",
              mock_run_exit,
          )
  
          def mock_get_run_state(*args, **kwargs):
              if args[0] == "sweep-scheduler":
                  return "running"
              return "finished"
  
          sweep_id = wandb.sweep(
              sweep_config, entity=_entity, project=_project
          )
          _scheduler = Scheduler(
              api, sweep_id=sweep_id, entity=_entity, project=_project
          )
          _scheduler._get_run_state = mock_get_run_state
          _scheduler.start()
          assert _scheduler.state == SchedulerState.FAILED
          assert _scheduler.is_alive is False
  
imports: import asyncio
  from typing import Dict
  from unittest.mock import Mock, patch
  import pytest
  import wandb
  from wandb.apis import internal, public
  from wandb.errors import CommError
  from wandb.sdk.launch.sweeps import SchedulerError, load_scheduler
  from wandb.sdk.launch.sweeps.scheduler import RunState, Scheduler, SchedulerState, SweepRun
  from wandb.sdk.launch.sweeps.scheduler_sweep import SweepScheduler
  from wandb.sdk.launch.sweeps.utils import construct_scheduler_args
  from .test_wandb_sweep import VALID_SWEEP_CONFIGS_MINIMAL
label_desc: Use image node_id 8 for calling a global function with example usage: test_sweep_scheduler_base_scheduler_states(user, relay_server, sweep_config, monkeypatch) and returns: str, str, str, str