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    __lowercase     (						):
 UpperCamelCase_					:						List[Any] =					10
 UpperCamelCase_					:						Optional[Any] =					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'	),
     }	)
 UpperCamelCase_					:						str =					datasets.Dataset.from_dict(
     {
         'tokens': [['foo'] * 5] * n,
         'labels': [[1] * 5] * n,
         'answers': [{'answer_start': [97], 'text': ['1976']}] * 10,
         'id': list(range(__UpperCamelCase	)	),
     }  ,  features=__UpperCamelCase  ,  )
 return dataset





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     List[str]  ,  lowerCamelCase					:     Union[str, Any]	):
 UpperCamelCase_					:						List[str] =					str(tmp_path_factory.mktemp('data'	) / 'file.arrow'	)
 dataset.map(cache_file_name=__UpperCamelCase	)
 return filename


# FILE_CONTENT + files


a_    					=       '\\n    Text data.\n    Second line of data.'





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     List[Any]	):
 UpperCamelCase_					:						Any =					tmp_path_factory.mktemp('data'	) / 'file.txt'
 UpperCamelCase_					:						List[str] =					FILE_CONTENT
 with open(__UpperCamelCase  ,  'w'	) as f:
  f.write(__UpperCamelCase	)
 return filename





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Optional[Any]	):
 import bza

 UpperCamelCase_					:						str =					tmp_path_factory.mktemp('data'	) / 'file.txt.bz2'
 UpperCamelCase_					:						Union[str, Any] =					bytes(__UpperCamelCase  ,  'utf-8'	)
 with bza.open(__UpperCamelCase  ,  'wb'	) as f:
  f.write(__UpperCamelCase	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Optional[int]	):
 import gzip

 UpperCamelCase_					:						Optional[Any] =					str(tmp_path_factory.mktemp('data'	) / 'file.txt.gz'	)
 UpperCamelCase_					:						List[str] =					bytes(__UpperCamelCase  ,  'utf-8'	)
 with gzip.open(__UpperCamelCase  ,  'wb'	) as f:
  f.write(__UpperCamelCase	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Tuple	):







 if datasets.config.LZ4_AVAILABLE:
  import lza.frame

  UpperCamelCase_					:						str =					tmp_path_factory.mktemp('data'	) / 'file.txt.lz4'
  UpperCamelCase_					:						List[str] =					bytes(__UpperCamelCase  ,  'utf-8'	)
  with lza.frame.open(__UpperCamelCase  ,  'wb'	) as f:
   f.write(__UpperCamelCase	)
  return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Union[str, Any]  ,  lowerCamelCase					:     List[str]	):







 if datasets.config.PY7ZR_AVAILABLE:
  import pyazr

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





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Union[str, Any]  ,  lowerCamelCase					:     Dict	):
 import tarfile

 UpperCamelCase_					:						List[Any] =					tmp_path_factory.mktemp('data'	) / 'file.txt.tar'
 with tarfile.TarFile(__UpperCamelCase  ,  'w'	) as f:
  f.add(__UpperCamelCase  ,  arcname=os.path.basename(__UpperCamelCase	)	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Any	):
 import lzma

 UpperCamelCase_					:						List[Any] =					tmp_path_factory.mktemp('data'	) / 'file.txt.xz'
 UpperCamelCase_					:						int =					bytes(__UpperCamelCase  ,  'utf-8'	)
 with lzma.open(__UpperCamelCase  ,  'wb'	) as f:
  f.write(__UpperCamelCase	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Optional[int]  ,  lowerCamelCase					:     str	):
 import zipfile

 UpperCamelCase_					:						List[Any] =					tmp_path_factory.mktemp('data'	) / 'file.txt.zip'
 with zipfile.ZipFile(__UpperCamelCase  ,  'w'	) as f:
  f.write(__UpperCamelCase  ,  arcname=os.path.basename(__UpperCamelCase	)	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Any	):







 if datasets.config.ZSTANDARD_AVAILABLE:
  import zstandard as zstd

  UpperCamelCase_					:						List[Any] =					tmp_path_factory.mktemp('data'	) / 'file.txt.zst'
  UpperCamelCase_					:						int =					bytes(__UpperCamelCase  ,  'utf-8'	)
  with zstd.open(__UpperCamelCase  ,  'wb'	) as f:
   f.write(__UpperCamelCase	)
  return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Dict	):
 UpperCamelCase_					:						Any =					tmp_path_factory.mktemp('data'	) / 'file.xml'
 UpperCamelCase_					:						List[Any] =					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(__UpperCamelCase  ,  'w'	) as f:
  f.write(__UpperCamelCase	)
 return filename


