




# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# 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.


import warnings
from typing import List
from unittest.mock import Mock

import torch
from torch.utils.data import DataLoader, IterableDataset, TensorDataset

from accelerate.accelerator import Accelerator
from accelerate.utils.dataclasses import DistributedType




class       _A				(		__lowercase     ):






		def __init__(    self						,		_SCREAMING_SNAKE_CASE			):
								_UpperCAmelCase      =			data






		def __iter__(    self			):
								for element in self.data:
														yield element




def        _SCREAMING_SNAKE_CASE      (		snake_case=True       )						->				List[str]:
						_UpperCAmelCase      =			Accelerator(even_batches=snake_case       )
						assert accelerator.num_processes == 2, "this script expects that two GPUs are available"
						return accelerator




def        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case			,     snake_case			,     snake_case = False       )						->				List[Any]:
						if iterable:
												_UpperCAmelCase      =			DummyIterableDataset(torch.as_tensor(range(snake_case       )       )       )
						else:
												_UpperCAmelCase      =			TensorDataset(torch.as_tensor(range(snake_case       )       )       )

						_UpperCAmelCase      =			DataLoader(snake_case			,     batch_size=snake_case       )
						_UpperCAmelCase      =			accelerator.prepare(snake_case       )

						return dl




def        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case			,     snake_case			,     snake_case			,     snake_case			,     )						->				Dict:
						_UpperCAmelCase      =			create_dataloader(accelerator=snake_case			,     dataset_size=snake_case			,     batch_size=snake_case       )

						_UpperCAmelCase      =			[len(batch[0]       ) for batch in dl]

						if accelerator.process_index == 0:
												assert batch_sizes == process_0_expected_batch_sizes
						elif accelerator.process_index == 1:
												assert batch_sizes == process_1_expected_batch_sizes




def        _SCREAMING_SNAKE_CASE      (		)						->				Dict:
						_UpperCAmelCase      =			create_accelerator()

						# without padding, we would expect a different number of batches
						verify_dataloader_batch_sizes(
						    snake_case			,     dataset_size=3			,     batch_size=1			,     process_0_expected_batch_sizes=[1, 1]			,     process_1_expected_batch_sizes=[1, 1]			,     )

						# without padding, we would expect the same number of batches, but different sizes
						verify_dataloader_batch_sizes(
						    snake_case			,     dataset_size=7			,     batch_size=2			,     process_0_expected_batch_sizes=[2, 2]			,     process_1_expected_batch_sizes=[2, 2]			,     )




def        _SCREAMING_SNAKE_CASE      (		)						->				List[Any]:
						_UpperCAmelCase      =			create_accelerator(even_batches=snake_case       )

						verify_dataloader_batch_sizes(
						    snake_case			,     dataset_size=3			,     batch_size=1			,     process_0_expected_batch_sizes=[1, 1]			,     process_1_expected_batch_sizes=[1]			,     )

						verify_dataloader_batch_sizes(
						    snake_case			,     dataset_size=7			,     batch_size=2			,     process_0_expected_batch_sizes=[2, 2]			,     process_1_expected_batch_sizes=[2, 1]			,     )




def        _SCREAMING_SNAKE_CASE      (		)						->				int:
						_UpperCAmelCase      =			create_accelerator(even_batches=snake_case       )

						_UpperCAmelCase      =			torch.nn.Linear(1			,     1       )
						_UpperCAmelCase      =			accelerator.prepare(snake_case       )

						_UpperCAmelCase      =			create_dataloader(snake_case			,     dataset_size=3			,     batch_size=1       )

						_UpperCAmelCase      =			[]
						with accelerator.join_uneven_inputs([ddp_model]       ):
												for batch_idx, batch in enumerate(snake_case       ):
																		_UpperCAmelCase      =			ddp_model(batch[0].float()       )
																		_UpperCAmelCase      =			output.sum()
																		loss.backward()
																		batch_idxs.append(snake_case       )

						accelerator.wait_for_everyone()

						if accelerator.process_index == 0:
												assert batch_idxs == [0, 1]
						elif accelerator.process_index == 1:
												assert batch_idxs == [0]




def        _SCREAMING_SNAKE_CASE      (		snake_case       )						->				int:
						with warnings.catch_warnings(record=snake_case       ) as w:
												with accelerator.join_uneven_inputs([Mock()]       ):
																		pass

												assert issubclass(w[-1].category			,     snake_case       )
												assert "only supported for multi-GPU" in str(w[-1].message       )




