
"""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 						lowerCamelCase__      (				)->				Union[str, Any]:







       """simple docstring"""
       UpperCamelCase       			=		10
       UpperCamelCase       			=		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       			=		datasets.Dataset.from_dict(
           {
               "tokens": [["foo"] * 5] * n,
               "labels": [[1] * 5] * n,
               "answers": [{"answer_start": [97], "text": ["1976"]}] * 10,
               "id": list(range(__A					)					),
           }		,   features=__A		,   )
       return dataset



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_					)->				Any:







       """simple docstring"""
       UpperCamelCase       			=		str(tmp_path_factory.mktemp("data"					) / "file.arrow"					)
       dataset.map(cache_file_name=__A					)
       return filename


# FILE_CONTENT + files


SCREAMING_SNAKE_CASE			  =  '''\
    Text data.
    Second line of data.'''



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Tuple:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Any:







       """simple docstring"""
       import bza

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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Dict:







       """simple docstring"""
       import gzip

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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Union[str, Any]:







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

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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_					)->				List[Any]:







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

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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_					)->				List[str]:







       """simple docstring"""
       import tarfile

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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				List[str]:







       """simple docstring"""
       import lzma

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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_					)->				Any:







       """simple docstring"""
       import zipfile

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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Union[str, Any]:







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

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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				int:







       """simple docstring"""
       UpperCamelCase       			=		tmp_path_factory.mktemp("data"					) / "file.xml"
       UpperCamelCase       			=		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(__A		,   "w"					) as f:
              f.write(__A					)
       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 						lowerCamelCase__      (				)->				List[Any]:







       """simple docstring"""
       return DATA_DICT_OF_LISTS



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Optional[Any]:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Dict:







       """simple docstring"""
       UpperCamelCase       			=		str(tmp_path_factory.mktemp("data"					) / "dataset.sqlite"					)
       with contextlib.closing(sqlitea.connect(__A					)					) as con:
              UpperCamelCase       			=		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 						lowerCamelCase__      (				UpperCAmelCase_					)->				Any:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				int:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_					)->				Tuple:







       """simple docstring"""
       import bza

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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				List[Any]:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Tuple:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Optional[Any]:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Optional[Any]:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Union[str, Any]:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Union[str, Any]:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				str:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				List[Any]:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Dict:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				List[Any]:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_					)->				List[str]:







       """simple docstring"""
       import gzip

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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_					)->				int:







       """simple docstring"""
       import gzip

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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Tuple:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Dict:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				int:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Tuple:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				int:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				List[str]:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Any:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Dict:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Tuple:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Dict:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Optional[Any]:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				List[Any]:







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



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







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



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







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_					)->				Any:







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



@pytest.fixture(scope="session"					)
def 						lowerCamelCase__      (				UpperCAmelCase_					)->				List[Any]:







       """simple docstring"""
       UpperCamelCase       			=		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








import gc
import unittest

import numpy as np
import torch

from diffusers import StableDiffusionKDiffusionPipeline
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()





@slow
@require_torch_gpu
class        lowerCAmelCase__  (					unittest.TestCase			):



       '''simple docstring'''







       def     __UpperCamelCase     (							self     ):







             '''simple docstring'''



             super().tearDown()
             gc.collect()
             torch.cuda.empty_cache()

       def     __UpperCamelCase     (							self     ):







             '''simple docstring'''



             __A    =StableDiffusionKDiffusionPipeline.from_pretrained('''CompVis/stable-diffusion-v1-4'''     )
             __A    =sd_pipe.to(lowercase__     )
             sd_pipe.set_progress_bar_config(disable=lowercase__     )

             sd_pipe.set_scheduler('''sample_euler'''     )

             __A    ='''A painting of a squirrel eating a burger'''
             __A    =torch.manual_seed(0     )
             __A    =sd_pipe([prompt] ,   generator=lowercase__ ,   guidance_scale=9.0 ,   num_inference_steps=2_0 ,   output_type='''np'''     )

             __A    =output.images

             __A    =image[0, -3:, -3:, -1]

             assert image.shape == (1, 5_1_2, 5_1_2, 3)
             __A    =np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]     )

             assert np.abs(image_slice.flatten() - expected_slice     ).max() < 1E-2

       def     __UpperCamelCase     (							self     ):







             '''simple docstring'''



             __A    =StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''     )
             __A    =sd_pipe.to(lowercase__     )
             sd_pipe.set_progress_bar_config(disable=lowercase__     )

             sd_pipe.set_scheduler('''sample_euler'''     )

             __A    ='''A painting of a squirrel eating a burger'''
             __A    =torch.manual_seed(0     )
             __A    =sd_pipe([prompt] ,   generator=lowercase__ ,   guidance_scale=9.0 ,   num_inference_steps=2_0 ,   output_type='''np'''     )

             __A    =output.images

             __A    =image[0, -3:, -3:, -1]

             assert image.shape == (1, 5_1_2, 5_1_2, 3)
             __A    =np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112]     )

             assert np.abs(image_slice.flatten() - expected_slice     ).max() < 5E-1


       def     __UpperCamelCase     (							self     ):







             '''simple docstring'''



             __A    =StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''     )
             __A    =sd_pipe.to(lowercase__     )
             sd_pipe.set_progress_bar_config(disable=lowercase__     )

             sd_pipe.set_scheduler('''sample_dpmpp_2m'''     )

             __A    ='''A painting of a squirrel eating a burger'''
             __A    =torch.manual_seed(0     )
             __A    =sd_pipe(
                 [prompt] ,   generator=lowercase__ ,   guidance_scale=7.5 ,   num_inference_steps=1_5 ,   output_type='''np''' ,   use_karras_sigmas=lowercase__ ,   )

             __A    =output.images

             __A    =image[0, -3:, -3:, -1]

             assert image.shape == (1, 5_1_2, 5_1_2, 3)
             __A    =np.array(
                 [0.1138_1689, 0.1211_2921, 0.138_9457, 0.1254_9606, 0.124_4964, 0.1083_1517, 0.1156_2866, 0.1086_7816, 0.1049_9048]     )

             assert np.abs(image_slice.flatten() - expected_slice     ).max() < 1E-2