a_    					=       [
    {'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_    					=       [
    {'col_1': '4', 'col_2': 4, 'col_3': 4.0},
    {'col_1': '5', 'col_2': 5, 'col_3': 5.0},
]
a_    					=       {
    'col_1': ['0', '1', '2', '3'],
    'col_2': [0, 1, 2, 3],
    'col_3': [0.0, 1.0, 2.0, 3.0],
}

a_    					=       [
    {'col_3': 0.0, 'col_1': '0', 'col_2': 0},
    {'col_3': 1.0, 'col_1': '1', 'col_2': 1},
]

a_    					=       [
    {'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    __lowercase     (						):
 return DATA_DICT_OF_LISTS





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Any	):
 UpperCamelCase_					:						List[str] =					datasets.Dataset.from_dict(__UpperCamelCase	)
 UpperCamelCase_					:						int =					str(tmp_path_factory.mktemp('data'	) / 'dataset.arrow'	)
 dataset.map(cache_file_name=__UpperCamelCase	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Tuple	):
 UpperCamelCase_					:						Optional[Any] =					str(tmp_path_factory.mktemp('data'	) / 'dataset.sqlite'	)
 with contextlib.closing(sqlitea.connect(__UpperCamelCase	)	) as con:
  UpperCamelCase_					:						int =					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    __lowercase     (						lowerCamelCase					:     str	):
 UpperCamelCase_					:						Any =					str(tmp_path_factory.mktemp('data'	) / 'dataset.csv'	)
 with open(__UpperCamelCase  ,  'w'  ,  newline=''	) as f:
  UpperCamelCase_					:						str =					csv.DictWriter(__UpperCamelCase  ,  fieldnames=['col_1', 'col_2', 'col_3']	)
  writer.writeheader()
  for item in DATA:
   writer.writerow(__UpperCamelCase	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     List[Any]	):
 UpperCamelCase_					:						List[str] =					str(tmp_path_factory.mktemp('data'	) / 'dataset2.csv'	)
 with open(__UpperCamelCase  ,  'w'  ,  newline=''	) as f:
  UpperCamelCase_					:						int =					csv.DictWriter(__UpperCamelCase  ,  fieldnames=['col_1', 'col_2', 'col_3']	)
  writer.writeheader()
  for item in DATA:
   writer.writerow(__UpperCamelCase	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     List[Any]  ,  lowerCamelCase					:     str	):
 import bza

 UpperCamelCase_					:						Union[str, Any] =					tmp_path_factory.mktemp('data'	) / 'dataset.csv.bz2'
 with open(__UpperCamelCase  ,  'rb'	) as f:
  UpperCamelCase_					:						Optional[Any] =					f.read()
 # data = bytes(FILE_CONTENT, "utf-8")
 with bza.open(__UpperCamelCase  ,  'wb'	) as f:
  f.write(__UpperCamelCase	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     str  ,  lowerCamelCase					:     Optional[int]  ,  lowerCamelCase					:     Optional[int]	):
 UpperCamelCase_					:						str =					tmp_path_factory.mktemp('data'	) / 'dataset.csv.zip'
 with zipfile.ZipFile(__UpperCamelCase  ,  'w'	) as f:
  f.write(__UpperCamelCase  ,  arcname=os.path.basename(__UpperCamelCase	)	)
  f.write(__UpperCamelCase  ,  arcname=os.path.basename(__UpperCamelCase	)	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Any  ,  lowerCamelCase					:     Optional[int]  ,  lowerCamelCase					:     int	):
 UpperCamelCase_					:						Optional[int] =					tmp_path_factory.mktemp('data'	) / 'dataset.csv.zip'
 with zipfile.ZipFile(__UpperCamelCase  ,  'w'	) as f:
  f.write(__UpperCamelCase  ,  arcname=os.path.basename(csv_path.replace('.csv'  ,  '.CSV'	)	)	)
  f.write(__UpperCamelCase  ,  arcname=os.path.basename(csva_path.replace('.csv'  ,  '.CSV'	)	)	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Union[str, Any]  ,  lowerCamelCase					:     Union[str, Any]  ,  lowerCamelCase					:     Optional[Any]	):
 UpperCamelCase_					:						Optional[Any] =					tmp_path_factory.mktemp('data'	) / 'dataset_with_dir.csv.zip'
 with zipfile.ZipFile(__UpperCamelCase  ,  'w'	) as f:
  f.write(__UpperCamelCase  ,  arcname=os.path.join('main_dir'  ,  os.path.basename(__UpperCamelCase	)	)	)
  f.write(__UpperCamelCase  ,  arcname=os.path.join('main_dir'  ,  os.path.basename(__UpperCamelCase	)	)	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Dict	):
 UpperCamelCase_					:						List[Any] =					str(tmp_path_factory.mktemp('data'	) / 'dataset.parquet'	)
 UpperCamelCase_					:						Optional[Any] =					pa.schema(
     {
         'col_1': pa.string(),
         'col_2': pa.intaa(),
         'col_3': pa.floataa(),
     }	)
 with open(__UpperCamelCase  ,  'wb'	) as f:
  UpperCamelCase_					:						Optional[Any] =					pq.ParquetWriter(__UpperCamelCase  ,  schema=__UpperCamelCase	)
  UpperCamelCase_					:						int =					pa.Table.from_pydict({k: [DATA[i][k] for i in range(len(__UpperCamelCase	)	)] for k in DATA[0]}  ,  schema=__UpperCamelCase	)
  writer.write_table(__UpperCamelCase	)
  writer.close()
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     int	):
 UpperCamelCase_					:						Union[str, Any] =					str(tmp_path_factory.mktemp('data'	) / 'dataset.json'	)
 UpperCamelCase_					:						Dict =					{'data': DATA}
 with open(__UpperCamelCase  ,  'w'	) as f:
  json.dump(__UpperCamelCase  ,  __UpperCamelCase	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Union[str, Any]	):
 UpperCamelCase_					:						Optional[int] =					str(tmp_path_factory.mktemp('data'	) / 'dataset.json'	)
 UpperCamelCase_					:						int =					{'data': DATA_DICT_OF_LISTS}
 with open(__UpperCamelCase  ,  'w'	) as f:
  json.dump(__UpperCamelCase  ,  __UpperCamelCase	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Optional[int]	):
 UpperCamelCase_					:						str =					str(tmp_path_factory.mktemp('data'	) / 'dataset.jsonl'	)
 with open(__UpperCamelCase  ,  'w'	) as f:
  for item in DATA:
   f.write(json.dumps(__UpperCamelCase	) + '\n'	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Union[str, Any]	):
 UpperCamelCase_					:						Dict =					str(tmp_path_factory.mktemp('data'	) / 'dataset2.jsonl'	)
 with open(__UpperCamelCase  ,  'w'	) as f:
  for item in DATA:
   f.write(json.dumps(__UpperCamelCase	) + '\n'	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     int	):
 UpperCamelCase_					:						Optional[Any] =					str(tmp_path_factory.mktemp('data'	) / 'dataset_312.jsonl'	)
 with open(__UpperCamelCase  ,  'w'	) as f:
  for item in DATA_312:
   f.write(json.dumps(__UpperCamelCase	) + '\n'	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     str	):
 UpperCamelCase_					:						Optional[int] =					str(tmp_path_factory.mktemp('data'	) / 'dataset-str.jsonl'	)
 with open(__UpperCamelCase  ,  'w'	) as f:
  for item in DATA_STR:
   f.write(json.dumps(__UpperCamelCase	) + '\n'	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     str  ,  lowerCamelCase					:     Optional[Any]	):
 import gzip

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





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Any  ,  lowerCamelCase					:     List[Any]	):
 import gzip

 UpperCamelCase_					:						Union[str, Any] =					str(tmp_path_factory.mktemp('data'	) / 'dataset.jsonl.gz'	)
 with open(__UpperCamelCase  ,  'rb'	) as orig_file:
  with gzip.open(__UpperCamelCase  ,  'wb'	) as zipped_file:
   zipped_file.writelines(__UpperCamelCase	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Tuple  ,  lowerCamelCase					:     Dict  ,  lowerCamelCase					:     int	):
 UpperCamelCase_					:						Dict =					tmp_path_factory.mktemp('data'	) / 'dataset.jsonl.zip'
 with zipfile.ZipFile(__UpperCamelCase  ,  'w'	) as f:
  f.write(__UpperCamelCase  ,  arcname=os.path.basename(__UpperCamelCase	)	)
  f.write(__UpperCamelCase  ,  arcname=os.path.basename(__UpperCamelCase	)	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Optional[Any]  ,  lowerCamelCase					:     str  ,  lowerCamelCase					:     Optional[int]  ,  lowerCamelCase					:     Any	):
 UpperCamelCase_					:						str =					tmp_path_factory.mktemp('data'	) / 'dataset_nested.jsonl.zip'
 with zipfile.ZipFile(__UpperCamelCase  ,  'w'	) as f:
  f.write(__UpperCamelCase  ,  arcname=os.path.join('nested'  ,  os.path.basename(__UpperCamelCase	)	)	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Dict  ,  lowerCamelCase					:     str  ,  lowerCamelCase					:     Optional[Any]	):
 UpperCamelCase_					:						Optional[int] =					tmp_path_factory.mktemp('data'	) / 'dataset_with_dir.jsonl.zip'
 with zipfile.ZipFile(__UpperCamelCase  ,  'w'	) as f:
  f.write(__UpperCamelCase  ,  arcname=os.path.join('main_dir'  ,  os.path.basename(__UpperCamelCase	)	)	)
  f.write(__UpperCamelCase  ,  arcname=os.path.join('main_dir'  ,  os.path.basename(__UpperCamelCase	)	)	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Optional[int]  ,  lowerCamelCase					:     List[str]  ,  lowerCamelCase					:     Dict	):
 UpperCamelCase_					:						str =					tmp_path_factory.mktemp('data'	) / 'dataset.jsonl.tar'
 with tarfile.TarFile(__UpperCamelCase  ,  'w'	) as f:
  f.add(__UpperCamelCase  ,  arcname=os.path.basename(__UpperCamelCase	)	)
  f.add(__UpperCamelCase  ,  arcname=os.path.basename(__UpperCamelCase	)	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Any  ,  lowerCamelCase					:     str  ,  lowerCamelCase					:     Dict  ,  lowerCamelCase					:     Tuple	):
 UpperCamelCase_					:						Tuple =					tmp_path_factory.mktemp('data'	) / 'dataset_nested.jsonl.tar'
 with tarfile.TarFile(__UpperCamelCase  ,  'w'	) as f:
  f.add(__UpperCamelCase  ,  arcname=os.path.join('nested'  ,  os.path.basename(__UpperCamelCase	)	)	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Tuple	):
 UpperCamelCase_					:						Union[str, Any] =					['0', '1', '2', '3']
 UpperCamelCase_					:						Tuple =					str(tmp_path_factory.mktemp('data'	) / 'dataset.txt'	)
 with open(__UpperCamelCase  ,  'w'	) as f:
  for item in data:
   f.write(item + '\n'	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Optional[Any]	):
 UpperCamelCase_					:						Tuple =					['0', '1', '2', '3']
 UpperCamelCase_					:						Any =					str(tmp_path_factory.mktemp('data'	) / 'dataset2.txt'	)
 with open(__UpperCamelCase  ,  'w'	) as f:
  for item in data:
   f.write(item + '\n'	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Tuple	):
 UpperCamelCase_					:						List[str] =					['0', '1', '2', '3']
 UpperCamelCase_					:						Union[str, Any] =					tmp_path_factory.mktemp('data'	) / 'dataset.abc'
 with open(__UpperCamelCase  ,  'w'	) as f:
  for item in data:
   f.write(item + '\n'	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Tuple  ,  lowerCamelCase					:     Union[str, Any]  ,  lowerCamelCase					:     List[str]	):
 UpperCamelCase_					:						int =					tmp_path_factory.mktemp('data'	) / 'dataset.text.zip'
 with zipfile.ZipFile(__UpperCamelCase  ,  'w'	) as f:
  f.write(__UpperCamelCase  ,  arcname=os.path.basename(__UpperCamelCase	)	)
  f.write(__UpperCamelCase  ,  arcname=os.path.basename(__UpperCamelCase	)	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Union[str, Any]  ,  lowerCamelCase					:     Tuple  ,  lowerCamelCase					:     List[str]	):
 UpperCamelCase_					:						Tuple =					tmp_path_factory.mktemp('data'	) / 'dataset_with_dir.text.zip'
 with zipfile.ZipFile(__UpperCamelCase  ,  'w'	) as f:
  f.write(__UpperCamelCase  ,  arcname=os.path.join('main_dir'  ,  os.path.basename(__UpperCamelCase	)	)	)
  f.write(__UpperCamelCase  ,  arcname=os.path.join('main_dir'  ,  os.path.basename(__UpperCamelCase	)	)	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     List[Any]  ,  lowerCamelCase					:     List[Any]  ,  lowerCamelCase					:     Optional[int]	):
 UpperCamelCase_					:						Union[str, Any] =					tmp_path_factory.mktemp('data'	) / 'dataset.ext.zip'
 with zipfile.ZipFile(__UpperCamelCase  ,  'w'	) as f:
  f.write(__UpperCamelCase  ,  arcname=os.path.basename('unsupported.ext'	)	)
  f.write(__UpperCamelCase  ,  arcname=os.path.basename('unsupported_2.ext'	)	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     List[Any]	):
 UpperCamelCase_					:						int =					'\n'.join(['First', 'Second\u2029with Unicode new line', 'Third']	)
 UpperCamelCase_					:						Optional[int] =					str(tmp_path_factory.mktemp('data'	) / 'dataset_with_unicode_new_lines.txt'	)
 with open(__UpperCamelCase  ,  'w'  ,  encoding='utf-8'	) as f:
  f.write(__UpperCamelCase	)
 return path





