# Path: xmanager/xm/id_predictor.py
# class BrokenSequenceError(RuntimeError):
# class Predictor:
#   def __init__(self, next_id: int) -> None:
#   def reserve_id(self) -> int:
#   async def submit_id(self, id_to_submit: int) -> AsyncIterable[None]:
# 
# Path: xmanager/xm/utils.py
# FLAGS = flags.FLAGS
# ARG_ESCAPER = pattern_matching.match(
#     pattern_matching.Case([ShellSafeArg], lambda v: v.arg),
#     pattern_matching.Case([enum.Enum], lambda v: shlex.quote(str(v.name))),
#     pattern_matching.Case([Any], lambda v: shlex.quote(str(v))),
# )
# class SpecialArg(abc.ABC):
# class ShellSafeArg(SpecialArg):
# def trivial_kwargs_joiner(key: str, value: str) -> str:
# def run_in_asyncio_loop(
#     f: Callable[..., ReturnType]) -> Callable[..., ReturnType]:
#   def decorated(*args, **kwargs) -> ReturnType:
# def find_launch_script_path() -> str:
# def resolve_path_relative_to_launcher(path: str) -> str:


import asyncio
import unittest
from xmanager.xm import id_predictor
from xmanager.xm import utils
# Copyright 2021 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




class IdPredictorTest(unittest.TestCase):

  @utils.run_in_asyncio_loop
  async def test_first_id_is_correct(self):
    """Simple Predictor usage example."""
    predictor = id_predictor.Predictor(next_id=1)

    first_id = predictor.reserve_id()
    async with predictor.submit_id(first_id):
      self.assertEqual(first_id, 1)

  @utils.run_in_asyncio_loop
  async def test_ids_are_submitted_in_order(self):

# Path: xmanager/xm/id_predictor.py
# class BrokenSequenceError(RuntimeError):
# class Predictor:
#   def __init__(self, next_id: int) -> None:
#   def reserve_id(self) -> int:
#   async def submit_id(self, id_to_submit: int) -> AsyncIterable[None]:
# 
# Path: xmanager/xm/utils.py
# FLAGS = flags.FLAGS
# ARG_ESCAPER = pattern_matching.match(
#     pattern_matching.Case([ShellSafeArg], lambda v: v.arg),
#     pattern_matching.Case([enum.Enum], lambda v: shlex.quote(str(v.name))),
#     pattern_matching.Case([Any], lambda v: shlex.quote(str(v))),
# )
# class SpecialArg(abc.ABC):
# class ShellSafeArg(SpecialArg):
# def trivial_kwargs_joiner(key: str, value: str) -> str:
# def run_in_asyncio_loop(
#     f: Callable[..., ReturnType]) -> Callable[..., ReturnType]:
#   def decorated(*args, **kwargs) -> ReturnType:
# def find_launch_script_path() -> str:
# def resolve_path_relative_to_launcher(path: str) -> str:


# Path: xmanager/xm/id_predictor_test.py
import asyncio
import unittest
from xmanager.xm import id_predictor
from xmanager.xm import utils

# Copyright 2021 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




class IdPredictorTest(unittest.TestCase):

  @utils.run_in_asyncio_loop
  async def test_first_id_is_correct(self):
    """Simple Predictor usage example."""
    predictor = id_predictor.Predictor(next_id=1)

    first_id = predictor.reserve_id()
    async with predictor.submit_id(first_id):
      self.assertEqual(first_id, 1)

  @utils.run_in_asyncio_loop
  async def test_ids_are_submitted_in_order(self):

    predictor = id_predictor.Predictor(next_id=1)