




from __future__ import annotations

import inspect
import unittest
from math import floor

import numpy as np

from transformers import CvtConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
						import tensorflow as tf

						from transformers import TFCvtForImageClassification, TFCvtModel
						from transformers.models.cvt.modeling_tf_cvt import TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from PIL import Image

						from transformers import AutoImageProcessor


class  A		(  __UpperCAmelCase     ):



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  self.config_class(**self.inputs_dict   )
								self.parent.assertTrue(hasattr(UpperCamelCase__,	'''embed_dim'''   )   )
								self.parent.assertTrue(hasattr(UpperCamelCase__,	'''num_heads'''   )   )







class  A		:



		def __init__(     self,	UpperCamelCase__,	UpperCamelCase__=13,	UpperCamelCase__=64,	UpperCamelCase__=3,	UpperCamelCase__=[16, 48, 96],	UpperCamelCase__=[1, 3, 6],	UpperCamelCase__=[1, 2, 10],	UpperCamelCase__=[7, 3, 3],	UpperCamelCase__=[4, 2, 2],	UpperCamelCase__=[2, 1, 1],	UpperCamelCase__=[2, 2, 2],	UpperCamelCase__=[False, False, True],	UpperCamelCase__=[0.0, 0.0, 0.0],	UpperCamelCase__=0.02,	UpperCamelCase__=1E-12,	UpperCamelCase__=True,	UpperCamelCase__=True,	UpperCamelCase__=2,	):







								"""simple docstring"""



								lowerCAmelCase_      			=  parent
								lowerCAmelCase_      			=  batch_size
								lowerCAmelCase_      			=  image_size
								lowerCAmelCase_      			=  patch_sizes
								lowerCAmelCase_      			=  patch_stride
								lowerCAmelCase_      			=  patch_padding
								lowerCAmelCase_      			=  is_training
								lowerCAmelCase_      			=  use_labels
								lowerCAmelCase_      			=  num_labels
								lowerCAmelCase_      			=  num_channels
								lowerCAmelCase_      			=  embed_dim
								lowerCAmelCase_      			=  num_heads
								lowerCAmelCase_      			=  stride_kv
								lowerCAmelCase_      			=  depth
								lowerCAmelCase_      			=  cls_token
								lowerCAmelCase_      			=  attention_drop_rate
								lowerCAmelCase_      			=  initializer_range
								lowerCAmelCase_      			=  layer_norm_eps



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]   )

								lowerCAmelCase_      			=  None
								if self.use_labels:
														# create a random int32 tensor of given shape
														lowerCAmelCase_      			=  ids_tensor([self.batch_size],	self.num_labels   )

								lowerCAmelCase_      			=  self.get_config()
								return config, pixel_values, labels



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								return CvtConfig(
								    image_size=self.image_size,	num_labels=self.num_labels,	num_channels=self.num_channels,	embed_dim=self.embed_dim,	num_heads=self.num_heads,	patch_sizes=self.patch_sizes,	patch_padding=self.patch_padding,	patch_stride=self.patch_stride,	stride_kv=self.stride_kv,	depth=self.depth,	cls_token=self.cls_token,	attention_drop_rate=self.attention_drop_rate,	initializer_range=self.initializer_range,	)



		def        SCREAMING_SNAKE_CASE__			(     self,	UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  TFCvtModel(config=UpperCamelCase__   )
								lowerCAmelCase_      			=  model(UpperCamelCase__,	training=UpperCamelCase__   )
								lowerCAmelCase_      			=  (self.image_size, self.image_size)
								lowerCAmelCase_			,					lowerCAmelCase_      			=  image_size[0], image_size[1]
								for i in range(len(self.depth   )   ):
														lowerCAmelCase_      			=  floor(((height + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1   )
														lowerCAmelCase_      			=  floor(((width + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1   )
								self.parent.assertEqual(result.last_hidden_state.shape,	(self.batch_size, self.embed_dim[-1], height, width)   )



		def        SCREAMING_SNAKE_CASE__			(     self,	UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  self.num_labels
								lowerCAmelCase_      			=  TFCvtForImageClassification(UpperCamelCase__   )
								lowerCAmelCase_      			=  model(UpperCamelCase__,	labels=UpperCamelCase__,	training=UpperCamelCase__   )
								self.parent.assertEqual(result.logits.shape,	(self.batch_size, self.num_labels)   )







		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  self.prepare_config_and_inputs()
								lowerCAmelCase_			,					lowerCAmelCase_			,					lowerCAmelCase_      			=  config_and_inputs
								lowerCAmelCase_      			=  {'''pixel_values''': pixel_values}
								return config, inputs_dict







@require_tf
class  A		(  __UpperCAmelCase      ,				__UpperCAmelCase      ,				unittest.TestCase     ):
		__snake_case									=   (TFCvtModel, TFCvtForImageClassification) if is_tf_available() else ()
		__snake_case									=   (
		    {'feature-extraction': TFCvtModel, 'image-classification': TFCvtForImageClassification}
		    if is_tf_available()
		    else {}
		)
		__snake_case									=   False
		__snake_case									=   False
		__snake_case									=   False
		__snake_case									=   False
		__snake_case									=   False



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  TFCvtModelTester(self   )
								lowerCAmelCase_      			=  TFCvtConfigTester(self,	config_class=UpperCamelCase__,	has_text_modality=UpperCamelCase__,	hidden_size=37   )



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								self.config_tester.create_and_test_config_common_properties()
								self.config_tester.create_and_test_config_to_json_string()
								self.config_tester.create_and_test_config_to_json_file()
								self.config_tester.create_and_test_config_from_and_save_pretrained()
								self.config_tester.create_and_test_config_with_num_labels()
								self.config_tester.check_config_can_be_init_without_params()
								self.config_tester.check_config_arguments_init()



		@unittest.skip(reason='''Cvt does not output attentions'''   )
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								pass



		@unittest.skip(reason='''Cvt does not use inputs_embeds'''   )
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								pass



		@unittest.skip(reason='''Cvt does not support input and output embeddings'''   )
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								pass



		@unittest.skipIf(
		    not is_tf_available() or len(tf.config.list_physical_devices('''GPU'''   )   ) == 0,	reason='''TF does not support backprop for grouped convolutions on CPU.''',	)
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								super().test_dataset_conversion()



		@unittest.skipIf(
		    not is_tf_available() or len(tf.config.list_physical_devices('''GPU'''   )   ) == 0,	reason='''TF does not support backprop for grouped convolutions on CPU.''',	)
		@slow
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								super().test_keras_fit()



		@unittest.skip(reason='''Get `Failed to determine best cudnn convolution algo.` error after using TF 2.12+cuda 11.8'''   )
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  tf.keras.mixed_precision.Policy('''mixed_float16'''   )
								tf.keras.mixed_precision.set_global_policy(UpperCamelCase__   )
								super().test_keras_fit()
								tf.keras.mixed_precision.set_global_policy('''float32'''   )



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_			,					lowerCAmelCase_      			=  self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
														lowerCAmelCase_      			=  model_class(UpperCamelCase__   )
														lowerCAmelCase_      			=  inspect.signature(model.call   )
														# signature.parameters is an OrderedDict => so arg_names order is deterministic
														lowerCAmelCase_      			=  [*signature.parameters.keys()]

														lowerCAmelCase_      			=  ['''pixel_values''']
														self.assertListEqual(arg_names[:1],	UpperCamelCase__   )



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								def check_hidden_states_output(UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__   ):
														lowerCAmelCase_      			=  model_class(UpperCamelCase__   )

														lowerCAmelCase_      			=  model(**self._prepare_for_class(UpperCamelCase__,	UpperCamelCase__   )   )
														lowerCAmelCase_      			=  outputs.hidden_states

														lowerCAmelCase_      			=  len(self.model_tester.depth   )
														self.assertEqual(len(UpperCamelCase__   ),	UpperCamelCase__   )

														# verify the first hidden states (first block)
														self.assertListEqual(
														    list(hidden_states[0].shape[-3:]   ),	[
														        self.model_tester.embed_dim[0],
														        self.model_tester.image_size // 4,
														        self.model_tester.image_size // 4,
														    ],	)

								lowerCAmelCase_			,					lowerCAmelCase_      			=  self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
														lowerCAmelCase_      			=  True
														check_hidden_states_output(UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__   )

														# check that output_hidden_states also work using config
														del inputs_dict["output_hidden_states"]
														lowerCAmelCase_      			=  True

														check_hidden_states_output(UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__   )



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*UpperCamelCase__   )



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*UpperCamelCase__   )







		@slow
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								for model_name in TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														lowerCAmelCase_      			=  TFCvtModel.from_pretrained(UpperCamelCase__   )
														self.assertIsNotNone(UpperCamelCase__   )







def __UpperCamelCase			(       ):
						lowerCAmelCase_      			=  Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''  )
						return image






@require_tf
@require_vision
class  A		(  unittest.TestCase     ):



		@cached_property
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								return AutoImageProcessor.from_pretrained(TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]   )







		@slow
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  TFCvtForImageClassification.from_pretrained(TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]   )

								lowerCAmelCase_      			=  self.default_image_processor
								lowerCAmelCase_      			=  prepare_img()
								lowerCAmelCase_      			=  image_processor(images=UpperCamelCase__,	return_tensors='''tf'''   )

								# forward pass
								lowerCAmelCase_      			=  model(**UpperCamelCase__   )

								# verify the logits
								lowerCAmelCase_      			=  tf.TensorShape((1, 1000)   )
								self.assertEqual(outputs.logits.shape,	UpperCamelCase__   )

								lowerCAmelCase_      			=  tf.constant([0.9_285, 0.9_015, -0.3_150]   )
								self.assertTrue(np.allclose(outputs.logits[0, :3].numpy(),	UpperCamelCase__,	atol=1E-4   )   )










import io
import json

import fsspec
import pytest

from datasets import Dataset, DatasetDict, Features, NamedSplit, Value
from datasets.io.json import JsonDatasetReader, JsonDatasetWriter

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases





def __UpperCamelCase			(       _A ,  _A  ):
						assert isinstance(_A ,  _A  )
						assert dataset.num_rows == 4
						assert dataset.num_columns == 3
						assert dataset.column_names == ["col_1", "col_2", "col_3"]
						for feature, expected_dtype in expected_features.items():
												assert dataset.features[feature].dtype == expected_dtype





@pytest.mark.parametrize('''keep_in_memory''' ,  [False, True]  )
def __UpperCamelCase			(       _A ,  _A ,  _A  ):
						lowerCAmelCase_      			=  tmp_path / '''cache'''
						lowerCAmelCase_      			=  {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
						with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
												lowerCAmelCase_      			=  JsonDatasetReader(_A ,  cache_dir=_A ,  keep_in_memory=_A  ).read()
						_check_json_dataset(_A ,  _A  )





@pytest.mark.parametrize(
    '''features''' ,  [
        None,
        {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''},
        {'''col_1''': '''string''', '''col_2''': '''string''', '''col_3''': '''string'''},
        {'''col_1''': '''int32''', '''col_2''': '''int32''', '''col_3''': '''int32'''},
        {'''col_1''': '''float32''', '''col_2''': '''float32''', '''col_3''': '''float32'''},
    ] ,  )
def __UpperCamelCase			(       _A ,  _A ,  _A  ):
						lowerCAmelCase_      			=  tmp_path / '''cache'''
						lowerCAmelCase_      			=  {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
						lowerCAmelCase_      			=  features.copy() if features else default_expected_features
						lowerCAmelCase_      			=  (
						    Features({feature: Value(_A  ) for feature, dtype in features.items()}  ) if features is not None else None
						)
						lowerCAmelCase_      			=  JsonDatasetReader(_A ,  features=_A ,  cache_dir=_A  ).read()
						_check_json_dataset(_A ,  _A  )





@pytest.mark.parametrize(
    '''features''' ,  [
        None,
        {'''col_3''': '''float64''', '''col_1''': '''string''', '''col_2''': '''int64'''},
    ] ,  )
def __UpperCamelCase			(       _A ,  _A ,  _A  ):
						lowerCAmelCase_      			=  tmp_path / '''cache'''
						lowerCAmelCase_      			=  {'''col_3''': '''float64''', '''col_1''': '''string''', '''col_2''': '''int64'''}
						lowerCAmelCase_      			=  features.copy() if features else default_expected_features
						lowerCAmelCase_      			=  (
						    Features({feature: Value(_A  ) for feature, dtype in features.items()}  ) if features is not None else None
						)
						lowerCAmelCase_      			=  JsonDatasetReader(_A ,  features=_A ,  cache_dir=_A  ).read()
						assert isinstance(_A ,  _A  )
						assert dataset.num_rows == 2
						assert dataset.num_columns == 3
						assert dataset.column_names == ["col_3", "col_1", "col_2"]
						for feature, expected_dtype in expected_features.items():
												assert dataset.features[feature].dtype == expected_dtype





def __UpperCamelCase			(       _A ,  _A  ):
						# jsonl_312_path features are {"col_3": "float64", "col_1": "string", "col_2": "int64"}
						lowerCAmelCase_      			=  {'''col_2''': '''int64''', '''col_3''': '''float64''', '''col_1''': '''string'''}
						lowerCAmelCase_      			=  features.copy()
						lowerCAmelCase_      			=  (
						    Features({feature: Value(_A  ) for feature, dtype in features.items()}  ) if features is not None else None
						)
						lowerCAmelCase_      			=  tmp_path / '''cache'''
						lowerCAmelCase_      			=  JsonDatasetReader(_A ,  features=_A ,  cache_dir=_A  ).read()
						assert isinstance(_A ,  _A  )
						assert dataset.num_rows == 2
						assert dataset.num_columns == 3
						assert dataset.column_names == ["col_2", "col_3", "col_1"]
						for feature, expected_dtype in expected_features.items():
												assert dataset.features[feature].dtype == expected_dtype





@pytest.mark.parametrize('''split''' ,  [None, NamedSplit('''train'''  ), '''train''', '''test''']  )
def __UpperCamelCase			(       _A ,  _A ,  _A  ):
						lowerCAmelCase_      			=  tmp_path / '''cache'''
						lowerCAmelCase_      			=  {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
						lowerCAmelCase_      			=  JsonDatasetReader(_A ,  cache_dir=_A ,  split=_A  ).read()
						_check_json_dataset(_A ,  _A  )
						assert dataset.split == split if split else "train"





@pytest.mark.parametrize('''path_type''' ,  [str, list]  )
def __UpperCamelCase			(       _A ,  _A ,  _A  ):
						if issubclass(_A ,  _A  ):
												lowerCAmelCase_      			=  jsonl_path
						elif issubclass(_A ,  _A  ):
												lowerCAmelCase_      			=  [jsonl_path]
						lowerCAmelCase_      			=  tmp_path / '''cache'''
						lowerCAmelCase_      			=  {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
						lowerCAmelCase_      			=  JsonDatasetReader(_A ,  cache_dir=_A  ).read()
						_check_json_dataset(_A ,  _A  )





def __UpperCamelCase			(       _A ,  _A ,  _A=("train",)  ):
						assert isinstance(_A ,  _A  )
						for split in splits:
												lowerCAmelCase_      			=  dataset_dict[split]
												assert dataset.num_rows == 4
												assert dataset.num_columns == 3
												assert dataset.column_names == ["col_1", "col_2", "col_3"]
												for feature, expected_dtype in expected_features.items():
																		assert dataset.features[feature].dtype == expected_dtype





@pytest.mark.parametrize('''keep_in_memory''' ,  [False, True]  )
def __UpperCamelCase			(       _A ,  _A ,  _A  ):
						lowerCAmelCase_      			=  tmp_path / '''cache'''
						lowerCAmelCase_      			=  {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
						with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
												lowerCAmelCase_      			=  JsonDatasetReader({'''train''': jsonl_path} ,  cache_dir=_A ,  keep_in_memory=_A  ).read()
						_check_json_datasetdict(_A ,  _A  )





@pytest.mark.parametrize(
    '''features''' ,  [
        None,
        {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''},
        {'''col_1''': '''string''', '''col_2''': '''string''', '''col_3''': '''string'''},
        {'''col_1''': '''int32''', '''col_2''': '''int32''', '''col_3''': '''int32'''},
        {'''col_1''': '''float32''', '''col_2''': '''float32''', '''col_3''': '''float32'''},
    ] ,  )
def __UpperCamelCase			(       _A ,  _A ,  _A  ):
						lowerCAmelCase_      			=  tmp_path / '''cache'''
						lowerCAmelCase_      			=  {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
						lowerCAmelCase_      			=  features.copy() if features else default_expected_features
						lowerCAmelCase_      			=  (
						    Features({feature: Value(_A  ) for feature, dtype in features.items()}  ) if features is not None else None
						)
						lowerCAmelCase_      			=  JsonDatasetReader({'''train''': jsonl_path} ,  features=_A ,  cache_dir=_A  ).read()
						_check_json_datasetdict(_A ,  _A  )





@pytest.mark.parametrize('''split''' ,  [None, NamedSplit('''train'''  ), '''train''', '''test''']  )
def __UpperCamelCase			(       _A ,  _A ,  _A  ):
						if split:
												lowerCAmelCase_      			=  {split: jsonl_path}
						else:
												lowerCAmelCase_      			=  '''train'''
												lowerCAmelCase_      			=  {'''train''': jsonl_path, '''test''': jsonl_path}
						lowerCAmelCase_      			=  tmp_path / '''cache'''
						lowerCAmelCase_      			=  {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
						lowerCAmelCase_      			=  JsonDatasetReader(_A ,  cache_dir=_A  ).read()
						_check_json_datasetdict(_A ,  _A ,  splits=list(path.keys()  )  )
						assert all(dataset[split].split == split for split in path.keys()  )





def __UpperCamelCase			(       _A  ):
						return json.load(_A  )





def __UpperCamelCase			(       _A  ):
						return [json.loads(_A  ) for line in buffer]






class  A		:



		@pytest.mark.parametrize('''lines, load_json_function''',	[(True, load_json_lines), (False, load_json)]   )
		def        SCREAMING_SNAKE_CASE__			(     self,	UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__   ):







								"""simple docstring"""



								with io.BytesIO() as buffer:
														JsonDatasetWriter(UpperCamelCase__,	UpperCamelCase__,	lines=UpperCamelCase__   ).write()
														buffer.seek(0   )
														lowerCAmelCase_      			=  load_json_function(UpperCamelCase__   )
								assert isinstance(UpperCamelCase__,	UpperCamelCase__   )
								assert isinstance(exported_content[0],	UpperCamelCase__   )
								assert len(UpperCamelCase__   ) == 10



		@pytest.mark.parametrize(
		    '''orient, container, keys, len_at''',	[
		        ('''records''', list, {'''tokens''', '''labels''', '''answers''', '''id'''}, None),
		        ('''split''', dict, {'''columns''', '''data'''}, '''data'''),
		        ('''index''', dict, set('''0123456789'''   ), None),
		        ('''columns''', dict, {'''tokens''', '''labels''', '''answers''', '''id'''}, '''tokens'''),
		        ('''values''', list, None, None),
		        ('''table''', dict, {'''schema''', '''data'''}, '''data'''),
		    ],	)
		def        SCREAMING_SNAKE_CASE__			(     self,	UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__   ):







								"""simple docstring"""



								with io.BytesIO() as buffer:
														JsonDatasetWriter(UpperCamelCase__,	UpperCamelCase__,	lines=UpperCamelCase__,	orient=UpperCamelCase__   ).write()
														buffer.seek(0   )
														lowerCAmelCase_      			=  load_json(UpperCamelCase__   )
								assert isinstance(UpperCamelCase__,	UpperCamelCase__   )
								if keys:
														if container is dict:
																				assert exported_content.keys() == keys
														else:
																				assert exported_content[0].keys() == keys
								else:
														assert not hasattr(UpperCamelCase__,	'''keys'''   ) and not hasattr(exported_content[0],	'''keys'''   )
								if len_at:
														assert len(exported_content[len_at]   ) == 10
								else:
														assert len(UpperCamelCase__   ) == 10



		@pytest.mark.parametrize('''lines, load_json_function''',	[(True, load_json_lines), (False, load_json)]   )
		def        SCREAMING_SNAKE_CASE__			(     self,	UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__   ):







								"""simple docstring"""



								with io.BytesIO() as buffer:
														JsonDatasetWriter(UpperCamelCase__,	UpperCamelCase__,	lines=UpperCamelCase__,	num_proc=2   ).write()
														buffer.seek(0   )
														lowerCAmelCase_      			=  load_json_function(UpperCamelCase__   )
								assert isinstance(UpperCamelCase__,	UpperCamelCase__   )
								assert isinstance(exported_content[0],	UpperCamelCase__   )
								assert len(UpperCamelCase__   ) == 10



		@pytest.mark.parametrize(
		    '''orient, container, keys, len_at''',	[
		        ('''records''', list, {'''tokens''', '''labels''', '''answers''', '''id'''}, None),
		        ('''split''', dict, {'''columns''', '''data'''}, '''data'''),
		        ('''index''', dict, set('''0123456789'''   ), None),
		        ('''columns''', dict, {'''tokens''', '''labels''', '''answers''', '''id'''}, '''tokens'''),
		        ('''values''', list, None, None),
		        ('''table''', dict, {'''schema''', '''data'''}, '''data'''),
		    ],	)
		def        SCREAMING_SNAKE_CASE__			(     self,	UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__   ):







								"""simple docstring"""



								with io.BytesIO() as buffer:
														JsonDatasetWriter(UpperCamelCase__,	UpperCamelCase__,	lines=UpperCamelCase__,	orient=UpperCamelCase__,	num_proc=2   ).write()
														buffer.seek(0   )
														lowerCAmelCase_      			=  load_json(UpperCamelCase__   )
								assert isinstance(UpperCamelCase__,	UpperCamelCase__   )
								if keys:
														if container is dict:
																				assert exported_content.keys() == keys
														else:
																				assert exported_content[0].keys() == keys
								else:
														assert not hasattr(UpperCamelCase__,	'''keys'''   ) and not hasattr(exported_content[0],	'''keys'''   )
								if len_at:
														assert len(exported_content[len_at]   ) == 10
								else:
														assert len(UpperCamelCase__   ) == 10



		def        SCREAMING_SNAKE_CASE__			(     self,	UpperCamelCase__   ):







								"""simple docstring"""



								with pytest.raises(UpperCamelCase__   ):
														with io.BytesIO() as buffer:
																				JsonDatasetWriter(UpperCamelCase__,	UpperCamelCase__,	num_proc=0   )







		@pytest.mark.parametrize('''compression, extension''',	[('''gzip''', '''gz'''), ('''bz2''', '''bz2'''), ('''xz''', '''xz''')]   )
		def        SCREAMING_SNAKE_CASE__			(     self,	UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  tmp_path_factory.mktemp('''data'''   ) / f"test.json.{extension}"
								lowerCAmelCase_      			=  str(shared_datadir / f"test_file.json.{extension}"   )
								JsonDatasetWriter(UpperCamelCase__,	UpperCamelCase__,	compression=UpperCamelCase__   ).write()

								with fsspec.open(UpperCamelCase__,	'''rb''',	compression='''infer'''   ) as f:
														lowerCAmelCase_      			=  f.read()
								with fsspec.open(UpperCamelCase__,	'''rb''',	compression='''infer'''   ) as f:
														lowerCAmelCase_      			=  f.read()
								assert exported_content == original_content