@pytest.fixture(scope='session'	)
def    __lowercase     (						):
 return os.path.join('tests'  ,  'features'  ,  'data'  ,  'test_image_rgb.jpg'	)





@pytest.fixture(scope='session'	)
def    __lowercase     (						):
 return os.path.join('tests'  ,  'features'  ,  'data'  ,  'test_audio_44100.wav'	)





@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     int  ,  lowerCamelCase					:     Tuple	):
 UpperCamelCase_					:						Tuple =					tmp_path_factory.mktemp('data'	) / 'dataset.img.zip'
 with zipfile.ZipFile(__UpperCamelCase  ,  'w'	) as f:
  f.write(__UpperCamelCase  ,  arcname=os.path.basename(__UpperCamelCase	)	)
  f.write(__UpperCamelCase  ,  arcname=os.path.basename(__UpperCamelCase	).replace('.jpg'  ,  '2.jpg'	)	)
 return path






@pytest.fixture(scope='session'	)
def    __lowercase     (						lowerCamelCase					:     Optional[Any]	):
 UpperCamelCase_					:						List[str] =					tmp_path_factory.mktemp('data_dir'	)

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

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

 return data_dir











"""simple docstring"""


import unittest

import numpy as np

from transformers import RoFormerConfig, 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.numpy as jnp

       from transformers.models.roformer.modeling_flax_roformer import (
           FlaxRoFormerForMaskedLM,
           FlaxRoFormerForMultipleChoice,
           FlaxRoFormerForQuestionAnswering,
           FlaxRoFormerForSequenceClassification,
           FlaxRoFormerForTokenClassification,
           FlaxRoFormerModel,
       )


