





import os
import shutil
import unittest
from unittest.mock import patch

from transformers.testing_utils import CaptureStd, is_pt_tf_cross_test, require_torch

class   __snake_case				(			unittest.TestCase   ):






    '''simple docstring'''





    @patch('''sys.argv'''			,						['''fakeprogrampath''', '''env''']							)
    def 	A		(   self						:		Optional[Any]							):

      """simple docstring"""





      import transformers.commands.transformers_cli

      with CaptureStd() as cs:
        transformers.commands.transformers_cli.main()
      self.assertIn('''Python version'''			,						cs.out							)
      self.assertIn('''Platform'''			,						cs.out							)
      self.assertIn('''Using distributed or parallel set-up in script?'''			,						cs.out							)





    @is_pt_tf_cross_test
    @patch(
        '''sys.argv'''			,						['''fakeprogrampath''', '''pt-to-tf''', '''--model-name''', '''hf-internal-testing/tiny-random-gptj''', '''--no-pr''']							)
    def 	A		(   self						:		List[Any]							):

      """simple docstring"""





      import transformers.commands.transformers_cli

      shutil.rmtree('''/tmp/hf-internal-testing/tiny-random-gptj'''			,						ignore_errors=snake_case							)  # cleans potential past runs
      transformers.commands.transformers_cli.main()

      # The original repo has no TF weights -- if they exist, they were created by the CLI
      self.assertTrue(os.path.exists('''/tmp/hf-internal-testing/tiny-random-gptj/tf_model.h5'''							)							)





    @require_torch
    @patch('''sys.argv'''			,						['''fakeprogrampath''', '''download''', '''hf-internal-testing/tiny-random-gptj''', '''--cache-dir''', '''/tmp''']							)
    def 	A		(   self						:		Any							):

      """simple docstring"""





      import transformers.commands.transformers_cli

      # # remove any previously downloaded model to start clean
      shutil.rmtree('''/tmp/models--hf-internal-testing--tiny-random-gptj'''			,						ignore_errors=snake_case							)

      # run the command
      transformers.commands.transformers_cli.main()

      # check if the model files are downloaded correctly on /tmp/models--hf-internal-testing--tiny-random-gptj
      self.assertTrue(os.path.exists('''/tmp/models--hf-internal-testing--tiny-random-gptj/blobs'''							)							)
      self.assertTrue(os.path.exists('''/tmp/models--hf-internal-testing--tiny-random-gptj/refs'''							)							)
      self.assertTrue(os.path.exists('''/tmp/models--hf-internal-testing--tiny-random-gptj/snapshots'''							)							)





    @require_torch
    @patch(
        '''sys.argv'''			,						[
            '''fakeprogrampath''',
            '''download''',
            '''hf-internal-testing/test_dynamic_model_with_tokenizer''',
            '''--trust-remote-code''',
            '''--cache-dir''',
            '''/tmp''',
        ]			,						)
    def 	A		(   self						:		Union[str, Any]							):

      """simple docstring"""





      import transformers.commands.transformers_cli

      # # remove any previously downloaded model to start clean
      shutil.rmtree('''/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer'''			,						ignore_errors=snake_case							)

      # run the command
      transformers.commands.transformers_cli.main()

      # check if the model files are downloaded correctly on /tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer
      self.assertTrue(os.path.exists('''/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer/blobs'''							)							)
      self.assertTrue(os.path.exists('''/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer/refs'''							)							)
      self.assertTrue(
          os.path.exists('''/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer/snapshots'''							)							)







class   __snake_case				:






    '''simple docstring'''





    def __init__(   self						:		Any							):

      """simple docstring"""





      __lowerCAmelCase			=				{}
      # indexmap keys are an index and it's values are the number at that index
      __lowerCAmelCase			=				{}





    def 	A		(   self						:		List[Any]			,						snake_case						:		list | str | range			,						snake_case						:		int							):

      """simple docstring"""





      if isinstance(snake_case			,						(range, str)							):
        __lowerCAmelCase			=				list(snake_case							)
      elif not isinstance(snake_case			,						snake_case							):
        raise TypeError(
            '''binary_search_delete() only accepts either a list, range or str'''							)

      __lowerCAmelCase			=				0
      __lowerCAmelCase			=				len(snake_case							) - 1

      while low <= high:
        __lowerCAmelCase			=				(low + high) // 2
        if array[mid] == item:
          array.pop(snake_case							)
          return array
        elif array[mid] < item:
          __lowerCAmelCase			=				mid + 1
        else:
          __lowerCAmelCase			=				mid - 1
      raise ValueError(
          '''Either the item is not in the array or the array was unsorted'''							)





    def 	A		(   self						:		Tuple			,						snake_case						:		list | str | range			,						snake_case						:		int							):

      """simple docstring"""





      if isinstance(snake_case			,						(range, str)							):
        __lowerCAmelCase			=				list(snake_case							)
      elif not isinstance(snake_case			,						snake_case							):
        raise TypeError(
            '''binary_search_insert() only accepts either a list, range or str'''							)

      __lowerCAmelCase			=				0
      __lowerCAmelCase			=				len(snake_case							) - 1

      while low <= high:
        __lowerCAmelCase			=				(low + high) // 2
        if array[mid] == index:
          # If the item already exists in the array,
          # insert it after the existing item
          array.insert(mid + 1			,						snake_case							)
          return array
        elif array[mid] < index:
          __lowerCAmelCase			=				mid + 1
        else:
          __lowerCAmelCase			=				mid - 1

        # If the item doesn't exist in the array, insert it at the appropriate position
      array.insert(snake_case			,						snake_case							)
      return array





    def 	A		(   self						:		Tuple			,						snake_case						:		int			,						snake_case						:		int							):

      """simple docstring"""





      if index in self.indexmap:
        __lowerCAmelCase			=				self.indexmap[index]
        if len(self.numbermap[n]							) == 1:
          del self.numbermap[n]
        else:
          __lowerCAmelCase			=				self.binary_search_delete(self.numbermap[n]			,						snake_case							)

        # Set new index
      __lowerCAmelCase			=				number

      # Number not seen before or empty so insert number value
      if number not in self.numbermap:
        __lowerCAmelCase			=				[index]

      # Here we need to perform a binary search insertion in order to insert
      # The item in the correct place
      else:
        __lowerCAmelCase			=				self.binary_search_insert(
            self.numbermap[number]			,						snake_case							)





    def 	A		(   self						:		List[str]			,						snake_case						:		int							):

      """simple docstring"""





      return self.numbermap.get(snake_case			,						[-1]							)[0]


if __name__ == "__main__":
      import doctest

      doctest.testmod()
