


'''simple docstring'''



import copy
import os
import tempfile
from unittest import TestCase
from unittest.mock import patch

import numpy as np
import pyarrow as pa
import pyarrow.parquet as pq
import pytest

from datasets.arrow_writer import ArrowWriter, OptimizedTypedSequence, ParquetWriter, TypedSequence
from datasets.features import ArrayaD, ClassLabel, Features, Image, Value
from datasets.features.features import ArrayaDExtensionType, cast_to_python_objects
from datasets.keyhash import DuplicatedKeysError, InvalidKeyError

from .utils import require_pil





class 							__UpperCamelCase				(		lowerCAmelCase_					):




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Tuple					    =  pa.array(TypedSequence([1, 2, 3]							)							)
						self.assertEqual(arr.type						,				pa.intaa()							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						with self.assertRaises(__a							):
											__a			:       Any					    =  pa.array(TypedSequence([1, 2, 3]							)						,				type=pa.intaa()							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						with self.assertRaises(__a							):
											__a			:       Optional[Any]					    =  pa.array(TypedSequence([1, 2, 3]						,				try_type=Value('bool'							)						,				type=Value('int64'							)							)							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Union[str, Any]					    =  pa.array(TypedSequence([1, 2, 3]						,				type=Value('int32'							)							)							)
						self.assertEqual(arr.type						,				pa.intaa()							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						with self.assertRaises((TypeError, pa.lib.ArrowInvalid)							):
											__a			:       Union[str, Any]					    =  pa.array(TypedSequence(['foo', 'bar']						,				type=Value('int64'							)							)							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Optional[Any]					    =  pa.array(TypedSequence([1, 2, 3]						,				try_type=Value('int32'							)							)							)
						self.assertEqual(arr.type						,				pa.intaa()							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       List[str]					    =  pa.array(TypedSequence(['foo', 'bar']						,				try_type=Value('int64'							)							)							)
						self.assertEqual(arr.type						,				pa.string()							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Tuple					    =  pa.array(TypedSequence([[[1, 2, 3]]]						,				type=ArrayaD((1, 3)						,				'int64'							)							)							)
						self.assertEqual(arr.type						,				ArrayaDExtensionType((1, 3)						,				'int64'							)							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						with self.assertRaises((TypeError, pa.lib.ArrowInvalid)							):
											__a			:       Any					    =  pa.array(TypedSequence(['foo', 'bar']						,				type=ArrayaD((1, 3)						,				'int64'							)							)							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       str					    =  pa.array(TypedSequence([[[1, 2, 3]]]						,				try_type=ArrayaD((1, 3)						,				'int64'							)							)							)
						self.assertEqual(arr.type						,				ArrayaDExtensionType((1, 3)						,				'int64'							)							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       List[str]					    =  pa.array(TypedSequence(['foo', 'bar']						,				try_type=ArrayaD((1, 3)						,				'int64'							)							)							)
						self.assertEqual(arr.type						,				pa.string()							)





	@require_pil
	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						import PIL.Image

						__a			:       Union[str, Any]					    =  PIL.Image.fromarray(np.arange(10						,				dtype=np.uinta							).reshape(2						,				5							)							)
						with patch(
						    'datasets.arrow_writer.cast_to_python_objects'						,				side_effect=__a							) as mock_cast_to_python_objects:
											__a			:       Union[str, Any]					    =  pa.array(TypedSequence([{'path': None, 'bytes': b'image_bytes'}, pil_image]						,				type=Image()							)							)
											__a    ,				__a			:       Optional[Any]					    =  mock_cast_to_python_objects.call_args_list[-1]
											self.assertIn('optimize_list_casting'						,				__a							)
											self.assertFalse(kwargs['optimize_list_casting']							)






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Union[str, Any]						,      _SCREAMING_SNAKE_CASE      :   int   ):
					__a			:       str					    =  pa.BufferReader(_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE						,      pa.Buffer   ) else pa.memory_map(_SCREAMING_SNAKE_CASE   )
					__a			:       Dict					    =  pa.ipc.open_stream(_SCREAMING_SNAKE_CASE   )
					__a			:       pa.Table					    =  f.read_all()
					assert len(pa_table.to_batches()   ) == expected_num_chunks
					assert pa_table.to_pydict() == {"col_1": ["foo", "bar"], "col_2": [1, 2]}
					del pa_table






@pytest.mark.parametrize('writer_batch_size'						,      [None, 1, 10]   )
@pytest.mark.parametrize(
    'fields'						,      [None, {'col_1': pa.string(), 'col_2': pa.intaa()}, {'col_1': pa.string(), 'col_2': pa.intaa()}]   )
def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   List[str]						,      _SCREAMING_SNAKE_CASE      :   Optional[Any]   ):
					__a			:       str					    =  pa.BufferOutputStream()
					__a			:       Any					    =  pa.schema(_SCREAMING_SNAKE_CASE   ) if fields else None
					with ArrowWriter(stream=_SCREAMING_SNAKE_CASE						,      schema=_SCREAMING_SNAKE_CASE						,      writer_batch_size=_SCREAMING_SNAKE_CASE   ) as writer:
										writer.write({'col_1': 'foo', 'col_2': 1}   )
										writer.write({'col_1': 'bar', 'col_2': 2}   )
										__a    ,				__a			:       Dict					    =  writer.finalize()
					assert num_examples == 2
					assert num_bytes > 0
					if not fields:
										__a			:       List[Any]					    =  {'col_1': pa.string(), 'col_2': pa.intaa()}
					assert writer._schema == pa.schema(_SCREAMING_SNAKE_CASE						,      metadata=writer._schema.metadata   )
					_check_output(output.getvalue()						,      expected_num_chunks=num_examples if writer_batch_size == 1 else 1   )






def   lowerCamelCase							():
					__a			:       int					    =  pa.BufferOutputStream()
					__a			:       Optional[int]					    =  Features({'labels': ClassLabel(names=['neg', 'pos']   )}   )
					with ArrowWriter(stream=_SCREAMING_SNAKE_CASE						,      features=_SCREAMING_SNAKE_CASE   ) as writer:
										writer.write({'labels': 0}   )
										writer.write({'labels': 1}   )
										__a    ,				__a			:       List[Any]					    =  writer.finalize()
					assert num_examples == 2
					assert num_bytes > 0
					assert writer._schema == features.arrow_schema
					assert writer._schema.metadata == features.arrow_schema.metadata
					__a			:       int					    =  pa.BufferReader(output.getvalue()   )
					__a			:       Tuple					    =  pa.ipc.open_stream(_SCREAMING_SNAKE_CASE   )
					__a			:       pa.Table					    =  f.read_all()
					__a			:       Optional[int]					    =  pa_table.schema
					assert pa_table.num_rows == 2
					assert schema == features.arrow_schema
					assert schema.metadata == features.arrow_schema.metadata
					assert features == Features.from_arrow_schema(_SCREAMING_SNAKE_CASE   )






@pytest.mark.parametrize('writer_batch_size'						,      [None, 1, 10]   )
def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Any   ):
					__a			:       int					    =  pa.BufferOutputStream()
					with ArrowWriter(
					    stream=_SCREAMING_SNAKE_CASE						,      writer_batch_size=_SCREAMING_SNAKE_CASE						,      hash_salt='split_name'						,      check_duplicates=_SCREAMING_SNAKE_CASE						,      ) as writer:
										with pytest.raises(_SCREAMING_SNAKE_CASE   ):
															writer.write({'col_1': 'foo', 'col_2': 1}						,      key=[1, 2]   )
															__a    ,				__a			:       Optional[Any]					    =  writer.finalize()






@pytest.mark.parametrize('writer_batch_size'						,      [None, 2, 10]   )
def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Optional[Any]   ):
					__a			:       Tuple					    =  pa.BufferOutputStream()
					with ArrowWriter(
					    stream=_SCREAMING_SNAKE_CASE						,      writer_batch_size=_SCREAMING_SNAKE_CASE						,      hash_salt='split_name'						,      check_duplicates=_SCREAMING_SNAKE_CASE						,      ) as writer:
										with pytest.raises(_SCREAMING_SNAKE_CASE   ):
															writer.write({'col_1': 'foo', 'col_2': 1}						,      key=10   )
															writer.write({'col_1': 'bar', 'col_2': 2}						,      key=10   )
															__a    ,				__a			:       Optional[Any]					    =  writer.finalize()






@pytest.mark.parametrize('writer_batch_size'						,      [None, 2, 10]   )
def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   List[str]   ):
					__a			:       List[str]					    =  pa.BufferOutputStream()
					with ArrowWriter(
					    stream=_SCREAMING_SNAKE_CASE						,      writer_batch_size=_SCREAMING_SNAKE_CASE						,      hash_salt='split_name'						,      check_duplicates=_SCREAMING_SNAKE_CASE						,      ) as writer:
										writer.write({'col_1': 'foo', 'col_2': 1}						,      key=1   )
										writer.write({'col_1': 'bar', 'col_2': 2}						,      key=2   )
										__a    ,				__a			:       Optional[int]					    =  writer.finalize()
					assert num_examples == 2
					assert num_bytes > 0
					_check_output(output.getvalue()						,      expected_num_chunks=num_examples if writer_batch_size == 1 else 1   )






@pytest.mark.parametrize('writer_batch_size'						,      [None, 1, 10]   )
@pytest.mark.parametrize(
    'fields'						,      [None, {'col_1': pa.string(), 'col_2': pa.intaa()}, {'col_1': pa.string(), 'col_2': pa.intaa()}]   )
def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Optional[Any]						,      _SCREAMING_SNAKE_CASE      :   Dict   ):
					__a			:       Optional[int]					    =  pa.BufferOutputStream()
					__a			:       int					    =  pa.schema(_SCREAMING_SNAKE_CASE   ) if fields else None
					with ArrowWriter(stream=_SCREAMING_SNAKE_CASE						,      schema=_SCREAMING_SNAKE_CASE						,      writer_batch_size=_SCREAMING_SNAKE_CASE   ) as writer:
										writer.write_batch({'col_1': ['foo', 'bar'], 'col_2': [1, 2]}   )
										writer.write_batch({'col_1': [], 'col_2': []}   )
										__a    ,				__a			:       Dict					    =  writer.finalize()
					assert num_examples == 2
					assert num_bytes > 0
					if not fields:
										__a			:       str					    =  {'col_1': pa.string(), 'col_2': pa.intaa()}
					assert writer._schema == pa.schema(_SCREAMING_SNAKE_CASE						,      metadata=writer._schema.metadata   )
					_check_output(output.getvalue()						,      expected_num_chunks=num_examples if writer_batch_size == 1 else 1   )






@pytest.mark.parametrize('writer_batch_size'						,      [None, 1, 10]   )
@pytest.mark.parametrize(
    'fields'						,      [None, {'col_1': pa.string(), 'col_2': pa.intaa()}, {'col_1': pa.string(), 'col_2': pa.intaa()}]   )
def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Any						,      _SCREAMING_SNAKE_CASE      :   List[Any]   ):
					__a			:       Tuple					    =  pa.BufferOutputStream()
					__a			:       str					    =  pa.schema(_SCREAMING_SNAKE_CASE   ) if fields else None
					with ArrowWriter(stream=_SCREAMING_SNAKE_CASE						,      schema=_SCREAMING_SNAKE_CASE						,      writer_batch_size=_SCREAMING_SNAKE_CASE   ) as writer:
										writer.write_table(pa.Table.from_pydict({'col_1': ['foo', 'bar'], 'col_2': [1, 2]}   )   )
										__a    ,				__a			:       str					    =  writer.finalize()
					assert num_examples == 2
					assert num_bytes > 0
					if not fields:
										__a			:       List[str]					    =  {'col_1': pa.string(), 'col_2': pa.intaa()}
					assert writer._schema == pa.schema(_SCREAMING_SNAKE_CASE						,      metadata=writer._schema.metadata   )
					_check_output(output.getvalue()						,      expected_num_chunks=num_examples if writer_batch_size == 1 else 1   )






@pytest.mark.parametrize('writer_batch_size'						,      [None, 1, 10]   )
@pytest.mark.parametrize(
    'fields'						,      [None, {'col_1': pa.string(), 'col_2': pa.intaa()}, {'col_1': pa.string(), 'col_2': pa.intaa()}]   )
def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Union[str, Any]						,      _SCREAMING_SNAKE_CASE      :   List[str]   ):
					__a			:       List[Any]					    =  pa.BufferOutputStream()
					__a			:       List[Any]					    =  pa.schema(_SCREAMING_SNAKE_CASE   ) if fields else None
					with ArrowWriter(stream=_SCREAMING_SNAKE_CASE						,      schema=_SCREAMING_SNAKE_CASE						,      writer_batch_size=_SCREAMING_SNAKE_CASE   ) as writer:
										writer.write_row(pa.Table.from_pydict({'col_1': ['foo'], 'col_2': [1]}   )   )
										writer.write_row(pa.Table.from_pydict({'col_1': ['bar'], 'col_2': [2]}   )   )
										__a    ,				__a			:       str					    =  writer.finalize()
					assert num_examples == 2
					assert num_bytes > 0
					if not fields:
										__a			:       List[Any]					    =  {'col_1': pa.string(), 'col_2': pa.intaa()}
					assert writer._schema == pa.schema(_SCREAMING_SNAKE_CASE						,      metadata=writer._schema.metadata   )
					_check_output(output.getvalue()						,      expected_num_chunks=num_examples if writer_batch_size == 1 else 1   )






def   lowerCamelCase							():
					with tempfile.TemporaryDirectory() as tmp_dir:
										__a			:       List[Any]					    =  {'col_1': pa.string(), 'col_2': pa.intaa()}
										__a			:       Optional[int]					    =  os.path.join(_SCREAMING_SNAKE_CASE						,      'test.arrow'   )
										with ArrowWriter(path=_SCREAMING_SNAKE_CASE						,      schema=pa.schema(_SCREAMING_SNAKE_CASE   )   ) as writer:
															writer.write_batch({'col_1': ['foo', 'bar'], 'col_2': [1, 2]}   )
															__a    ,				__a			:       List[Any]					    =  writer.finalize()
										assert num_examples == 2
										assert num_bytes > 0
										assert writer._schema == pa.schema(_SCREAMING_SNAKE_CASE						,      metadata=writer._schema.metadata   )
										_check_output(_SCREAMING_SNAKE_CASE						,      1   )






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   int   ):
					if pa.types.is_list(_SCREAMING_SNAKE_CASE   ):
										return get_base_dtype(arr_type.value_type   )
					else:
										return arr_type






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Any						,      _SCREAMING_SNAKE_CASE      :   int   ):
					if isinstance(lst[0]						,      _SCREAMING_SNAKE_CASE   ):
										change_first_primitive_element_in_list(lst[0]						,      _SCREAMING_SNAKE_CASE   )
					else:
										__a			:       List[str]					    =  value






