code: def mock_sagemaker(mocker):
      env = {}
      config_path = "/opt/ml/input/config/hyperparameters.json"
      resource_path = "/opt/ml/input/config/resourceconfig.json"
      secrets_path = "secrets.env"
      env["TRAINING_JOB_NAME"] = "sage"
      env["CURRENT_HOST"] = "maker"
  
      orig_exist = os.path.exists
  
      def exists(path):
          if path in (config_path, secrets_path, resource_path):
              return True
          else:
              return orig_exist(path)
  
      mocker.patch("wandb.util.os.path.exists", exists)
  
      def magic_factory(original):
          def magic(path, *args, **kwargs):
              if path == config_path:
                  return io.StringIO('{"foo": "bar"}')
              elif path == resource_path:
                  return io.StringIO('{"hosts":["a", "b"]}')
              elif path == secrets_path:
                  return io.StringIO("WANDB_TEST_SECRET=TRUE")
              else:
                  return original(path, *args, **kwargs)
  
          return magic
  
      mocker.patch("builtins.open", magic_factory(open), create=True)
      return env
  
file_path: wandb/tests/pytest_tests/unit_tests_old/utils/utils.py
imports: import io
  import os
  import shutil
  import socket
  from typing import Union
label_desc: Use image node_id 12 for calling a global function with example usage: mock_sagemaker(mocker) and returns: env, magic, True, orig_exist, io, io, io, original