import importlib
import os
import sys


# This is required to make the module import works (when the python process is running from the root of the repo)
sys.path.append('.')







def       A__   (						snake_case_			:		Union[str, Any]   ):
 SCREAMING_SNAKE_CASE__: Dict=   test_file.split(os.path.sep   )
 if components[0:2] != ["tests", "models"]:
  raise ValueError(
      '''`test_file` should start with `tests/models/` (with `/` being the OS specific path separator). Got '''
      F'{test_file} instead.'   )
 SCREAMING_SNAKE_CASE__: Optional[int]=   components[-1]
 if not test_fn.endswith('''py'''   ):
  raise ValueError(F'`test_file` should be a python file. Got {test_fn} instead.'   )
 if not test_fn.startswith('''test_modeling_'''   ):
  raise ValueError(
      F'`test_file` should point to a file name of the form `test_modeling_*.py`. Got {test_fn} instead.'   )

 SCREAMING_SNAKE_CASE__: int=   components[:-1] + [test_fn.replace('''.py'''							,					''''''   )]
 SCREAMING_SNAKE_CASE__: List[str]=   '''.'''.join(snake_case_   )

 return test_module_path







def       A__   (						snake_case_			:		Dict   ):
 SCREAMING_SNAKE_CASE__: Dict=   get_module_path(snake_case_   )
 SCREAMING_SNAKE_CASE__: int=   importlib.import_module(snake_case_   )

 return test_module







def       A__   (						snake_case_			:		List[str]   ):
 SCREAMING_SNAKE_CASE__: Any=   []
 SCREAMING_SNAKE_CASE__: Optional[Any]=   get_test_module(snake_case_   )
 for attr in dir(snake_case_   ):
  if attr.endswith('''ModelTester'''   ):
   tester_classes.append(getattr(snake_case_							,					snake_case_   )   )

    # sort with class names
 return sorted(snake_case_							,					key=lambda snake_case_   : x.__name__   )







def       A__   (						snake_case_			:		Union[str, Any]   ):
 SCREAMING_SNAKE_CASE__: Union[str, Any]=   []
 SCREAMING_SNAKE_CASE__: Dict=   get_test_module(snake_case_   )
 for attr in dir(snake_case_   ):
  SCREAMING_SNAKE_CASE__: str=   getattr(snake_case_							,					snake_case_   )
  # (TF/Flax)ModelTesterMixin is also an attribute in specific model test module. Let's exclude them by checking
  # `all_model_classes` is not empty (which also excludes other special classes).
  SCREAMING_SNAKE_CASE__: List[Any]=   getattr(snake_case_							,					'''all_model_classes'''							,					[]   )
  if len(snake_case_   ) > 0:
   test_classes.append(snake_case_   )

    # sort with class names
 return sorted(snake_case_							,					key=lambda snake_case_   : x.__name__   )







def       A__   (						snake_case_			:		int   ):
 SCREAMING_SNAKE_CASE__: List[str]=   get_test_classes(snake_case_   )
 SCREAMING_SNAKE_CASE__: Optional[int]=   set()
 for test_class in test_classes:
  model_classes.update(test_class.all_model_classes   )

 # sort with class names
 return sorted(snake_case_							,					key=lambda snake_case_   : x.__name__   )







def       A__   (						snake_case_			:		str   ):
 SCREAMING_SNAKE_CASE__: Tuple=   test_class()
 if hasattr(snake_case_							,					'''setUp'''   ):
  test.setUp()

 SCREAMING_SNAKE_CASE__: List[str]=   None
 if hasattr(snake_case_							,					'''model_tester'''   ):
  # `(TF/Flax)ModelTesterMixin` has this attribute default to `None`. Let's skip this case.
  if test.model_tester is not None:
   SCREAMING_SNAKE_CASE__: List[Any]=   test.model_tester.__class__

 return model_tester







def       A__   (						snake_case_			:		List[Any]							,					snake_case_			:		List[str]   ):
 SCREAMING_SNAKE_CASE__: Tuple=   get_test_classes(snake_case_   )

 SCREAMING_SNAKE_CASE__: Dict=   []
 for test_class in test_classes:
  if model_class in test_class.all_model_classes:
   target_test_classes.append(snake_case_   )

    # sort with class names
 return sorted(snake_case_							,					key=lambda snake_case_   : x.__name__   )







def       A__   (						snake_case_			:		Dict							,					snake_case_			:		Dict   ):
 SCREAMING_SNAKE_CASE__: str=   get_test_classes_for_model(snake_case_							,					snake_case_   )

 SCREAMING_SNAKE_CASE__: Union[str, Any]=   []
 for test_class in test_classes:
  SCREAMING_SNAKE_CASE__: Optional[Any]=   get_model_tester_from_test_class(snake_case_   )
  if tester_class is not None:
   tester_classes.append(snake_case_   )

    # sort with class names
 return sorted(snake_case_							,					key=lambda snake_case_   : x.__name__   )







def       A__   (						snake_case_			:		Optional[Any]   ):
 SCREAMING_SNAKE_CASE__: List[str]=   get_test_classes(snake_case_   )
 SCREAMING_SNAKE_CASE__: Optional[int]=   {test_class: get_model_tester_from_test_class(snake_case_   ) for test_class in test_classes}
 return test_tester_mapping