@pytest.mark.parametrize('optimized_int_type, expected_dtype'						,      [(None, pa.intaa()), (Value('int32'   ), pa.intaa())]   )
@pytest.mark.parametrize('sequence'						,      [[1, 2, 3], [[1, 2, 3]], [[[1, 2, 3]]]]   )
def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Union[str, Any]						,      _SCREAMING_SNAKE_CASE      :   Optional[int]						,      _SCREAMING_SNAKE_CASE      :   Union[str, Any]   ):
					__a			:       Optional[Any]					    =  pa.array(TypedSequence(_SCREAMING_SNAKE_CASE						,      optimized_int_type=_SCREAMING_SNAKE_CASE   )   )
					assert get_base_dtype(arr.type   ) == expected_dtype






@pytest.mark.parametrize(
    'col, expected_dtype'						,      [
        ('attention_mask', pa.inta()),
        ('special_tokens_mask', pa.inta()),
        ('token_type_ids', pa.inta()),
        ('input_ids', pa.intaa()),
        ('other', pa.intaa()),
    ]						,      )
@pytest.mark.parametrize('sequence'						,      [[1, 2, 3], [[1, 2, 3]], [[[1, 2, 3]]]]   )
def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Any						,      _SCREAMING_SNAKE_CASE      :   Optional[Any]						,      _SCREAMING_SNAKE_CASE      :   Optional[Any]   ):
					# in range
					__a			:       Any					    =  pa.array(OptimizedTypedSequence(_SCREAMING_SNAKE_CASE						,      col=_SCREAMING_SNAKE_CASE   )   )
					assert get_base_dtype(arr.type   ) == expected_dtype

					# not in range
					if col != "other":
										# avoids errors due to in-place modifications
										__a			:       Optional[Any]					    =  copy.deepcopy(_SCREAMING_SNAKE_CASE   )
										__a			:       List[str]					    =  np.iinfo(expected_dtype.to_pandas_dtype()   ).max + 1
										change_first_primitive_element_in_list(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE   )
										__a			:       Dict					    =  pa.array(OptimizedTypedSequence(_SCREAMING_SNAKE_CASE						,      col=_SCREAMING_SNAKE_CASE   )   )
										assert get_base_dtype(arr.type   ) == pa.intaa()






