# Path: xmanager/cloud/utils.py
# def get_master_address_port() -> Tuple[str, str]:
# def get_world_size_rank() -> Tuple[int, int]:
# def create_cluster_specs(workers: Sequence[str]) -> List[str]:
# def get_workerpool_address(workerpool: str) -> str:
# def map_workerpool_address_args(args: List[str]) -> List[str]:
# def print_workerpool_address_args(argv: List[str]) -> None:
# def create_workerpool_address_env_vars_script(path: str) -> None:
# def get_region() -> str:
# def get_closest_bucket(bucket_names: List[str]) -> str:


import os
import tempfile
import unittest
from xmanager.cloud import utils
    self.assertEqual(port, '2222')

  def test_get_master_address_port_default(self):
    address, port = utils.get_master_address_port()
    self.assertEqual(address, '127.0.0.1')
    self.assertEqual(port, '29500')

  def test_get_world_size_rank(self):
    os.environ['CLUSTER_SPEC'] = _CLUSTER_SPEC
    world_size, rank = utils.get_world_size_rank()
    self.assertEqual(world_size, 5)
    self.assertEqual(rank, 2)

  def test_get_world_size_rank_default(self):
    world_size, rank = utils.get_world_size_rank()
    self.assertEqual(world_size, 1)
    self.assertEqual(rank, 0)

  def test_wrap_and_unwrap_addresses(self):
    arg = '--master=' + utils.get_workerpool_address('workerpool0')
    self.assertEqual(arg, '--master=%objectname(workerpool0)%')
    os.environ['CLUSTER_SPEC'] = _CLUSTER_SPEC
    self.assertEqual(
        utils.map_workerpool_address_args([arg]),
        ['--master=cmle-training-workerpool0-ab-0:2222'])

  def test_create_workerpool_address_env_vars_script(self):
    os.environ['MY_WORKER'] = utils.get_workerpool_address('workerpool0')
    os.environ['CLUSTER_SPEC'] = _CLUSTER_SPEC
    t = tempfile.NamedTemporaryFile()

# Path: xmanager/cloud/utils.py
# def get_master_address_port() -> Tuple[str, str]:
# def get_world_size_rank() -> Tuple[int, int]:
# def create_cluster_specs(workers: Sequence[str]) -> List[str]:
# def get_workerpool_address(workerpool: str) -> str:
# def map_workerpool_address_args(args: List[str]) -> List[str]:
# def print_workerpool_address_args(argv: List[str]) -> None:
# def create_workerpool_address_env_vars_script(path: str) -> None:
# def get_region() -> str:
# def get_closest_bucket(bucket_names: List[str]) -> str:


# Path: xmanager/cloud/utils_test.py
import os
import tempfile
import unittest
from xmanager.cloud import utils

    self.assertEqual(port, '2222')

  def test_get_master_address_port_default(self):
    address, port = utils.get_master_address_port()
    self.assertEqual(address, '127.0.0.1')
    self.assertEqual(port, '29500')

  def test_get_world_size_rank(self):
    os.environ['CLUSTER_SPEC'] = _CLUSTER_SPEC
    world_size, rank = utils.get_world_size_rank()
    self.assertEqual(world_size, 5)
    self.assertEqual(rank, 2)

  def test_get_world_size_rank_default(self):
    world_size, rank = utils.get_world_size_rank()
    self.assertEqual(world_size, 1)
    self.assertEqual(rank, 0)

  def test_wrap_and_unwrap_addresses(self):
    arg = '--master=' + utils.get_workerpool_address('workerpool0')
    self.assertEqual(arg, '--master=%objectname(workerpool0)%')
    os.environ['CLUSTER_SPEC'] = _CLUSTER_SPEC
    self.assertEqual(
        utils.map_workerpool_address_args([arg]),
        ['--master=cmle-training-workerpool0-ab-0:2222'])

  def test_create_workerpool_address_env_vars_script(self):
    os.environ['MY_WORKER'] = utils.get_workerpool_address('workerpool0')
    os.environ['CLUSTER_SPEC'] = _CLUSTER_SPEC
    t = tempfile.NamedTemporaryFile()

    utils.create_workerpool_address_env_vars_script(t.name)