class 					snake_case		(							unittest.TestCase						):


   '''simple docstring'''

   def __init__(	self :     Optional[Any],       _lowerCamelCase :     Tuple,       _lowerCamelCase :     List[str]=13,       _lowerCamelCase :     Optional[Any]=7,       _lowerCamelCase :     Optional[int]=True,       _lowerCamelCase :     int=True,       _lowerCamelCase :     List[str]=True,       _lowerCamelCase :     Optional[Any]=True,       _lowerCamelCase :     int=99,       _lowerCamelCase :     Optional[int]=32,       _lowerCamelCase :     Tuple=5,       _lowerCamelCase :     Tuple=4,       _lowerCamelCase :     str=37,       _lowerCamelCase :     Union[str, Any]="gelu",       _lowerCamelCase :     int=0.1,       _lowerCamelCase :     List[Any]=0.1,       _lowerCamelCase :     Dict=5_12,       _lowerCamelCase :     List[Any]=16,       _lowerCamelCase :     Any=2,       _lowerCamelCase :     Any=0.02,       _lowerCamelCase :     Dict=4,       ):

     '''simple docstring'''
     __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


   def 				_SCREAMING_SNAKE_CASE				(	self :     Any  ):

     '''simple docstring'''
     __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									= RoFormerConfig(
         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=_lowerCamelCase,       initializer_range=self.initializer_range,       )

     return config, input_ids, token_type_ids, attention_mask






   def 				_SCREAMING_SNAKE_CASE				(	self :     Optional[int]  ):

     '''simple docstring'''
     __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 					snake_case		(							_lowerCAmelCase   ,	unittest.TestCase						):


   '''simple docstring'''

   A_						:	Dict						 = True

   A_						:	Tuple						 = (
       (
           FlaxRoFormerModel,
           FlaxRoFormerForMaskedLM,
           FlaxRoFormerForSequenceClassification,
           FlaxRoFormerForTokenClassification,
           FlaxRoFormerForMultipleChoice,
           FlaxRoFormerForQuestionAnswering,
       )
       if is_flax_available()
       else ()
   )


   def 				_SCREAMING_SNAKE_CASE				(	self :     Union[str, Any]  ):

     '''simple docstring'''
     __A									= FlaxRoFormerModelTester(self  )






   @slow
   def 				_SCREAMING_SNAKE_CASE				(	self :     Any  ):

     '''simple docstring'''
     for model_class_name in self.all_model_classes:
       __A									= model_class_name.from_pretrained('''junnyu/roformer_chinese_small''',       from_pt=_lowerCamelCase  )
       __A									= model(np.ones((1, 1)  )  )
       self.assertIsNotNone(_lowerCamelCase  )





@require_flax
class 					snake_case		(							unittest.TestCase						):


   '''simple docstring'''

   @slow
   def 				_SCREAMING_SNAKE_CASE				(	self :     Dict  ):

     '''simple docstring'''
     __A									= FlaxRoFormerForMaskedLM.from_pretrained('''junnyu/roformer_chinese_base'''  )
     __A									= jnp.array([[0, 1, 2, 3, 4, 5]]  )
     __A									= model(_lowerCamelCase  )[0]

     __A									= 5_00_00

     __A									= (1, 6, vocab_size)
     self.assertEqual(output.shape,       _lowerCamelCase  )

     __A									= jnp.array(
         [[[-0.12_05, -1.02_65, 0.29_22], [-1.51_34, 0.19_74, 0.15_19], [-5.01_35, -3.90_03, -0.84_04]]]  )

     self.assertTrue(jnp.allclose(output[:, :3, :3],       _lowerCamelCase,       atol=1e-4  )  )