@pytest.mark.parametrize('raise_exception'						,      [False, True]   )
def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   List[Any]						,      _SCREAMING_SNAKE_CASE      :   Union[str, Any]   ):
					__a			:       Union[str, Any]					    =  str(tmp_path / 'dataset-train.arrow'   )
					try:
										with ArrowWriter(path=_SCREAMING_SNAKE_CASE   ) as writer:
															if raise_exception:
																				raise pa.lib.ArrowInvalid()
															else:
																				writer.stream.close()
					except pa.lib.ArrowInvalid:
										pass
					finally:
										assert writer.stream.closed






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Optional[Any]   ):
					__a			:       Optional[Any]					    =  'mock://dataset-train.arrow'
					with ArrowWriter(path=_SCREAMING_SNAKE_CASE						,      storage_options=mockfs.storage_options   ) as writer:
										assert isinstance(writer._fs						,      type(_SCREAMING_SNAKE_CASE   )   )
										assert writer._fs.storage_options == mockfs.storage_options
										writer.write({'col_1': 'foo', 'col_2': 1}   )
										writer.write({'col_1': 'bar', 'col_2': 2}   )
										__a    ,				__a			:       Dict					    =  writer.finalize()
					assert num_examples == 2
					assert num_bytes > 0
					assert mockfs.exists(_SCREAMING_SNAKE_CASE   )






