code: def test_init_errors(ray_start_4_cpus):
      from ray.train.mosaic import MosaicTrainer
  
      """Tests errors that may be raised when constructing MosaicTrainer. The error may
      be due to bad `trainer_init_per_worker` function or missing requirements in the
      `trainer_init_config` argument.
      """
  
      # invalid trainer init function -- no argument
      def bad_trainer_init_per_worker_1():
          pass
  
      trainer_init_config = {
          "max_duration": "1ba",
      }
  
      with pytest.raises(ValueError):
          _ = MosaicTrainer(
              trainer_init_per_worker=bad_trainer_init_per_worker_1,
              trainer_init_config=trainer_init_config,
              scaling_config=scaling_config,
          )
  
      # invalid trainer init function -- more than one argument
      def bad_trainer_init_per_worker_1(a, b):
          pass
  
      with pytest.raises(ValueError):
          _ = MosaicTrainer(
              trainer_init_per_worker=bad_trainer_init_per_worker_1,
              trainer_init_config=trainer_init_config,
              scaling_config=scaling_config,
          )
  
      # datasets is not supported
      with pytest.raises(
          ValueError, match=r".*dataset shards.*`prepare_dataloader`.*"
      ):
          _ = MosaicTrainer(
              trainer_init_per_worker=trainer_init_per_worker,
              trainer_init_config=trainer_init_config,
              scaling_config=scaling_config,
              datasets={"train": [1]},
          )
  
file_path: ray/python/ray/train/tests/test_mosaic_trainer.py
imports: import os
  import pytest
  import torch
  import torch.utils.data
  import torchvision
  from filelock import FileLock
  from torchvision import datasets, transforms
  import ray.train
  from ray.train import ScalingConfig
  from ray.train.trainer import TrainingFailedError
label_desc: Use image node_id 2 for calling a global function with example usage: test_init_errors(ray_start_4_cpus) without return types