def        _SCREAMING_SNAKE_CASE      (		)						->				List[Any]:
						_UpperCAmelCase      =			True
						_UpperCAmelCase      =			False
						_UpperCAmelCase      =			create_accelerator(even_batches=snake_case       )
						_UpperCAmelCase      =			torch.nn.Linear(1			,     1       )
						_UpperCAmelCase      =			accelerator.prepare(snake_case       )
						_UpperCAmelCase      =			create_dataloader(snake_case			,     dataset_size=3			,     batch_size=1       )
						_UpperCAmelCase      =			create_dataloader(snake_case			,     dataset_size=3			,     batch_size=1       )

						with accelerator.join_uneven_inputs([ddp_model]			,     even_batches=snake_case       ):
												_UpperCAmelCase      =			train_dl.batch_sampler.even_batches
												_UpperCAmelCase      =			valid_dl.batch_sampler.even_batches

						assert train_dl_overridden_value == overridden_even_batches
						assert valid_dl_overridden_value == overridden_even_batches
						assert train_dl.batch_sampler.even_batches == default_even_batches
						assert valid_dl.batch_sampler.even_batches == default_even_batches




def        _SCREAMING_SNAKE_CASE      (		)						->				List[str]:
						_UpperCAmelCase      =			True
						_UpperCAmelCase      =			False
						_UpperCAmelCase      =			create_accelerator(even_batches=snake_case       )
						_UpperCAmelCase      =			torch.nn.Linear(1			,     1       )
						_UpperCAmelCase      =			accelerator.prepare(snake_case       )
						create_dataloader(snake_case			,     dataset_size=3			,     batch_size=1			,     iterable=snake_case       )
						_UpperCAmelCase      =			create_dataloader(snake_case			,     dataset_size=3			,     batch_size=1       )

						with warnings.catch_warnings():
												warnings.filterwarnings("""ignore"""       )
												try:
																		with accelerator.join_uneven_inputs([ddp_model]			,     even_batches=snake_case       ):
																								_UpperCAmelCase      =			batch_dl.batch_sampler.even_batches
												except AttributeError:
																		# ensure attribute error is not raised when processing iterable dl
																		raise AssertionError

						assert batch_dl_overridden_value == overridden_even_batches
						assert batch_dl.batch_sampler.even_batches == default_even_batches




def        _SCREAMING_SNAKE_CASE      (		)						->				Union[str, Any]:
						_UpperCAmelCase      =			create_accelerator()
						_UpperCAmelCase      =			torch.nn.Linear(1			,     1       )
						_UpperCAmelCase      =			accelerator.prepare(snake_case       )
						create_dataloader(snake_case			,     dataset_size=3			,     batch_size=1			,     iterable=snake_case       )

						with warnings.catch_warnings(record=snake_case       ) as w:
												with accelerator.join_uneven_inputs([ddp_model]			,     even_batches=snake_case       ):
																		pass

												assert issubclass(w[-1].category			,     snake_case       )
												assert "only supported for map-style datasets" in str(w[-1].message       )




def        _SCREAMING_SNAKE_CASE      (		)						->				Optional[int]:
						_UpperCAmelCase      =			create_accelerator()

						accelerator.print("""Test that even_batches variable ensures uniform batches across processes"""       )
						test_default_ensures_even_batch_sizes()

						accelerator.print("""Run tests with even_batches disabled"""       )
						test_can_disable_even_batches()

						accelerator.print("""Test joining uneven inputs"""       )
						test_can_join_uneven_inputs()

						accelerator.print("""Test overriding even_batches when joining uneven inputs"""       )
						test_join_can_override_even_batches()

						accelerator.print("""Test overriding even_batches for mixed dataloader types"""       )
						test_join_can_override_for_mixed_type_dataloaders()

						accelerator.print("""Test overriding even_batches raises a warning for iterable dataloaders"""       )
						test_join_raises_warning_for_iterable_when_overriding_even_batches()

						accelerator.print("""Test join with non DDP distributed raises warning"""       )
						_UpperCAmelCase      =			accelerator.state.distributed_type
						_UpperCAmelCase      =			DistributedType.FSDP
						test_join_raises_warning_for_non_ddp_distributed(snake_case       )
						_UpperCAmelCase      =			original_state