def   lowerCamelCase							():
					__a			:       List[Any]					    =  pa.BufferOutputStream()
					with ParquetWriter(stream=_SCREAMING_SNAKE_CASE   ) as writer:
										writer.write({'col_1': 'foo', 'col_2': 1}   )
										writer.write({'col_1': 'bar', 'col_2': 2}   )
										__a    ,				__a			:       int					    =  writer.finalize()
					assert num_examples == 2
					assert num_bytes > 0
					__a			:       Optional[Any]					    =  pa.BufferReader(output.getvalue()   )
					__a			:       pa.Table					    =  pq.read_table(_SCREAMING_SNAKE_CASE   )
					assert pa_table.to_pydict() == {"col_1": ["foo", "bar"], "col_2": [1, 2]}






@require_pil
@pytest.mark.parametrize('embed_local_files'						,      [False, True]   )
def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   str						,      _SCREAMING_SNAKE_CASE      :   str   ):
					import PIL.Image

					__a			:       List[Any]					    =  str(tmp_path / 'test_image_rgb.jpg'   )
					PIL.Image.fromarray(np.zeros((5, 5)						,      dtype=np.uinta   )   ).save(_SCREAMING_SNAKE_CASE						,      format='png'   )
					__a			:       Union[str, Any]					    =  pa.BufferOutputStream()
					with ParquetWriter(
					    stream=_SCREAMING_SNAKE_CASE						,      features=Features({'image': Image()}   )						,      embed_local_files=_SCREAMING_SNAKE_CASE   ) as writer:
										writer.write({'image': image_path}   )
										writer.finalize()
					__a			:       Any					    =  pa.BufferReader(output.getvalue()   )
					__a			:       pa.Table					    =  pq.read_table(_SCREAMING_SNAKE_CASE   )
					__a			:       Union[str, Any]					    =  pa_table.to_pydict()
					if embed_local_files:
										assert isinstance(out['image'][0]['path']						,      _SCREAMING_SNAKE_CASE   )
										with open(_SCREAMING_SNAKE_CASE						,      'rb'   ) as f:
															assert out["image"][0]["bytes"] == f.read()
					else:
										assert out["image"][0]["path"] == image_path
										assert out["image"][0]["bytes"] is None






