


'''simple docstring'''




import contextlib
import csv
import json
import os
import sqlitea
import tarfile
import textwrap
import zipfile

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

import datasets
import datasets.config





@pytest.fixture(scope='session'						)
def   _a		()			->			Union[str, Any]:






     """simple docstring"""
     __snake_case           =						1_0
     __snake_case           =						datasets.Features(
         {
             'tokens': datasets.Sequence(datasets.Value('string'						)						),
             'labels': datasets.Sequence(datasets.ClassLabel(names=['negative', 'positive']						)						),
             'answers': datasets.Sequence(
                 {
                     'text': datasets.Value('string'						),
                     'answer_start': datasets.Value('int32'						),
                 }						),
             'id': datasets.Value('int64'						),
         }						)
     __snake_case           =						datasets.Dataset.from_dict(
         {
             'tokens': [['foo'] * 5] * n,
             'labels': [[1] * 5] * n,
             'answers': [{'answer_start': [9_7], 'text': ['1976']}] * 1_0,
             'id': list(range(lowercase__						)						),
         }							,   features=lowercase__							,   )
     return dataset





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Tuple							,   lowercase__			:   Dict						)			->			Tuple:






     """simple docstring"""
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'file.arrow'						)
     dataset.map(cache_file_name=lowercase__						)
     return filename


# FILE_CONTENT + files


