





'''simple docstring'''






import argparse
import os

from accelerate.test_utils import execute_subprocess_async
def    UpperCamelCase__      (		lowerCAmelCase=None  ):





      """simple docstring"""


      if subparsers is not None:
            _lowerCAmelCase							     =							subparsers.add_parser("""test"""  )
      else:
            _lowerCAmelCase							     =							argparse.ArgumentParser("""Accelerate test command"""  )

      parser.add_argument(
          """--config_file"""							,	default=_lowercase							,	help=(
              """The path to use to store the config file. Will default to a file named default_config.yaml in the cache """
              """location, which is the content of the environment `HF_HOME` suffixed with 'accelerate', or if you don't have """
              """such an environment variable, your cache directory ('~/.cache' or the content of `XDG_CACHE_HOME`) suffixed """
              """with 'huggingface'."""
          )							,	)

      if subparsers is not None:
            parser.set_defaults(func=_lowercase  )
      return parser
def    UpperCamelCase__      (		lowerCAmelCase  ):





      """simple docstring"""


      _lowerCAmelCase							     =							os.path.sep.join(__file__.split(os.path.sep  )[:-2] + ["""test_utils""", """scripts""", """test_script.py"""]  )

      if args.config_file is None:
            _lowerCAmelCase							     =							script_name
      else:
            _lowerCAmelCase							     =							f"--config_file={args.config_file} {script_name}"

      _lowerCAmelCase							     =							["accelerate-launch"] + test_args.split()
      _lowerCAmelCase							     =							execute_subprocess_async(_lowercase							,	env=os.environ.copy()  )
      if result.returncode == 0:
            print("""Test is a success! You are ready for your distributed training!"""  )
def    UpperCamelCase__      (		):





      """simple docstring"""


      _lowerCAmelCase							     =							test_command_parser()
      _lowerCAmelCase							     =							parser.parse_args()
      test_command(_lowercase  )


if __name__ == "__main__":
      main()













"""simple docstring"""




from unittest.mock import Mock, patch

from file_transfer.send_file import send_file






@patch("socket.socket"					)
@patch("builtins.open"					)
def       _SCREAMING_SNAKE_CASE		(	_lowercase						:    List[Any]    ,       _lowercase						:    int					) ->str:






	'''simple docstring'''






	a      :		Optional[Any]	=				Mock()
	a      :		Dict	=				conn, Mock()
	a      :		Union[str, Any]	=				iter([1, None]					)
	a      :		Optional[int]	=				lambda _lowercase					: next(_lowercase					)

	# ===== invoke =====
	send_file(filename="mytext.txt"    ,       testing=_lowercase					)

	# ===== ensurance =====
	sock.assert_called_once()
	sock.return_value.bind.assert_called_once()
	sock.return_value.listen.assert_called_once()
	sock.return_value.accept.assert_called_once()
	conn.recv.assert_called_once()

	file.return_value.__enter__.assert_called_once()
	file.return_value.__enter__.return_value.read.assert_called()

	conn.send.assert_called_once()
	conn.close.assert_called_once()
	sock.return_value.shutdown.assert_called_once()
	sock.return_value.close.assert_called_once()