def   lowerCamelCase							():
					__a			:       Tuple					    =  pa.schema([pa.field('col_1'						,      pa.string()						,      nullable=_SCREAMING_SNAKE_CASE   )]   )
					__a			:       str					    =  pa.BufferOutputStream()
					with ArrowWriter(stream=_SCREAMING_SNAKE_CASE   ) as writer:
										writer._build_writer(inferred_schema=_SCREAMING_SNAKE_CASE   )
										assert writer._schema == pa.schema([pa.field('col_1'						,      pa.string()   )]   )







'''simple docstring'''



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   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   List[Any]   ):
					__a			:       Any					    =  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."""   )
					__a			:       Tuple					    =  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."""   )

					__a			:       List[str]					    =  components[:-1] + [test_fn.replace('.py'						,      ''   )]
					__a			:       Optional[Any]					    =  '.'.join(_SCREAMING_SNAKE_CASE   )

					return test_module_path






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Tuple   ):
					__a			:       List[str]					    =  get_module_path(_SCREAMING_SNAKE_CASE   )
					__a			:       Dict					    =  importlib.import_module(_SCREAMING_SNAKE_CASE   )

					return test_module






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Tuple   ):
					__a			:       List[str]					    =  []
					__a			:       List[str]					    =  get_test_module(_SCREAMING_SNAKE_CASE   )
					for attr in dir(_SCREAMING_SNAKE_CASE   ):
										if attr.endswith('ModelTester'   ):
															tester_classes.append(getattr(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE   )   )

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






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Tuple   ):
					__a			:       Any					    =  []
					__a			:       str					    =  get_test_module(_SCREAMING_SNAKE_CASE   )
					for attr in dir(_SCREAMING_SNAKE_CASE   ):
										__a			:       int					    =  getattr(_SCREAMING_SNAKE_CASE						,      _SCREAMING_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).
										__a			:       Optional[Any]					    =  getattr(_SCREAMING_SNAKE_CASE						,      'all_model_classes'						,      []   )
										if len(_SCREAMING_SNAKE_CASE   ) > 0:
															test_classes.append(_SCREAMING_SNAKE_CASE   )

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






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   int   ):
					__a			:       str					    =  get_test_classes(_SCREAMING_SNAKE_CASE   )
					__a			:       Any					    =  set()
					for test_class in test_classes:
										model_classes.update(test_class.all_model_classes   )

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






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Optional[Any]   ):
					__a			:       Tuple					    =  test_class()
					if hasattr(_SCREAMING_SNAKE_CASE						,      'setUp'   ):
										test.setUp()

					__a			:       List[Any]					    =  None
					if hasattr(_SCREAMING_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:
															__a			:       List[str]					    =  test.model_tester.__class__

					return model_tester






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   int						,      _SCREAMING_SNAKE_CASE      :   Optional[Any]   ):
					__a			:       str					    =  get_test_classes(_SCREAMING_SNAKE_CASE   )

					__a			:       int					    =  []
					for test_class in test_classes:
										if model_class in test_class.all_model_classes:
															target_test_classes.append(_SCREAMING_SNAKE_CASE   )

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






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Tuple						,      _SCREAMING_SNAKE_CASE      :   List[str]   ):
					__a			:       List[Any]					    =  get_test_classes_for_model(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE   )

					__a			:       Any					    =  []
					for test_class in test_classes:
										__a			:       Any					    =  get_model_tester_from_test_class(_SCREAMING_SNAKE_CASE   )
										if tester_class is not None:
															tester_classes.append(_SCREAMING_SNAKE_CASE   )

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






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Optional[int]   ):
					__a			:       str					    =  get_test_classes(_SCREAMING_SNAKE_CASE   )
					__a			:       int					    =  {test_class: get_model_tester_from_test_class(_SCREAMING_SNAKE_CASE   ) for test_class in test_classes}
					return test_tester_mapping






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   List[str]   ):
					__a			:       Optional[Any]					    =  get_model_classes(_SCREAMING_SNAKE_CASE   )
					__a			:       Optional[int]					    =  {
					    model_class: get_test_classes_for_model(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE   ) for model_class in model_classes
					}
					return model_test_mapping






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   List[str]   ):
					__a			:       Optional[Any]					    =  get_model_classes(_SCREAMING_SNAKE_CASE   )
					__a			:       str					    =  {
					    model_class: get_tester_classes_for_model(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE   ) for model_class in model_classes
					}
					return model_to_tester_mapping






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