_a   :   Union[str, Any]												=   "\\n    Text data.\n    Second line of data."





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[Any]						)			->			List[str]:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'file.txt'
     __snake_case           =						FILE_CONTENT
     with open(lowercase__							,   'w'						) as f:
          f.write(lowercase__						)
     return filename





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Optional[Any]						)			->			Optional[int]:






     """simple docstring"""
     import bza

     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'file.txt.bz2'
     __snake_case           =						bytes(lowercase__							,   'utf-8'						)
     with bza.open(lowercase__							,   'wb'						) as f:
          f.write(lowercase__						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Union[str, Any]						)			->			Dict:






     """simple docstring"""
     import gzip

     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'file.txt.gz'						)
     __snake_case           =						bytes(lowercase__							,   'utf-8'						)
     with gzip.open(lowercase__							,   'wb'						) as f:
          f.write(lowercase__						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Tuple						)			->			Optional[int]:






     """simple docstring"""
     if datasets.config.LZ4_AVAILABLE:
          import lza.frame

          __snake_case           =						tmp_path_factory.mktemp('data'						) / 'file.txt.lz4'
          __snake_case           =						bytes(lowercase__							,   'utf-8'						)
          with lza.frame.open(lowercase__							,   'wb'						) as f:
               f.write(lowercase__						)
          return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Dict							,   lowercase__			:   Tuple						)			->			Tuple:






     """simple docstring"""
     if datasets.config.PY7ZR_AVAILABLE:
          import pyazr

          __snake_case           =						tmp_path_factory.mktemp('data'						) / 'file.txt.7z'
          with pyazr.SevenZipFile(lowercase__							,   'w'						) as archive:
               archive.write(lowercase__							,   arcname=os.path.basename(lowercase__						)						)
          return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Optional[int]							,   lowercase__			:   Union[str, Any]						)			->			Tuple:






     """simple docstring"""
     import tarfile

     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'file.txt.tar'
     with tarfile.TarFile(lowercase__							,   'w'						) as f:
          f.add(lowercase__							,   arcname=os.path.basename(lowercase__						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[Any]						)			->			Tuple:






     """simple docstring"""
     import lzma

     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'file.txt.xz'
     __snake_case           =						bytes(lowercase__							,   'utf-8'						)
     with lzma.open(lowercase__							,   'wb'						) as f:
          f.write(lowercase__						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Dict							,   lowercase__			:   str						)			->			Union[str, Any]:






     """simple docstring"""
     import zipfile

     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'file.txt.zip'
     with zipfile.ZipFile(lowercase__							,   'w'						) as f:
          f.write(lowercase__							,   arcname=os.path.basename(lowercase__						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[Any]						)			->			int:






     """simple docstring"""
     if datasets.config.ZSTANDARD_AVAILABLE:
          import zstandard as zstd

          __snake_case           =						tmp_path_factory.mktemp('data'						) / 'file.txt.zst'
          __snake_case           =						bytes(lowercase__							,   'utf-8'						)
          with zstd.open(lowercase__							,   'wb'						) as f:
               f.write(lowercase__						)
          return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Optional[Any]						)			->			Tuple:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'file.xml'
     __snake_case           =						textwrap.dedent(
         '\\n    <?xml version="1.0" encoding="UTF-8" ?>\n    <tmx version="1.4">\n      <header segtype="sentence" srclang="ca" />\n      <body>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 1</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 1</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 2</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 2</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 3</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 3</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 4</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 4</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 5</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 5</seg></tuv>\n        </tu>\n      </body>\n    </tmx>'						)
     with open(lowercase__							,   'w'						) as f:
          f.write(lowercase__						)
     return filename


_a   :   int												=   [
    {"col_1": "0", "col_2": 0, "col_3": 0.0},
    {"col_1": "1", "col_2": 1, "col_3": 1.0},
    {"col_1": "2", "col_2": 2, "col_3": 2.0},
    {"col_1": "3", "col_2": 3, "col_3": 3.0},
]
_a   :   List[str]												=   [
    {"col_1": "4", "col_2": 4, "col_3": 4.0},
    {"col_1": "5", "col_2": 5, "col_3": 5.0},
]
_a   :   Tuple												=   {
    "col_1": ["0", "1", "2", "3"],
    "col_2": [0, 1, 2, 3],
    "col_3": [0.0, 1.0, 2.0, 3.0],
}

_a   :   Optional[int]												=   [
    {"col_3": 0.0, "col_1": "0", "col_2": 0},
    {"col_3": 1.0, "col_1": "1", "col_2": 1},
]

_a   :   Any												=   [
    {"col_1": "s0", "col_2": 0, "col_3": 0.0},
    {"col_1": "s1", "col_2": 1, "col_3": 1.0},
    {"col_1": "s2", "col_2": 2, "col_3": 2.0},
    {"col_1": "s3", "col_2": 3, "col_3": 3.0},
]





@pytest.fixture(scope='session'						)
def   _a		()			->			Optional[Any]:






     """simple docstring"""
     return DATA_DICT_OF_LISTS





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Optional[Any]						)			->			List[Any]:






     """simple docstring"""
     __snake_case           =						datasets.Dataset.from_dict(lowercase__						)
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset.arrow'						)
     dataset.map(cache_file_name=lowercase__						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Any						)			->			Dict:






     """simple docstring"""
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset.sqlite'						)
     with contextlib.closing(sqlitea.connect(lowercase__						)						) as con:
          __snake_case           =						con.cursor()
          cur.execute('CREATE TABLE dataset(col_1 text, col_2 int, col_3 real)'						)
          for item in DATA:
               cur.execute('INSERT INTO dataset(col_1, col_2, col_3) VALUES (?, ?, ?)'							,   tuple(item.values()						)						)
          con.commit()
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[Any]						)			->			Tuple:






     """simple docstring"""
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset.csv'						)
     with open(lowercase__							,   'w'							,   newline=''						) as f:
          __snake_case           =						csv.DictWriter(lowercase__							,   fieldnames=['col_1', 'col_2', 'col_3']						)
          writer.writeheader()
          for item in DATA:
               writer.writerow(lowercase__						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[Any]						)			->			Tuple:






     """simple docstring"""
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset2.csv'						)
     with open(lowercase__							,   'w'							,   newline=''						) as f:
          __snake_case           =						csv.DictWriter(lowercase__							,   fieldnames=['col_1', 'col_2', 'col_3']						)
          writer.writeheader()
          for item in DATA:
               writer.writerow(lowercase__						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   str							,   lowercase__			:   Optional[Any]						)			->			List[str]:






     """simple docstring"""
     import bza

     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset.csv.bz2'
     with open(lowercase__							,   'rb'						) as f:
          __snake_case           =						f.read()
     # data = bytes(FILE_CONTENT, "utf-8")
     with bza.open(lowercase__							,   'wb'						) as f:
          f.write(lowercase__						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[Any]							,   lowercase__			:   Union[str, Any]							,   lowercase__			:   str						)			->			Optional[int]:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset.csv.zip'
     with zipfile.ZipFile(lowercase__							,   'w'						) as f:
          f.write(lowercase__							,   arcname=os.path.basename(lowercase__						)						)
          f.write(lowercase__							,   arcname=os.path.basename(lowercase__						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[str]							,   lowercase__			:   Tuple							,   lowercase__			:   int						)			->			int:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset.csv.zip'
     with zipfile.ZipFile(lowercase__							,   'w'						) as f:
          f.write(lowercase__							,   arcname=os.path.basename(csv_path.replace('.csv'							,   '.CSV'						)						)						)
          f.write(lowercase__							,   arcname=os.path.basename(csva_path.replace('.csv'							,   '.CSV'						)						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[Any]							,   lowercase__			:   Dict							,   lowercase__			:   Union[str, Any]						)			->			Optional[int]:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset_with_dir.csv.zip'
     with zipfile.ZipFile(lowercase__							,   'w'						) as f:
          f.write(lowercase__							,   arcname=os.path.join('main_dir'							,   os.path.basename(lowercase__						)						)						)
          f.write(lowercase__							,   arcname=os.path.join('main_dir'							,   os.path.basename(lowercase__						)						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[str]						)			->			int:






     """simple docstring"""
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset.parquet'						)
     __snake_case           =						pa.schema(
         {
             'col_1': pa.string(),
             'col_2': pa.intaa(),
             'col_3': pa.floataa(),
         }						)
     with open(lowercase__							,   'wb'						) as f:
          __snake_case           =						pq.ParquetWriter(lowercase__							,   schema=lowercase__						)
          __snake_case           =						pa.Table.from_pydict({k: [DATA[i][k] for i in range(len(lowercase__						)						)] for k in DATA[0]}							,   schema=lowercase__						)
          writer.write_table(lowercase__						)
          writer.close()
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[Any]						)			->			List[str]:






     """simple docstring"""
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset.json'						)
     __snake_case           =						{'data': DATA}
     with open(lowercase__							,   'w'						) as f:
          json.dump(lowercase__							,   lowercase__						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[str]						)			->			List[Any]:






     """simple docstring"""
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset.json'						)
     __snake_case           =						{'data': DATA_DICT_OF_LISTS}
     with open(lowercase__							,   'w'						) as f:
          json.dump(lowercase__							,   lowercase__						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Union[str, Any]						)			->			Optional[int]:






     """simple docstring"""
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset.jsonl'						)
     with open(lowercase__							,   'w'						) as f:
          for item in DATA:
               f.write(json.dumps(lowercase__						) + '\n'						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Optional[Any]						)			->			List[str]:






     """simple docstring"""
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset2.jsonl'						)
     with open(lowercase__							,   'w'						) as f:
          for item in DATA:
               f.write(json.dumps(lowercase__						) + '\n'						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   int						)			->			Tuple:






     """simple docstring"""
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset_312.jsonl'						)
     with open(lowercase__							,   'w'						) as f:
          for item in DATA_312:
               f.write(json.dumps(lowercase__						) + '\n'						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Dict						)			->			int:






     """simple docstring"""
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset-str.jsonl'						)
     with open(lowercase__							,   'w'						) as f:
          for item in DATA_STR:
               f.write(json.dumps(lowercase__						) + '\n'						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   int							,   lowercase__			:   List[Any]						)			->			Dict:






     """simple docstring"""
     import gzip

     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset.txt.gz'						)
     with open(lowercase__							,   'rb'						) as orig_file:
          with gzip.open(lowercase__							,   'wb'						) as zipped_file:
               zipped_file.writelines(lowercase__						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Union[str, Any]							,   lowercase__			:   Dict						)			->			Optional[Any]:






     """simple docstring"""
     import gzip

     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset.jsonl.gz'						)
     with open(lowercase__							,   'rb'						) as orig_file:
          with gzip.open(lowercase__							,   'wb'						) as zipped_file:
               zipped_file.writelines(lowercase__						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   str							,   lowercase__			:   str							,   lowercase__			:   str						)			->			Optional[int]:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset.jsonl.zip'
     with zipfile.ZipFile(lowercase__							,   'w'						) as f:
          f.write(lowercase__							,   arcname=os.path.basename(lowercase__						)						)
          f.write(lowercase__							,   arcname=os.path.basename(lowercase__						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Dict							,   lowercase__			:   Optional[int]							,   lowercase__			:   List[Any]							,   lowercase__			:   List[Any]						)			->			str:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset_nested.jsonl.zip'
     with zipfile.ZipFile(lowercase__							,   'w'						) as f:
          f.write(lowercase__							,   arcname=os.path.join('nested'							,   os.path.basename(lowercase__						)						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Optional[Any]							,   lowercase__			:   Union[str, Any]							,   lowercase__			:   str						)			->			Optional[Any]:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset_with_dir.jsonl.zip'
     with zipfile.ZipFile(lowercase__							,   'w'						) as f:
          f.write(lowercase__							,   arcname=os.path.join('main_dir'							,   os.path.basename(lowercase__						)						)						)
          f.write(lowercase__							,   arcname=os.path.join('main_dir'							,   os.path.basename(lowercase__						)						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   str							,   lowercase__			:   Optional[int]							,   lowercase__			:   Tuple						)			->			List[Any]:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset.jsonl.tar'
     with tarfile.TarFile(lowercase__							,   'w'						) as f:
          f.add(lowercase__							,   arcname=os.path.basename(lowercase__						)						)
          f.add(lowercase__							,   arcname=os.path.basename(lowercase__						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Tuple							,   lowercase__			:   Tuple							,   lowercase__			:   Dict							,   lowercase__			:   int						)			->			Optional[Any]:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset_nested.jsonl.tar'
     with tarfile.TarFile(lowercase__							,   'w'						) as f:
          f.add(lowercase__							,   arcname=os.path.join('nested'							,   os.path.basename(lowercase__						)						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Tuple						)			->			Union[str, Any]:






     """simple docstring"""
     __snake_case           =						['0', '1', '2', '3']
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset.txt'						)
     with open(lowercase__							,   'w'						) as f:
          for item in data:
               f.write(item + '\n'						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[str]						)			->			List[Any]:






     """simple docstring"""
     __snake_case           =						['0', '1', '2', '3']
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset2.txt'						)
     with open(lowercase__							,   'w'						) as f:
          for item in data:
               f.write(item + '\n'						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Optional[int]						)			->			Dict:






     """simple docstring"""
     __snake_case           =						['0', '1', '2', '3']
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset.abc'
     with open(lowercase__							,   'w'						) as f:
          for item in data:
               f.write(item + '\n'						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[str]							,   lowercase__			:   Union[str, Any]							,   lowercase__			:   Any						)			->			str:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset.text.zip'
     with zipfile.ZipFile(lowercase__							,   'w'						) as f:
          f.write(lowercase__							,   arcname=os.path.basename(lowercase__						)						)
          f.write(lowercase__							,   arcname=os.path.basename(lowercase__						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Tuple							,   lowercase__			:   Any							,   lowercase__			:   Tuple						)			->			List[Any]:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset_with_dir.text.zip'
     with zipfile.ZipFile(lowercase__							,   'w'						) as f:
          f.write(lowercase__							,   arcname=os.path.join('main_dir'							,   os.path.basename(lowercase__						)						)						)
          f.write(lowercase__							,   arcname=os.path.join('main_dir'							,   os.path.basename(lowercase__						)						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Optional[Any]							,   lowercase__			:   Optional[int]							,   lowercase__			:   Any						)			->			Union[str, Any]:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset.ext.zip'
     with zipfile.ZipFile(lowercase__							,   'w'						) as f:
          f.write(lowercase__							,   arcname=os.path.basename('unsupported.ext'						)						)
          f.write(lowercase__							,   arcname=os.path.basename('unsupported_2.ext'						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   Any						)			->			List[Any]:






     """simple docstring"""
     __snake_case           =						'\n'.join(['First', 'Second\u2029with Unicode new line', 'Third']						)
     __snake_case           =						str(tmp_path_factory.mktemp('data'						) / 'dataset_with_unicode_new_lines.txt'						)
     with open(lowercase__							,   'w'							,   encoding='utf-8'						) as f:
          f.write(lowercase__						)
     return path





@pytest.fixture(scope='session'						)
def   _a		()			->			int:






     """simple docstring"""
     return os.path.join('tests'							,   'features'							,   'data'							,   'test_image_rgb.jpg'						)





@pytest.fixture(scope='session'						)
def   _a		()			->			Optional[int]:






     """simple docstring"""
     return os.path.join('tests'							,   'features'							,   'data'							,   'test_audio_44100.wav'						)





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   List[Any]							,   lowercase__			:   Union[str, Any]						)			->			List[str]:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data'						) / 'dataset.img.zip'
     with zipfile.ZipFile(lowercase__							,   'w'						) as f:
          f.write(lowercase__							,   arcname=os.path.basename(lowercase__						)						)
          f.write(lowercase__							,   arcname=os.path.basename(lowercase__						).replace('.jpg'							,   '2.jpg'						)						)
     return path





@pytest.fixture(scope='session'						)
def   _a		(lowercase__			:   str						)			->			List[Any]:






     """simple docstring"""
     __snake_case           =						tmp_path_factory.mktemp('data_dir'						)

     (data_dir / "subdir").mkdir()
     with open(data_dir / 'subdir' / 'train.txt'							,   'w'						) as f:
          f.write('foo\n' * 1_0						)
     with open(data_dir / 'subdir' / 'test.txt'							,   'w'						) as f:
          f.write('bar\n' * 1_0						)
     # hidden file
     with open(data_dir / 'subdir' / '.test.txt'							,   'w'						) as f:
          f.write('bar\n' * 1_0						)

     # hidden directory
     (data_dir / ".subdir").mkdir()
     with open(data_dir / '.subdir' / 'train.txt'							,   'w'						) as f:
          f.write('foo\n' * 1_0						)
     with open(data_dir / '.subdir' / 'test.txt'							,   'w'						) as f:
          f.write('bar\n' * 1_0						)

     return data_dir








import unittest

from transformers import BigBirdConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
				import jax

				from transformers.models.big_bird.modeling_flax_big_bird import (
				    FlaxBigBirdForCausalLM,
				    FlaxBigBirdForMaskedLM,
				    FlaxBigBirdForMultipleChoice,
				    FlaxBigBirdForPreTraining,
				    FlaxBigBirdForQuestionAnswering,
				    FlaxBigBirdForSequenceClassification,
				    FlaxBigBirdForTokenClassification,
				    FlaxBigBirdModel,
				)






class    _UpperCamelCase     (       unittest.TestCase					):

				"""simple docstring"""







				def __init__(    self					, a__					, a__=2					, a__=56					, a__=True					, a__=True					, a__=True					, a__=True					, a__=99					, a__=32					, a__=2					, a__=2					, a__=7					, a__="gelu_new"					, a__=0.1					, a__=0.1					, a__=512					, a__=16					, a__=2					, a__=0.02					, a__=4					, a__="block_sparse"					, a__=True					, a__=False					, a__=2					, a__=3					, )						->					List[Any]:
					A             =					parent
					A             =					batch_size
					A             =					seq_length
					A             =					is_training
					A             =					use_attention_mask
					A             =					use_token_type_ids
					A             =					use_labels
					A             =					vocab_size
					A             =					hidden_size
					A             =					num_hidden_layers
					A             =					num_attention_heads
					A             =					intermediate_size
					A             =					hidden_act
					A             =					hidden_dropout_prob
					A             =					attention_probs_dropout_prob
					A             =					max_position_embeddings
					A             =					type_vocab_size
					A             =					type_sequence_label_size
					A             =					initializer_range
					A             =					num_choices

					A             =					rescale_embeddings
					A             =					attention_type
					A             =					use_bias
					A             =					block_size
					A             =					num_random_blocks

				def   _UpperCAmelCase       (    self )						->					List[Any]:
					A             =					ids_tensor([self.batch_size, self.seq_length]					, self.vocab_size )

					A             =					None
					if self.use_attention_mask:
						A             =					random_attention_mask([self.batch_size, self.seq_length] )

					A             =					None
					if self.use_token_type_ids:
						A             =					ids_tensor([self.batch_size, self.seq_length]					, self.type_vocab_size )

					A             =					BigBirdConfig(
					    vocab_size=self.vocab_size					, hidden_size=self.hidden_size					, num_hidden_layers=self.num_hidden_layers					, num_attention_heads=self.num_attention_heads					, intermediate_size=self.intermediate_size					, hidden_act=self.hidden_act					, hidden_dropout_prob=self.hidden_dropout_prob					, attention_probs_dropout_prob=self.attention_probs_dropout_prob					, max_position_embeddings=self.max_position_embeddings					, type_vocab_size=self.type_vocab_size					, is_decoder=a__					, initializer_range=self.initializer_range					, attention_type=self.attention_type					, block_size=self.block_size					, num_random_blocks=self.num_random_blocks					, use_bias=self.use_bias					, rescale_embeddings=self.rescale_embeddings					, )

					return config, input_ids, token_type_ids, attention_mask

				def   _UpperCAmelCase       (    self )						->					Optional[int]:
					A             =					self.prepare_config_and_inputs()
					A       ,      A       ,      A       ,      A             =					config_and_inputs
					A             =					{
					    """input_ids""": input_ids,
					    """token_type_ids""": token_type_ids,
					    """attention_mask""": attention_mask,
					}
					return config, inputs_dict






@require_flax
class    _UpperCamelCase     (       __snake_case     ,		unittest.TestCase					):

				"""simple docstring"""







				lowerCAmelCase					=			(
				    (
				        FlaxBigBirdForCausalLM,
				        FlaxBigBirdModel,
				        FlaxBigBirdForPreTraining,
				        FlaxBigBirdForMaskedLM,
				        FlaxBigBirdForMultipleChoice,
				        FlaxBigBirdForQuestionAnswering,
				        FlaxBigBirdForSequenceClassification,
				        FlaxBigBirdForTokenClassification,
				    )
				    if is_flax_available()
				    else ()
				)

				lowerCAmelCase					=			False
				lowerCAmelCase					=			False

				def   _UpperCAmelCase       (    self )						->					Optional[int]:
					A             =					FlaxBigBirdModelTester(self )

				@slow
				# copied from `test_modeling_flax_common` because it takes much longer than other models
				def   _UpperCAmelCase       (    self )						->					Tuple:
					super().test_from_pretrained_save_pretrained()

				@slow
				# copied from `test_modeling_flax_common` because it takes much longer than other models
				def   _UpperCAmelCase       (    self )						->					Dict:
					super().test_from_pretrained_with_no_automatic_init()

				@slow
				# copied from `test_modeling_flax_common` because it takes much longer than other models
				def   _UpperCAmelCase       (    self )						->					str:
					super().test_no_automatic_init()

				@slow
				# copied from `test_modeling_flax_common` because it takes much longer than other models
				def   _UpperCAmelCase       (    self )						->					List[Any]:
					super().test_hidden_states_output()

				@slow
				def   _UpperCAmelCase       (    self )						->					str:
					for model_class_name in self.all_model_classes:
						A             =					model_class_name.from_pretrained("""google/bigbird-roberta-base""" )
						self.assertIsNotNone(a__ )

				def   _UpperCAmelCase       (    self )						->					Optional[int]:
					if self.test_attn_probs:
						super().test_attention_outputs()

				@slow
				# copied from `test_modeling_flax_common` because it takes much longer than other models
				def   _UpperCAmelCase       (    self )						->					List[Any]:
					A       ,      A             =					self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
						with self.subTest(model_class.__name__ ):
							A             =					self._prepare_for_class(a__					, a__ )
							A             =					model_class(a__ )

							@jax.jit
							def model_jitted(a__					, a__=None					, **a__ ):
								return model(input_ids=a__					, attention_mask=a__					, **a__ )

							with self.subTest("""JIT Enabled""" ):
								A             =					model_jitted(**a__ ).to_tuple()

							with self.subTest("""JIT Disabled""" ):
								with jax.disable_jit():
									A             =					model_jitted(**a__ ).to_tuple()

							self.assertEqual(len(a__ )					, len(a__ ) )
							for jitted_output, output in zip(a__					, a__ ):
								self.assertEqual(jitted_output.shape					, output.shape )

				def   _UpperCAmelCase       (    self					, a__					, a__					, a__					, a__=1e-5					, a__="outputs"					, a__=None )						->					Tuple:
					# `bigbird_block_sparse_attention` in `FlaxBigBird` returns `attention_probs = None`, while in PyTorch version,
					# an effort was done to return `attention_probs` (yet to be verified).
					if name.startswith("""outputs.attentions""" ):
						return
					else:
						super().check_pt_flax_outputs(a__					, a__					, a__					, a__					, a__					, a__ )



