code: def test_train_local_intermediate_output(
      get_data_source_instance, tmpdir, sagemaker_session
  ):
      data_source = Mock()
      data_source.get_root_dir.return_value = "foo"
      get_data_source_instance.return_value = data_source
  
      directories = [
          str(tmpdir.mkdir("container-root")),
          str(tmpdir.mkdir("data")),
      ]
      with patch(
          "sagemaker.local.image._SageMakerContainer._create_tmp_folder",
          side_effect=directories,
      ):
          instance_count = 2
          image = "my-image"
          sagemaker_container = _SageMakerContainer(
              "local",
              instance_count,
              image,
              sagemaker_session=sagemaker_session,
          )
  
          output_path = str(
              tmpdir.mkdir("customer_intermediate_output")
          )
          output_data_config = {
              "S3OutputPath": "file://%s" % output_path
          }
          hyperparameters = {"sagemaker_s3_output": output_path}
  
          sagemaker_container.train(
              INPUT_DATA_CONFIG,
              output_data_config,
              hyperparameters,
              ENVIRONMENT,
              TRAINING_JOB_NAME,
          )
  
          docker_compose_file = os.path.join(
              sagemaker_container.container_root, "docker-compose.yaml"
          )
          intermediate_folder_path = os.path.join(
              output_path, "output/intermediate"
          )
  
          with open(docker_compose_file, "r") as f:
              config = yaml.load(f, Loader=yaml.SafeLoader)
              assert len(config["services"]) == instance_count
              for h in sagemaker_container.hosts:
                  assert config["services"][h]["image"] == image
                  assert config["services"][h]["command"] == "train"
                  volumes = config["services"][h]["volumes"]
                  volumes = [
                      v[:-2] if v.endswith(":z") else v for v in volumes
                  ]
                  assert (
                      "%s:/opt/ml/output/intermediate"
                      % intermediate_folder_path
                      in volumes
                  )
  
imports: from __future__ import absolute_import
  import random
  import string
  from botocore.credentials import Credentials
  import base64
  import logging
  import json
  import os
  import subprocess
  import tarfile
  import pytest
  import yaml
  from mock import patch, Mock, MagicMock, mock_open, call
  import sagemaker
  from sagemaker.local.image import _SageMakerContainer, _Volume, _aws_credentials
  from sagemaker.local.utils import STUDIO_APP_TYPES
label_desc: Use image node_id 18 for calling a global function with example usage: test_train_local_intermediate_output(get_data_source_instance, tmpdir, sagemaker_session) without return types