if __name__ == "__main__":
				main()





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        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case       )						->				int:
						assert isinstance(snake_case			,     snake_case       )
						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        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case			,     snake_case       )						->				Optional[int]:
						_UpperCAmelCase      =			tmp_path / """cache"""
						_UpperCAmelCase      =			{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
						with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
												_UpperCAmelCase      =			JsonDatasetReader(snake_case			,     cache_dir=snake_case			,     keep_in_memory=snake_case       ).read()
						_check_json_dataset(snake_case			,     snake_case       )




@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        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case			,     snake_case       )						->				Optional[Any]:
						_UpperCAmelCase      =			tmp_path / """cache"""
						_UpperCAmelCase      =			{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
						_UpperCAmelCase      =			features.copy() if features else default_expected_features
						_UpperCAmelCase      =			(
						    Features({feature: Value(snake_case       ) for feature, dtype in features.items()}       ) if features is not None else None
						)
						_UpperCAmelCase      =			JsonDatasetReader(snake_case			,     features=snake_case			,     cache_dir=snake_case       ).read()
						_check_json_dataset(snake_case			,     snake_case       )




@pytest.mark.parametrize(
    """features"""			,     [
        None,
        {"""col_3""": """float64""", """col_1""": """string""", """col_2""": """int64"""},
    ]			,     )
def        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case			,     snake_case       )						->				int:
						_UpperCAmelCase      =			tmp_path / """cache"""
						_UpperCAmelCase      =			{"""col_3""": """float64""", """col_1""": """string""", """col_2""": """int64"""}
						_UpperCAmelCase      =			features.copy() if features else default_expected_features
						_UpperCAmelCase      =			(
						    Features({feature: Value(snake_case       ) for feature, dtype in features.items()}       ) if features is not None else None
						)
						_UpperCAmelCase      =			JsonDatasetReader(snake_case			,     features=snake_case			,     cache_dir=snake_case       ).read()
						assert isinstance(snake_case			,     snake_case       )
						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        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case       )						->				Optional[int]:
						# jsonl_312_path features are {"col_3": "float64", "col_1": "string", "col_2": "int64"}
						_UpperCAmelCase      =			{"""col_2""": """int64""", """col_3""": """float64""", """col_1""": """string"""}
						_UpperCAmelCase      =			features.copy()
						_UpperCAmelCase      =			(
						    Features({feature: Value(snake_case       ) for feature, dtype in features.items()}       ) if features is not None else None
						)
						_UpperCAmelCase      =			tmp_path / """cache"""
						_UpperCAmelCase      =			JsonDatasetReader(snake_case			,     features=snake_case			,     cache_dir=snake_case       ).read()
						assert isinstance(snake_case			,     snake_case       )
						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        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case			,     snake_case       )						->				List[Any]:
						_UpperCAmelCase      =			tmp_path / """cache"""
						_UpperCAmelCase      =			{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
						_UpperCAmelCase      =			JsonDatasetReader(snake_case			,     cache_dir=snake_case			,     split=snake_case       ).read()
						_check_json_dataset(snake_case			,     snake_case       )
						assert dataset.split == split if split else "train"




@pytest.mark.parametrize("""path_type"""			,     [str, list]       )
def        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case			,     snake_case       )						->				Any:
						if issubclass(snake_case			,     snake_case       ):
												_UpperCAmelCase      =			jsonl_path
						elif issubclass(snake_case			,     snake_case       ):
												_UpperCAmelCase      =			[jsonl_path]
						_UpperCAmelCase      =			tmp_path / """cache"""
						_UpperCAmelCase      =			{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
						_UpperCAmelCase      =			JsonDatasetReader(snake_case			,     cache_dir=snake_case       ).read()
						_check_json_dataset(snake_case			,     snake_case       )




def        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case			,     snake_case=("train",)       )						->				str:
						assert isinstance(snake_case			,     snake_case       )
						for split in splits:
												_UpperCAmelCase      =			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        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case			,     snake_case       )						->				str:
						_UpperCAmelCase      =			tmp_path / """cache"""
						_UpperCAmelCase      =			{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
						with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
												_UpperCAmelCase      =			JsonDatasetReader({"""train""": jsonl_path}			,     cache_dir=snake_case			,     keep_in_memory=snake_case       ).read()
						_check_json_datasetdict(snake_case			,     snake_case       )




@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        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case			,     snake_case       )						->				Tuple:
						_UpperCAmelCase      =			tmp_path / """cache"""
						_UpperCAmelCase      =			{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
						_UpperCAmelCase      =			features.copy() if features else default_expected_features
						_UpperCAmelCase      =			(
						    Features({feature: Value(snake_case       ) for feature, dtype in features.items()}       ) if features is not None else None
						)
						_UpperCAmelCase      =			JsonDatasetReader({"""train""": jsonl_path}			,     features=snake_case			,     cache_dir=snake_case       ).read()
						_check_json_datasetdict(snake_case			,     snake_case       )




@pytest.mark.parametrize("""split"""			,     [None, NamedSplit("""train"""       ), """train""", """test"""]       )
def        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case			,     snake_case       )						->				Optional[Any]:
						if split:
												_UpperCAmelCase      =			{split: jsonl_path}
						else:
												_UpperCAmelCase      =			"""train"""
												_UpperCAmelCase      =			{"""train""": jsonl_path, """test""": jsonl_path}
						_UpperCAmelCase      =			tmp_path / """cache"""
						_UpperCAmelCase      =			{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
						_UpperCAmelCase      =			JsonDatasetReader(snake_case			,     cache_dir=snake_case       ).read()
						_check_json_datasetdict(snake_case			,     snake_case			,     splits=list(path.keys()       )       )
						assert all(dataset[split].split == split for split in path.keys()       )




def        _SCREAMING_SNAKE_CASE      (		snake_case       )						->				List[Any]:
						return json.load(snake_case       )




def        _SCREAMING_SNAKE_CASE      (		snake_case       )						->				List[Any]:
						return [json.loads(snake_case       ) for line in buffer]




class       _A				:






		@pytest.mark.parametrize("""lines, load_json_function"""						,		[(True, load_json_lines), (False, load_json)]			)
		def 				UpperCAmelCase (    self						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE			):
								with io.BytesIO() as buffer:
														JsonDatasetWriter(_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		lines=_SCREAMING_SNAKE_CASE			).write()
														buffer.seek(0			)
														_UpperCAmelCase      =			load_json_function(_SCREAMING_SNAKE_CASE			)
								assert isinstance(_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE			)
								assert isinstance(exported_content[0]						,		_SCREAMING_SNAKE_CASE			)
								assert len(_SCREAMING_SNAKE_CASE			) == 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 				UpperCAmelCase (    self						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE			):
								with io.BytesIO() as buffer:
														JsonDatasetWriter(_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		lines=_SCREAMING_SNAKE_CASE						,		orient=_SCREAMING_SNAKE_CASE			).write()
														buffer.seek(0			)
														_UpperCAmelCase      =			load_json(_SCREAMING_SNAKE_CASE			)
								assert isinstance(_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE			)
								if keys:
														if container is dict:
																				assert exported_content.keys() == keys
														else:
																				assert exported_content[0].keys() == keys
								else:
														assert not hasattr(_SCREAMING_SNAKE_CASE						,		"""keys"""			) and not hasattr(exported_content[0]						,		"""keys"""			)
								if len_at:
														assert len(exported_content[len_at]			) == 10
								else:
														assert len(_SCREAMING_SNAKE_CASE			) == 10






		@pytest.mark.parametrize("""lines, load_json_function"""						,		[(True, load_json_lines), (False, load_json)]			)
		def 				UpperCAmelCase (    self						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE			):
								with io.BytesIO() as buffer:
														JsonDatasetWriter(_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		lines=_SCREAMING_SNAKE_CASE						,		num_proc=2			).write()
														buffer.seek(0			)
														_UpperCAmelCase      =			load_json_function(_SCREAMING_SNAKE_CASE			)
								assert isinstance(_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE			)
								assert isinstance(exported_content[0]						,		_SCREAMING_SNAKE_CASE			)
								assert len(_SCREAMING_SNAKE_CASE			) == 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 				UpperCAmelCase (    self						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE			):
								with io.BytesIO() as buffer:
														JsonDatasetWriter(_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		lines=_SCREAMING_SNAKE_CASE						,		orient=_SCREAMING_SNAKE_CASE						,		num_proc=2			).write()
														buffer.seek(0			)
														_UpperCAmelCase      =			load_json(_SCREAMING_SNAKE_CASE			)
								assert isinstance(_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE			)
								if keys:
														if container is dict:
																				assert exported_content.keys() == keys
														else:
																				assert exported_content[0].keys() == keys
								else:
														assert not hasattr(_SCREAMING_SNAKE_CASE						,		"""keys"""			) and not hasattr(exported_content[0]						,		"""keys"""			)
								if len_at:
														assert len(exported_content[len_at]			) == 10
								else:
														assert len(_SCREAMING_SNAKE_CASE			) == 10






		def 				UpperCAmelCase (    self						,		_SCREAMING_SNAKE_CASE			):
								with pytest.raises(_SCREAMING_SNAKE_CASE			):
														with io.BytesIO() as buffer:
																				JsonDatasetWriter(_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		num_proc=0			)






		@pytest.mark.parametrize("""compression, extension"""						,		[("""gzip""", """gz"""), ("""bz2""", """bz2"""), ("""xz""", """xz""")]			)
		def 				UpperCAmelCase (    self						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE			):
								_UpperCAmelCase      =			tmp_path_factory.mktemp("""data"""			) / F"test.json.{extension}"
								_UpperCAmelCase      =			str(shared_datadir / F"test_file.json.{extension}"			)
								JsonDatasetWriter(_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE						,		compression=_SCREAMING_SNAKE_CASE			).write()

								with fsspec.open(_SCREAMING_SNAKE_CASE						,		"""rb"""						,		compression="""infer"""			) as f:
														_UpperCAmelCase      =			f.read()
								with fsspec.open(_SCREAMING_SNAKE_CASE						,		"""rb"""						,		compression="""infer"""			) as f:
														_UpperCAmelCase      =			f.read()
								assert exported_content == original_content