def       A__   (						snake_case_			:		Optional[int]   ):
 SCREAMING_SNAKE_CASE__: List[str]=   get_model_classes(snake_case_   )
 SCREAMING_SNAKE_CASE__: Any=   {
     model_class: get_test_classes_for_model(snake_case_							,					snake_case_   ) for model_class in model_classes
 }
 return model_test_mapping







def       A__   (						snake_case_			:		Dict   ):
 SCREAMING_SNAKE_CASE__: int=   get_model_classes(snake_case_   )
 SCREAMING_SNAKE_CASE__: List[str]=   {
     model_class: get_tester_classes_for_model(snake_case_							,					snake_case_   ) for model_class in model_classes
 }
 return model_to_tester_mapping







def       A__   (						snake_case_			:		Union[str, Any]   ):
 if isinstance(snake_case_							,					snake_case_   ):
  return o
 elif isinstance(snake_case_							,					snake_case_   ):
  return o.__name__
 elif isinstance(snake_case_							,					(list, tuple)   ):
  return [to_json(snake_case_   ) for x in o]
 elif isinstance(snake_case_							,					snake_case_   ):
  return {to_json(snake_case_   ): to_json(snake_case_   ) for k, v in o.items()}
 else:
  return o









'''simple docstring'''



__UpperCamelCase   :							List[Any]         =   """ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"""



def  __UpperCAmelCase						(					SCREAMING_SNAKE_CASE__:						bytes     )	->      bytes:

   """simple docstring"""
   # Make sure the supplied data is a bytes-like object
   if not isinstance(SCREAMING_SNAKE_CASE__,       SCREAMING_SNAKE_CASE__     ):
      __a					  =     f"""a bytes-like object is required, not '{data.__class__.__name__}'"""
      raise TypeError(SCREAMING_SNAKE_CASE__     )

   __a					  =     ''.join(bin(SCREAMING_SNAKE_CASE__     )[2:].zfill(8     ) for byte in data     )

   __a					  =     len(SCREAMING_SNAKE_CASE__     ) % 6 != 0

   if padding_needed:
      # The padding that will be added later
      __a					  =     b'=' * ((6 - len(SCREAMING_SNAKE_CASE__     ) % 6) // 2)

      # Append binary_stream with arbitrary binary digits (0's by default) to make its
      # length a multiple of 6.
      binary_stream += "0" * (6 - len(SCREAMING_SNAKE_CASE__     ) % 6)
   else:
      __a					  =     b''

   # Encode every 6 binary digits to their corresponding Base64 character
   return (
       "".join(
           B64_CHARSET[int(binary_stream[index : index + 6],       2     )]
           for index in range(0,       len(SCREAMING_SNAKE_CASE__     ),       6     )     ).encode()
       + padding
   )



def  __UpperCAmelCase						(					SCREAMING_SNAKE_CASE__:						str     )	->      bytes:

   """simple docstring"""
   # Make sure encoded_data is either a string or a bytes-like object
   if not isinstance(SCREAMING_SNAKE_CASE__,       SCREAMING_SNAKE_CASE__     ) and not isinstance(SCREAMING_SNAKE_CASE__,       SCREAMING_SNAKE_CASE__     ):
      __a					  =     (
          'argument should be a bytes-like object or ASCII string, '
          f"""not '{encoded_data.__class__.__name__}'"""
      )
      raise TypeError(SCREAMING_SNAKE_CASE__     )

   # In case encoded_data is a bytes-like object, make sure it contains only
   # ASCII characters so we convert it to a string object
   if isinstance(SCREAMING_SNAKE_CASE__,       SCREAMING_SNAKE_CASE__     ):
      try:
         __a					  =     encoded_data.decode('utf-8'     )
      except UnicodeDecodeError:
         raise ValueError('base64 encoded data should only contain ASCII characters'     )

   __a					  =     encoded_data.count('='     )

   # Check if the encoded string contains non base64 characters
   if padding:
      assert all(
          char in B64_CHARSET for char in encoded_data[:-padding]     ), "Invalid base64 character(s) found."
   else:
      assert all(
          char in B64_CHARSET for char in encoded_data     ), "Invalid base64 character(s) found."

   # Check the padding
   assert len(SCREAMING_SNAKE_CASE__     ) % 4 == 0 and padding < 3, "Incorrect padding"

   if padding:
      # Remove padding if there is one
      __a					  =     encoded_data[:-padding]

      __a					  =     ''.join(
          bin(B64_CHARSET.index(SCREAMING_SNAKE_CASE__     )     )[2:].zfill(6     ) for char in encoded_data     )[: -padding * 2]
   else:
      __a					  =     ''.join(
          bin(B64_CHARSET.index(SCREAMING_SNAKE_CASE__     )     )[2:].zfill(6     ) for char in encoded_data     )

   __a					  =     [
       int(binary_stream[index : index + 8],       2     )
       for index in range(0,       len(SCREAMING_SNAKE_CASE__     ),       8     )
   ]

   return bytes(SCREAMING_SNAKE_CASE__     )


if __name__ == "__main__":
 import doctest

 doctest.testmod()