'''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  UpperCamelCase__					(					)							->	Optional[int]:
  __UpperCAmelCase:					int		= 1_0
  __UpperCAmelCase:					List[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""": [9_7], """text""": ["""1976"""]}] * 1_0,
          """id""": list(range(_lowercase     )     ),
      }   ,    features=_lowercase   ,    )
  return dataset






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					_lowercase    :				Optional[Any]   ,    _lowercase    :				Optional[int]     )							->	Union[str, Any]:
  __UpperCAmelCase:					Union[str, Any]		= str(tmp_path_factory.mktemp("""data"""     ) / """file.arrow"""     )
  dataset.map(cache_file_name=_lowercase     )
  return filename


# FILE_CONTENT + files


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






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					_lowercase    :				List[Any]     )							->	Tuple:
  __UpperCAmelCase:					Tuple		= tmp_path_factory.mktemp("""data"""     ) / """file.txt"""
  __UpperCAmelCase:					str		= FILE_CONTENT
  with open(_lowercase   ,    """w"""     ) as f:
    f.write(_lowercase     )
  return filename






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					_lowercase    :				Union[str, Any]     )							->	Tuple:
  import bza

  __UpperCAmelCase:					Tuple		= tmp_path_factory.mktemp("""data"""     ) / """file.txt.bz2"""
  __UpperCAmelCase:					str		= bytes(_lowercase   ,    """utf-8"""     )
  with bza.open(_lowercase   ,    """wb"""     ) as f:
    f.write(_lowercase     )
  return path






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					_lowercase    :				Any     )							->	List[Any]:
  import gzip

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






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					_lowercase    :				int     )							->	Union[str, Any]:
  if datasets.config.LZ4_AVAILABLE:
    import lza.frame

    __UpperCAmelCase:					List[str]		= tmp_path_factory.mktemp("""data"""     ) / """file.txt.lz4"""
    __UpperCAmelCase:					Union[str, Any]		= bytes(_lowercase   ,    """utf-8"""     )
    with lza.frame.open(_lowercase   ,    """wb"""     ) as f:
      f.write(_lowercase     )
    return path






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					_lowercase    :				Optional[int]   ,    _lowercase    :				Any     )							->	Any:
  if datasets.config.PY7ZR_AVAILABLE:
    import pyazr

    __UpperCAmelCase:					List[str]		= 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  UpperCamelCase__					(					_lowercase    :				Any   ,    _lowercase    :				Tuple     )							->	int:
  import tarfile

  __UpperCAmelCase:					str		= 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  UpperCamelCase__					(					_lowercase    :				Optional[Any]     )							->	Optional[int]:
  import lzma

  __UpperCAmelCase:					Union[str, Any]		= tmp_path_factory.mktemp("""data"""     ) / """file.txt.xz"""
  __UpperCAmelCase:					Optional[int]		= bytes(_lowercase   ,    """utf-8"""     )
  with lzma.open(_lowercase   ,    """wb"""     ) as f:
    f.write(_lowercase     )
  return path






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					_lowercase    :				Dict   ,    _lowercase    :				Dict     )							->	List[str]:
  import zipfile

  __UpperCAmelCase:					int		= 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  UpperCamelCase__					(					_lowercase    :				Optional[int]     )							->	str:
  if datasets.config.ZSTANDARD_AVAILABLE:
    import zstandard as zstd

    __UpperCAmelCase:					List[str]		= tmp_path_factory.mktemp("""data"""     ) / """file.txt.zst"""
    __UpperCAmelCase:					List[Any]		= bytes(_lowercase   ,    """utf-8"""     )
    with zstd.open(_lowercase   ,    """wb"""     ) as f:
      f.write(_lowercase     )
    return path






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					_lowercase    :				Dict     )							->	Union[str, Any]:
  __UpperCAmelCase:					Union[str, Any]		= tmp_path_factory.mktemp("""data"""     ) / """file.xml"""
  __UpperCAmelCase:					int		= textwrap.dedent(
      """\
    <?xml version=\"1.0\" encoding=\"UTF-8\" ?>
    <tmx version=\"1.4\">
      <header segtype=\"sentence\" srclang=\"ca\" />
      <body>
        <tu>
          <tuv xml:lang=\"ca\"><seg>Contingut 1</seg></tuv>
          <tuv xml:lang=\"en\"><seg>Content 1</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang=\"ca\"><seg>Contingut 2</seg></tuv>
          <tuv xml:lang=\"en\"><seg>Content 2</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang=\"ca\"><seg>Contingut 3</seg></tuv>
          <tuv xml:lang=\"en\"><seg>Content 3</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang=\"ca\"><seg>Contingut 4</seg></tuv>
          <tuv xml:lang=\"en\"><seg>Content 4</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang=\"ca\"><seg>Contingut 5</seg></tuv>
          <tuv xml:lang=\"en\"><seg>Content 5</seg></tuv>
        </tu>
      </body>
    </tmx>"""     )
  with open(_lowercase   ,    """w"""     ) as f:
    f.write(_lowercase     )
  return filename


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

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

SCREAMING_SNAKE_CASE_	   =			[
    {'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  UpperCamelCase__					(					)							->	Any:
  return DATA_DICT_OF_LISTS






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					_lowercase    :				int     )							->	int:
  __UpperCAmelCase:					str		= datasets.Dataset.from_dict(_lowercase     )
  __UpperCAmelCase:					List[str]		= str(tmp_path_factory.mktemp("""data"""     ) / """dataset.arrow"""     )
  dataset.map(cache_file_name=_lowercase     )
  return path






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					_lowercase    :				Dict     )							->	Any:
  __UpperCAmelCase:					Optional[int]		= str(tmp_path_factory.mktemp("""data"""     ) / """dataset.sqlite"""     )
  with contextlib.closing(sqlitea.connect(_lowercase     )     ) as con:
    __UpperCAmelCase:					str		= 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  UpperCamelCase__					(					_lowercase    :				Union[str, Any]     )							->	Optional[Any]:
  __UpperCAmelCase:					int		= str(tmp_path_factory.mktemp("""data"""     ) / """dataset.csv"""     )
  with open(_lowercase   ,    """w"""   ,    newline=""""""     ) as f:
    __UpperCAmelCase:					Optional[Any]		= 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  UpperCamelCase__					(					_lowercase    :				List[str]     )							->	List[Any]:
  __UpperCAmelCase:					List[Any]		= str(tmp_path_factory.mktemp("""data"""     ) / """dataset2.csv"""     )
  with open(_lowercase   ,    """w"""   ,    newline=""""""     ) as f:
    __UpperCAmelCase:					str		= 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  UpperCamelCase__					(					_lowercase    :				Tuple   ,    _lowercase    :				Optional[Any]     )							->	str:
  import bza

  __UpperCAmelCase:					Optional[int]		= tmp_path_factory.mktemp("""data"""     ) / """dataset.csv.bz2"""
  with open(_lowercase   ,    """rb"""     ) as f:
    __UpperCAmelCase:					Union[str, Any]		= 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  UpperCamelCase__					(					_lowercase    :				Union[str, Any]   ,    _lowercase    :				str   ,    _lowercase    :				List[str]     )							->	Tuple:
  __UpperCAmelCase:					int		= 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  UpperCamelCase__					(					_lowercase    :				List[Any]   ,    _lowercase    :				Any   ,    _lowercase    :				Optional[int]     )							->	List[Any]:
  __UpperCAmelCase:					Optional[Any]		= 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  UpperCamelCase__					(					_lowercase    :				str   ,    _lowercase    :				List[Any]   ,    _lowercase    :				List[Any]     )							->	Any:
  __UpperCAmelCase:					Dict		= 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  UpperCamelCase__					(					_lowercase    :				Optional[int]     )							->	List[str]:
  __UpperCAmelCase:					int		= str(tmp_path_factory.mktemp("""data"""     ) / """dataset.parquet"""     )
  __UpperCAmelCase:					List[Any]		= pa.schema(
      {
          """col_1""": pa.string(),
          """col_2""": pa.intaa(),
          """col_3""": pa.floataa(),
      }     )
  with open(_lowercase   ,    """wb"""     ) as f:
    __UpperCAmelCase:					int		= pq.ParquetWriter(_lowercase   ,    schema=_lowercase     )
    __UpperCAmelCase:					List[str]		= 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  UpperCamelCase__					(					_lowercase    :				Dict     )							->	List[str]:
  __UpperCAmelCase:					Tuple		= str(tmp_path_factory.mktemp("""data"""     ) / """dataset.json"""     )
  __UpperCAmelCase:					List[str]		= {"""data""": DATA}
  with open(_lowercase   ,    """w"""     ) as f:
    json.dump(_lowercase   ,    _lowercase     )
  return path






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					_lowercase    :				str     )							->	Any:
  __UpperCAmelCase:					int		= str(tmp_path_factory.mktemp("""data"""     ) / """dataset.json"""     )
  __UpperCAmelCase:					Any		= {"""data""": DATA_DICT_OF_LISTS}
  with open(_lowercase   ,    """w"""     ) as f:
    json.dump(_lowercase   ,    _lowercase     )
  return path






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					_lowercase    :				Any     )							->	List[Any]:
  __UpperCAmelCase:					Optional[int]		= 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  UpperCamelCase__					(					_lowercase    :				Tuple     )							->	Any:
  __UpperCAmelCase:					Optional[Any]		= 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  UpperCamelCase__					(					_lowercase    :				Tuple     )							->	Dict:
  __UpperCAmelCase:					int		= 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  UpperCamelCase__					(					_lowercase    :				int     )							->	Any:
  __UpperCAmelCase:					Optional[int]		= 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  UpperCamelCase__					(					_lowercase    :				int   ,    _lowercase    :				Dict     )							->	Dict:
  import gzip

  __UpperCAmelCase:					str		= 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  UpperCamelCase__					(					_lowercase    :				int   ,    _lowercase    :				List[Any]     )							->	Dict:
  import gzip

  __UpperCAmelCase:					int		= 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  UpperCamelCase__					(					_lowercase    :				List[str]   ,    _lowercase    :				str   ,    _lowercase    :				List[str]     )							->	Any:
  __UpperCAmelCase:					str		= 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  UpperCamelCase__					(					_lowercase    :				Union[str, Any]   ,    _lowercase    :				Optional[Any]   ,    _lowercase    :				str   ,    _lowercase    :				Tuple     )							->	Tuple:
  __UpperCAmelCase:					Any		= 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  UpperCamelCase__					(					_lowercase    :				List[str]   ,    _lowercase    :				Optional[int]   ,    _lowercase    :				List[str]     )							->	Dict:
  __UpperCAmelCase:					int		= 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  UpperCamelCase__					(					_lowercase    :				int   ,    _lowercase    :				int   ,    _lowercase    :				List[str]     )							->	Dict:
  __UpperCAmelCase:					Optional[int]		= 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  UpperCamelCase__					(					_lowercase    :				Tuple   ,    _lowercase    :				Optional[Any]   ,    _lowercase    :				Optional[Any]   ,    _lowercase    :				Optional[int]     )							->	Union[str, Any]:
  __UpperCAmelCase:					Optional[int]		= 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  UpperCamelCase__					(					_lowercase    :				int     )							->	Dict:
  __UpperCAmelCase:					Tuple		= ["""0""", """1""", """2""", """3"""]
  __UpperCAmelCase:					Optional[int]		= 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  UpperCamelCase__					(					_lowercase    :				Tuple     )							->	List[str]:
  __UpperCAmelCase:					List[str]		= ["""0""", """1""", """2""", """3"""]
  __UpperCAmelCase:					str		= 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  UpperCamelCase__					(					_lowercase    :				List[str]     )							->	List[str]:
  __UpperCAmelCase:					Tuple		= ["""0""", """1""", """2""", """3"""]
  __UpperCAmelCase:					Optional[int]		= 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  UpperCamelCase__					(					_lowercase    :				List[Any]   ,    _lowercase    :				int   ,    _lowercase    :				Any     )							->	int:
  __UpperCAmelCase:					Optional[int]		= 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  UpperCamelCase__					(					_lowercase    :				int   ,    _lowercase    :				Dict   ,    _lowercase    :				Optional[int]     )							->	int:
  __UpperCAmelCase:					Dict		= 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  UpperCamelCase__					(					_lowercase    :				List[Any]   ,    _lowercase    :				Tuple   ,    _lowercase    :				int     )							->	List[Any]:
  __UpperCAmelCase:					Optional[Any]		= 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  UpperCamelCase__					(					_lowercase    :				List[str]     )							->	Dict:
  __UpperCAmelCase:					List[str]		= """\n""".join(["""First""", """Second\u2029with Unicode new line""", """Third"""]     )
  __UpperCAmelCase:					Dict		= 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  UpperCamelCase__					(					)							->	str:
  return os.path.join("""tests"""   ,    """features"""   ,    """data"""   ,    """test_image_rgb.jpg"""     )






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					)							->	Union[str, Any]:
  return os.path.join("""tests"""   ,    """features"""   ,    """data"""   ,    """test_audio_44100.wav"""     )






@pytest.fixture(scope="""session"""     )
def  UpperCamelCase__					(					_lowercase    :				List[Any]   ,    _lowercase    :				List[Any]     )							->	Dict:
  __UpperCAmelCase:					Optional[int]		= 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  UpperCamelCase__					(					_lowercase    :				Optional[Any]     )							->	str:
  __UpperCAmelCase:					Dict		= 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






'''simple docstring'''






import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import PoolFormerImageProcessor




class    a (       unittest.TestCase				):



  """simple docstring"""







  def __init__(							self   ,    snake_case_   ,    snake_case_=7   ,    snake_case_=3   ,    snake_case_=30   ,    snake_case_=400   ,    snake_case_=True   ,    snake_case_=None   ,    snake_case_=0.9   ,    snake_case_=None   ,    snake_case_=True   ,    snake_case_=[0.5, 0.5, 0.5]   ,    snake_case_=[0.5, 0.5, 0.5]   ,    ):

    '''simple docstring'''







    __UpperCAmelCase:					List[Any]		= size if size is not None else {"""shortest_edge""": 30}
    __UpperCAmelCase:					str		= crop_size if crop_size is not None else {"""height""": 30, """width""": 30}
    __UpperCAmelCase:					Dict		= parent
    __UpperCAmelCase:					Union[str, Any]		= batch_size
    __UpperCAmelCase:					List[Any]		= num_channels
    __UpperCAmelCase:					List[str]		= min_resolution
    __UpperCAmelCase:					List[str]		= max_resolution
    __UpperCAmelCase:					Tuple		= do_resize_and_center_crop
    __UpperCAmelCase:					Union[str, Any]		= size
    __UpperCAmelCase:					str		= crop_pct
    __UpperCAmelCase:					List[Any]		= crop_size
    __UpperCAmelCase:					str		= do_normalize
    __UpperCAmelCase:					Union[str, Any]		= image_mean
    __UpperCAmelCase:					List[str]		= image_std







  def    lowercase_  (							self					):

    '''simple docstring'''







    return {
        "size": self.size,
        "do_resize_and_center_crop": self.do_resize_and_center_crop,
        "crop_pct": self.crop_pct,
        "crop_size": self.crop_size,
        "do_normalize": self.do_normalize,
        "image_mean": self.image_mean,
        "image_std": self.image_std,
    }




@require_torch
@require_vision
class    a (       __lowerCAmelCase						,  unittest.TestCase				):



  """simple docstring"""
  __lowerCAmelCase				      =					PoolFormerImageProcessor if is_vision_available() else None







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Any		= PoolFormerImageProcessingTester(self					)







  @property
  def    lowercase_  (							self					):

    '''simple docstring'''







    return self.image_processor_tester.prepare_image_processor_dict()







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[Any]		= self.image_processing_class(**self.image_processor_dict					)
    self.assertTrue(hasattr(snake_case_   ,    """do_resize_and_center_crop"""					)					)
    self.assertTrue(hasattr(snake_case_   ,    """size"""					)					)
    self.assertTrue(hasattr(snake_case_   ,    """crop_pct"""					)					)
    self.assertTrue(hasattr(snake_case_   ,    """do_normalize"""					)					)
    self.assertTrue(hasattr(snake_case_   ,    """image_mean"""					)					)
    self.assertTrue(hasattr(snake_case_   ,    """image_std"""					)					)







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					List[str]		= self.image_processing_class.from_dict(self.image_processor_dict					)
    self.assertEqual(image_processor.size   ,    {"""shortest_edge""": 30}					)
    self.assertEqual(image_processor.crop_size   ,    {"""height""": 30, """width""": 30}					)

    __UpperCAmelCase:					Dict		= self.image_processing_class.from_dict(self.image_processor_dict   ,    size=42   ,    crop_size=84					)
    self.assertEqual(image_processor.size   ,    {"""shortest_edge""": 42}					)
    self.assertEqual(image_processor.crop_size   ,    {"""height""": 84, """width""": 84}					)







  def    lowercase_  (							self					):

    '''simple docstring'''







    pass







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Any		= self.image_processing_class(**self.image_processor_dict					)
    # create random PIL images
    __UpperCAmelCase:					Optional[Any]		= prepare_image_inputs(self.image_processor_tester   ,    equal_resolution=snake_case_					)
    for image in image_inputs:
      self.assertIsInstance(snake_case_   ,    Image.Image					)

    # Test not batched input
    __UpperCAmelCase:					Optional[int]		= image_processing(image_inputs[0]   ,    return_tensors="""pt"""					).pixel_values

    self.assertEqual(
        encoded_images.shape   ,    (
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        )   ,    )

    # Test batched
    __UpperCAmelCase:					Any		= image_processing(snake_case_   ,    return_tensors="""pt"""					).pixel_values
    self.assertEqual(
        encoded_images.shape   ,    (
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        )   ,    )







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[Any]		= self.image_processing_class(**self.image_processor_dict					)
    # create random numpy tensors
    __UpperCAmelCase:					Union[str, Any]		= prepare_image_inputs(self.image_processor_tester   ,    equal_resolution=snake_case_   ,    numpify=snake_case_					)
    for image in image_inputs:
      self.assertIsInstance(snake_case_   ,    np.ndarray					)

    # Test not batched input
    __UpperCAmelCase:					Union[str, Any]		= image_processing(image_inputs[0]   ,    return_tensors="""pt"""					).pixel_values
    self.assertEqual(
        encoded_images.shape   ,    (
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        )   ,    )

    # Test batched
    __UpperCAmelCase:					str		= image_processing(snake_case_   ,    return_tensors="""pt"""					).pixel_values
    self.assertEqual(
        encoded_images.shape   ,    (
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        )   ,    )







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Any		= self.image_processing_class(**self.image_processor_dict					)
    # create random PyTorch tensors
    __UpperCAmelCase:					Dict		= prepare_image_inputs(self.image_processor_tester   ,    equal_resolution=snake_case_   ,    torchify=snake_case_					)
    for image in image_inputs:
      self.assertIsInstance(snake_case_   ,    torch.Tensor					)

    # Test not batched input
    __UpperCAmelCase:					Optional[int]		= image_processing(image_inputs[0]   ,    return_tensors="""pt"""					).pixel_values
    self.assertEqual(
        encoded_images.shape   ,    (
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        )   ,    )

    # Test batched
    __UpperCAmelCase:					Optional[int]		= image_processing(snake_case_   ,    return_tensors="""pt"""					).pixel_values
    self.assertEqual(
        encoded_images.shape   ,    (
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        )   ,    )