





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

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			str					,					_lowerCAmelCase			:			Union[str, Any]						)			->    List[Any]:
   A_       :					str        =      str(tmp_path_factory.mktemp("data"						) / "file.arrow"						)
   dataset.map(cache_file_name=_lowerCAmelCase						)
   return filename


# FILE_CONTENT + files


_lowerCAmelCase				:   List[Any]						       =						'''\
    Text data.
    Second line of data.'''

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Optional[int]						)			->    Any:
   A_       :					Dict        =      tmp_path_factory.mktemp("data"						) / "file.txt"
   A_       :					int        =      FILE_CONTENT
   with open(_lowerCAmelCase					,					"w"						) as f:
      f.write(_lowerCAmelCase						)
   return filename

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			List[Any]						)			->    Dict:
   import bza

   A_       :					Dict        =      tmp_path_factory.mktemp("data"						) / "file.txt.bz2"
   A_       :					List[str]        =      bytes(_lowerCAmelCase					,					"utf-8"						)
   with bza.open(_lowerCAmelCase					,					"wb"						) as f:
      f.write(_lowerCAmelCase						)
   return path

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

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

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

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

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

      A_       :					Optional[Any]        =      tmp_path_factory.mktemp("data"						) / "file.txt.7z"
      with pyazr.SevenZipFile(_lowerCAmelCase					,					"w"						) as archive:
         archive.write(_lowerCAmelCase					,					arcname=os.path.basename(_lowerCAmelCase						)						)
      return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			List[Any]					,					_lowerCAmelCase			:			Optional[Any]						)			->    List[str]:
   import tarfile

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

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			List[Any]						)			->    List[str]:
   import lzma

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

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Tuple					,					_lowerCAmelCase			:			Dict						)			->    Tuple:
   import zipfile

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

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Tuple						)			->    Union[str, Any]:
   if datasets.config.ZSTANDARD_AVAILABLE:
      import zstandard as zstd

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

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			str						)			->    int:
   A_       :					Tuple        =      tmp_path_factory.mktemp("data"						) / "file.xml"
   A_       :					int        =      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(_lowerCAmelCase					,					"w"						) as f:
      f.write(_lowerCAmelCase						)
   return filename


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

_lowerCAmelCase				:   List[Any]						       =						[
    {'''col_3''': 0.0, '''col_1''': '''0''', '''col_2''': 0},
    {'''col_3''': 1.0, '''col_1''': '''1''', '''col_2''': 1},
]

_lowerCAmelCase				:   List[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   __snake_case    (       )			->    List[Any]:
   return DATA_DICT_OF_LISTS

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

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

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Optional[int]						)			->    int:
   A_       :					Optional[Any]        =      str(tmp_path_factory.mktemp("data"						) / "dataset2.csv"						)
   with open(_lowerCAmelCase					,					"w"					,					newline=""						) as f:
      A_       :					Optional[int]        =      csv.DictWriter(_lowerCAmelCase					,					fieldnames=["col_1", "col_2", "col_3"]						)
      writer.writeheader()
      for item in DATA:
         writer.writerow(_lowerCAmelCase						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Any					,					_lowerCAmelCase			:			List[str]						)			->    Optional[int]:
   import bza

   A_       :					Dict        =      tmp_path_factory.mktemp("data"						) / "dataset.csv.bz2"
   with open(_lowerCAmelCase					,					"rb"						) as f:
      A_       :					List[str]        =      f.read()
   # data = bytes(FILE_CONTENT, "utf-8")
   with bza.open(_lowerCAmelCase					,					"wb"						) as f:
      f.write(_lowerCAmelCase						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Any					,					_lowerCAmelCase			:			Dict					,					_lowerCAmelCase			:			Optional[Any]						)			->    Any:
   A_       :					List[Any]        =      tmp_path_factory.mktemp("data"						) / "dataset.csv.zip"
   with zipfile.ZipFile(_lowerCAmelCase					,					"w"						) as f:
      f.write(_lowerCAmelCase					,					arcname=os.path.basename(_lowerCAmelCase						)						)
      f.write(_lowerCAmelCase					,					arcname=os.path.basename(_lowerCAmelCase						)						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			List[str]					,					_lowerCAmelCase			:			Optional[int]					,					_lowerCAmelCase			:			Dict						)			->    Any:
   A_       :					int        =      tmp_path_factory.mktemp("data"						) / "dataset.csv.zip"
   with zipfile.ZipFile(_lowerCAmelCase					,					"w"						) as f:
      f.write(_lowerCAmelCase					,					arcname=os.path.basename(csv_path.replace(".csv"					,					".CSV"						)						)						)
      f.write(_lowerCAmelCase					,					arcname=os.path.basename(csva_path.replace(".csv"					,					".CSV"						)						)						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Union[str, Any]					,					_lowerCAmelCase			:			Optional[Any]					,					_lowerCAmelCase			:			Union[str, Any]						)			->    int:
   A_       :					int        =      tmp_path_factory.mktemp("data"						) / "dataset_with_dir.csv.zip"
   with zipfile.ZipFile(_lowerCAmelCase					,					"w"						) as f:
      f.write(_lowerCAmelCase					,					arcname=os.path.join("main_dir"					,					os.path.basename(_lowerCAmelCase						)						)						)
      f.write(_lowerCAmelCase					,					arcname=os.path.join("main_dir"					,					os.path.basename(_lowerCAmelCase						)						)						)
   return path

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

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Optional[int]						)			->    Dict:
   A_       :					Any        =      str(tmp_path_factory.mktemp("data"						) / "dataset.json"						)
   A_       :					Any        =      {"data": DATA}
   with open(_lowerCAmelCase					,					"w"						) as f:
      json.dump(_lowerCAmelCase					,					_lowerCAmelCase						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			List[str]						)			->    int:
   A_       :					int        =      str(tmp_path_factory.mktemp("data"						) / "dataset.json"						)
   A_       :					Optional[Any]        =      {"data": DATA_DICT_OF_LISTS}
   with open(_lowerCAmelCase					,					"w"						) as f:
      json.dump(_lowerCAmelCase					,					_lowerCAmelCase						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			str						)			->    Tuple:
   A_       :					int        =      str(tmp_path_factory.mktemp("data"						) / "dataset.jsonl"						)
   with open(_lowerCAmelCase					,					"w"						) as f:
      for item in DATA:
         f.write(json.dumps(_lowerCAmelCase						) + "\n"						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			str						)			->    Optional[Any]:
   A_       :					Optional[int]        =      str(tmp_path_factory.mktemp("data"						) / "dataset2.jsonl"						)
   with open(_lowerCAmelCase					,					"w"						) as f:
      for item in DATA:
         f.write(json.dumps(_lowerCAmelCase						) + "\n"						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Dict						)			->    Tuple:
   A_       :					int        =      str(tmp_path_factory.mktemp("data"						) / "dataset_312.jsonl"						)
   with open(_lowerCAmelCase					,					"w"						) as f:
      for item in DATA_312:
         f.write(json.dumps(_lowerCAmelCase						) + "\n"						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Union[str, Any]						)			->    List[str]:
   A_       :					Dict        =      str(tmp_path_factory.mktemp("data"						) / "dataset-str.jsonl"						)
   with open(_lowerCAmelCase					,					"w"						) as f:
      for item in DATA_STR:
         f.write(json.dumps(_lowerCAmelCase						) + "\n"						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Optional[int]					,					_lowerCAmelCase			:			Union[str, Any]						)			->    Any:
   import gzip

   A_       :					Optional[int]        =      str(tmp_path_factory.mktemp("data"						) / "dataset.txt.gz"						)
   with open(_lowerCAmelCase					,					"rb"						) as orig_file:
      with gzip.open(_lowerCAmelCase					,					"wb"						) as zipped_file:
         zipped_file.writelines(_lowerCAmelCase						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Tuple					,					_lowerCAmelCase			:			Optional[Any]						)			->    int:
   import gzip

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

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			List[str]					,					_lowerCAmelCase			:			Tuple					,					_lowerCAmelCase			:			int						)			->    Any:
   A_       :					Union[str, Any]        =      tmp_path_factory.mktemp("data"						) / "dataset.jsonl.zip"
   with zipfile.ZipFile(_lowerCAmelCase					,					"w"						) as f:
      f.write(_lowerCAmelCase					,					arcname=os.path.basename(_lowerCAmelCase						)						)
      f.write(_lowerCAmelCase					,					arcname=os.path.basename(_lowerCAmelCase						)						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Union[str, Any]					,					_lowerCAmelCase			:			Any					,					_lowerCAmelCase			:			Union[str, Any]					,					_lowerCAmelCase			:			Optional[Any]						)			->    Optional[Any]:
   A_       :					int        =      tmp_path_factory.mktemp("data"						) / "dataset_nested.jsonl.zip"
   with zipfile.ZipFile(_lowerCAmelCase					,					"w"						) as f:
      f.write(_lowerCAmelCase					,					arcname=os.path.join("nested"					,					os.path.basename(_lowerCAmelCase						)						)						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Tuple					,					_lowerCAmelCase			:			Optional[Any]					,					_lowerCAmelCase			:			List[Any]						)			->    str:
   A_       :					Union[str, Any]        =      tmp_path_factory.mktemp("data"						) / "dataset_with_dir.jsonl.zip"
   with zipfile.ZipFile(_lowerCAmelCase					,					"w"						) as f:
      f.write(_lowerCAmelCase					,					arcname=os.path.join("main_dir"					,					os.path.basename(_lowerCAmelCase						)						)						)
      f.write(_lowerCAmelCase					,					arcname=os.path.join("main_dir"					,					os.path.basename(_lowerCAmelCase						)						)						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Any					,					_lowerCAmelCase			:			Union[str, Any]					,					_lowerCAmelCase			:			str						)			->    Union[str, Any]:
   A_       :					Dict        =      tmp_path_factory.mktemp("data"						) / "dataset.jsonl.tar"
   with tarfile.TarFile(_lowerCAmelCase					,					"w"						) as f:
      f.add(_lowerCAmelCase					,					arcname=os.path.basename(_lowerCAmelCase						)						)
      f.add(_lowerCAmelCase					,					arcname=os.path.basename(_lowerCAmelCase						)						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			List[Any]					,					_lowerCAmelCase			:			Union[str, Any]					,					_lowerCAmelCase			:			Union[str, Any]					,					_lowerCAmelCase			:			Optional[Any]						)			->    Any:
   A_       :					Any        =      tmp_path_factory.mktemp("data"						) / "dataset_nested.jsonl.tar"
   with tarfile.TarFile(_lowerCAmelCase					,					"w"						) as f:
      f.add(_lowerCAmelCase					,					arcname=os.path.join("nested"					,					os.path.basename(_lowerCAmelCase						)						)						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			int						)			->    List[Any]:
   A_       :					Optional[int]        =      ["0", "1", "2", "3"]
   A_       :					Dict        =      str(tmp_path_factory.mktemp("data"						) / "dataset.txt"						)
   with open(_lowerCAmelCase					,					"w"						) as f:
      for item in data:
         f.write(item + "\n"						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Optional[Any]						)			->    Any:
   A_       :					Union[str, Any]        =      ["0", "1", "2", "3"]
   A_       :					int        =      str(tmp_path_factory.mktemp("data"						) / "dataset2.txt"						)
   with open(_lowerCAmelCase					,					"w"						) as f:
      for item in data:
         f.write(item + "\n"						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Optional[Any]						)			->    str:
   A_       :					Tuple        =      ["0", "1", "2", "3"]
   A_       :					List[Any]        =      tmp_path_factory.mktemp("data"						) / "dataset.abc"
   with open(_lowerCAmelCase					,					"w"						) as f:
      for item in data:
         f.write(item + "\n"						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			List[Any]					,					_lowerCAmelCase			:			Union[str, Any]					,					_lowerCAmelCase			:			str						)			->    Optional[Any]:
   A_       :					Optional[int]        =      tmp_path_factory.mktemp("data"						) / "dataset.text.zip"
   with zipfile.ZipFile(_lowerCAmelCase					,					"w"						) as f:
      f.write(_lowerCAmelCase					,					arcname=os.path.basename(_lowerCAmelCase						)						)
      f.write(_lowerCAmelCase					,					arcname=os.path.basename(_lowerCAmelCase						)						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			List[str]					,					_lowerCAmelCase			:			List[str]					,					_lowerCAmelCase			:			Optional[int]						)			->    Any:
   A_       :					Tuple        =      tmp_path_factory.mktemp("data"						) / "dataset_with_dir.text.zip"
   with zipfile.ZipFile(_lowerCAmelCase					,					"w"						) as f:
      f.write(_lowerCAmelCase					,					arcname=os.path.join("main_dir"					,					os.path.basename(_lowerCAmelCase						)						)						)
      f.write(_lowerCAmelCase					,					arcname=os.path.join("main_dir"					,					os.path.basename(_lowerCAmelCase						)						)						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Union[str, Any]					,					_lowerCAmelCase			:			Any					,					_lowerCAmelCase			:			Any						)			->    str:
   A_       :					Union[str, Any]        =      tmp_path_factory.mktemp("data"						) / "dataset.ext.zip"
   with zipfile.ZipFile(_lowerCAmelCase					,					"w"						) as f:
      f.write(_lowerCAmelCase					,					arcname=os.path.basename("unsupported.ext"						)						)
      f.write(_lowerCAmelCase					,					arcname=os.path.basename("unsupported_2.ext"						)						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			int						)			->    int:
   A_       :					Optional[int]        =      "\n".join(["First", "Second\u2029with Unicode new line", "Third"]						)
   A_       :					Union[str, Any]        =      str(tmp_path_factory.mktemp("data"						) / "dataset_with_unicode_new_lines.txt"						)
   with open(_lowerCAmelCase					,					"w"					,					encoding="utf-8"						) as f:
      f.write(_lowerCAmelCase						)
   return path

@pytest.fixture(scope="session"						)
def   __snake_case    (       )			->    List[str]:
   return os.path.join("tests"					,					"features"					,					"data"					,					"test_image_rgb.jpg"						)

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

@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			Optional[int]					,					_lowerCAmelCase			:			List[Any]						)			->    str:
   A_       :					Optional[Any]        =      tmp_path_factory.mktemp("data"						) / "dataset.img.zip"
   with zipfile.ZipFile(_lowerCAmelCase					,					"w"						) as f:
      f.write(_lowerCAmelCase					,					arcname=os.path.basename(_lowerCAmelCase						)						)
      f.write(_lowerCAmelCase					,					arcname=os.path.basename(_lowerCAmelCase						).replace(".jpg"					,					"2.jpg"						)						)
   return path





@pytest.fixture(scope="session"						)
def   __snake_case    (       _lowerCAmelCase			:			List[Any]						)			->    List[Any]:
   A_       :					Optional[int]        =      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







from __future__ import annotations

import math
import random
from typing import Any


class        __magic_name__	:





     """simple docstring"""



     def __init__(				self							:Tuple	):





        '''simple docstring'''




        A_       :					list[Any]        =      []
        A_       :					int        =      0
        A_       :					int        =      0



     def     SCREAMING_SNAKE_CASE		(				self							:List[Any]	):





        '''simple docstring'''




        return self.head == self.tail



     def     SCREAMING_SNAKE_CASE		(				self							:Optional[Any]      ,   snake_case							:Any	):





        '''simple docstring'''




        self.data.append(snake_case	)
        A_       :					int        =      self.tail + 1



     def     SCREAMING_SNAKE_CASE		(				self							:str	):





        '''simple docstring'''




        A_       :					int        =      self.data[self.head]
        A_       :					Tuple        =      self.head + 1
        return ret



     def     SCREAMING_SNAKE_CASE		(				self							:Optional[int]	):





        '''simple docstring'''




        return self.tail - self.head





     def     SCREAMING_SNAKE_CASE		(				self							:Any	):





        '''simple docstring'''




        print(self.data	)
        print("**************"	)
        print(self.data[self.head : self.tail]	)




class        __magic_name__	:





     """simple docstring"""



     def __init__(				self							:Any      ,   snake_case							:Any	):





        '''simple docstring'''




        A_       :					Any        =      data
        A_       :					MyNode | None        =      None
        A_       :					MyNode | None        =      None
        A_       :					int        =      1



     def     SCREAMING_SNAKE_CASE		(				self							:List[str]	):





        '''simple docstring'''




        return self.data



     def     SCREAMING_SNAKE_CASE		(				self							:Dict	):





        '''simple docstring'''




        return self.left



     def     SCREAMING_SNAKE_CASE		(				self							:Any	):





        '''simple docstring'''




        return self.right



     def     SCREAMING_SNAKE_CASE		(				self							:List[Any]	):





        '''simple docstring'''




        return self.height



     def     SCREAMING_SNAKE_CASE		(				self							:List[str]      ,   snake_case							:Any	):





        '''simple docstring'''




        A_       :					Optional[int]        =      data



     def     SCREAMING_SNAKE_CASE		(				self							:Optional[int]      ,   snake_case							:MyNode | None	):





        '''simple docstring'''




        A_       :					Tuple        =      node



     def     SCREAMING_SNAKE_CASE		(				self							:str      ,   snake_case							:MyNode | None	):





        '''simple docstring'''




        A_       :					str        =      node





     def     SCREAMING_SNAKE_CASE		(				self							:Tuple      ,   snake_case							:int	):





        '''simple docstring'''




        A_       :					Optional[int]        =      height




def   __snake_case    (       _lowerCAmelCase			:			MyNode | None						)			->    int:
   if node is None:
      return 0
   return node.get_height()

def   __snake_case    (       _lowerCAmelCase			:			int					,					_lowerCAmelCase			:			int						)			->    int:
   if a > b:
      return a
   return b

def   __snake_case    (       _lowerCAmelCase			:			MyNode						)			->    MyNode:
   print("left rotation node:"					,					node.get_data()						)
   A_       :					Optional[int]        =      node.get_left()
   assert ret is not None
   node.set_left(ret.get_right()						)
   ret.set_right(_lowerCAmelCase						)
   A_       :					Any        =      my_max(get_height(node.get_right()						)					,					get_height(node.get_left()						)						) + 1
   node.set_height(_lowerCAmelCase						)
   A_       :					List[str]        =      my_max(get_height(ret.get_right()						)					,					get_height(ret.get_left()						)						) + 1
   ret.set_height(_lowerCAmelCase						)
   return ret

def   __snake_case    (       _lowerCAmelCase			:			MyNode						)			->    MyNode:
   print("right rotation node:"					,					node.get_data()						)
   A_       :					Union[str, Any]        =      node.get_right()
   assert ret is not None
   node.set_right(ret.get_left()						)
   ret.set_left(_lowerCAmelCase						)
   A_       :					int        =      my_max(get_height(node.get_right()						)					,					get_height(node.get_left()						)						) + 1
   node.set_height(_lowerCAmelCase						)
   A_       :					Dict        =      my_max(get_height(ret.get_right()						)					,					get_height(ret.get_left()						)						) + 1
   ret.set_height(_lowerCAmelCase						)
   return ret

def   __snake_case    (       _lowerCAmelCase			:			MyNode						)			->    MyNode:
   A_       :					List[Any]        =      node.get_left()
   assert left_child is not None
   node.set_left(left_rotation(_lowerCAmelCase						)						)
   return right_rotation(_lowerCAmelCase						)

def   __snake_case    (       _lowerCAmelCase			:			MyNode						)			->    MyNode:
   A_       :					List[Any]        =      node.get_right()
   assert right_child is not None
   node.set_right(right_rotation(_lowerCAmelCase						)						)
   return left_rotation(_lowerCAmelCase						)

def   __snake_case    (       _lowerCAmelCase			:			MyNode | None					,					_lowerCAmelCase			:			Any						)			->    MyNode | None:
   if node is None:
      return MyNode(_lowerCAmelCase						)
   if data < node.get_data():
      node.set_left(insert_node(node.get_left()					,					_lowerCAmelCase						)						)
      if (
          get_height(node.get_left()						) - get_height(node.get_right()						) == 2
      ):  # an unbalance detected
         A_       :					Any        =      node.get_left()
         assert left_child is not None
         if (
             data < left_child.get_data()
         ):  # new node is the left child of the left child
            A_       :					Optional[int]        =      right_rotation(_lowerCAmelCase						)
         else:
            A_       :					int        =      lr_rotation(_lowerCAmelCase						)
   else:
      node.set_right(insert_node(node.get_right()					,					_lowerCAmelCase						)						)
      if get_height(node.get_right()						) - get_height(node.get_left()						) == 2:
         A_       :					Dict        =      node.get_right()
         assert right_child is not None
         if data < right_child.get_data():
            A_       :					Optional[Any]        =      rl_rotation(_lowerCAmelCase						)
         else:
            A_       :					Dict        =      left_rotation(_lowerCAmelCase						)
   A_       :					Optional[int]        =      my_max(get_height(node.get_right()						)					,					get_height(node.get_left()						)						) + 1
   node.set_height(_lowerCAmelCase						)
   return node

def   __snake_case    (       _lowerCAmelCase			:			MyNode						)			->    Any:
   while True:
      A_       :					Any        =      root.get_right()
      if right_child is None:
         break
      A_       :					Optional[Any]        =      right_child
   return root.get_data()

def   __snake_case    (       _lowerCAmelCase			:			MyNode						)			->    Any:
   while True:
      A_       :					Optional[Any]        =      root.get_left()
      if left_child is None:
         break
      A_       :					int        =      left_child
   return root.get_data()

def   __snake_case    (       _lowerCAmelCase			:			MyNode					,					_lowerCAmelCase			:			Any						)			->    MyNode | None:
   A_       :					Optional[int]        =      root.get_left()
   A_       :					Dict        =      root.get_right()
   if root.get_data() == data:
      if left_child is not None and right_child is not None:
         A_       :					int        =      get_left_most(_lowerCAmelCase						)
         root.set_data(_lowerCAmelCase						)
         root.set_right(del_node(_lowerCAmelCase					,					_lowerCAmelCase						)						)
      elif left_child is not None:
         A_       :					Tuple        =      left_child
      elif right_child is not None:
         A_       :					Any        =      right_child
      else:
         return None
   elif root.get_data() > data:
      if left_child is None:
         print("No such data"						)
         return root
      else:
         root.set_left(del_node(_lowerCAmelCase					,					_lowerCAmelCase						)						)
   else:  # root.get_data() < data
      if right_child is None:
         return root
      else:
         root.set_right(del_node(_lowerCAmelCase					,					_lowerCAmelCase						)						)

   if get_height(_lowerCAmelCase						) - get_height(_lowerCAmelCase						) == 2:
      assert right_child is not None
      if get_height(right_child.get_right()						) > get_height(right_child.get_left()						):
         A_       :					Dict        =      left_rotation(_lowerCAmelCase						)
      else:
         A_       :					List[Any]        =      rl_rotation(_lowerCAmelCase						)
   elif get_height(_lowerCAmelCase						) - get_height(_lowerCAmelCase						) == -2:
      assert left_child is not None
      if get_height(left_child.get_left()						) > get_height(left_child.get_right()						):
         A_       :					Optional[Any]        =      right_rotation(_lowerCAmelCase						)
      else:
         A_       :					Tuple        =      lr_rotation(_lowerCAmelCase						)
   A_       :					List[str]        =      my_max(get_height(root.get_right()						)					,					get_height(root.get_left()						)						) + 1
   root.set_height(_lowerCAmelCase						)
   return root


class        __magic_name__	:





     """simple docstring"""



     def __init__(				self							:List[str]	):





        '''simple docstring'''




        A_       :					MyNode | None        =      None



     def     SCREAMING_SNAKE_CASE		(				self							:List[Any]	):





        '''simple docstring'''




        return get_height(self.root	)



     def     SCREAMING_SNAKE_CASE		(				self							:str      ,   snake_case							:Any	):





        '''simple docstring'''




        print("insert:" + str(snake_case	)	)
        A_       :					List[Any]        =      insert_node(self.root      ,   snake_case	)



     def     SCREAMING_SNAKE_CASE		(				self							:Optional[Any]      ,   snake_case							:Any	):





        '''simple docstring'''




        print("delete:" + str(snake_case	)	)
        if self.root is None:
           print("Tree is empty!"	)
           return
        A_       :					Dict        =      del_node(self.root      ,   snake_case	)





     def __str__(				self							:Optional[int]      ,   ):  # a level traversale, gives a more intuitive look on the tree





        '''simple docstring'''




        A_       :					Optional[Any]        =      ""
        A_       :					Optional[int]        =      MyQueue()
        q.push(self.root	)
        A_       :					Optional[int]        =      self.get_height()
        if layer == 0:
           return output
        A_       :					Dict        =      0
        while not q.is_empty():
           A_       :					Optional[int]        =      q.pop()
           A_       :					Union[str, Any]        =      " " * int(math.pow(2      ,   layer - 1	)	)
           output += space
           if node is None:
              output += "*"
              q.push(snake_case	)
              q.push(snake_case	)
           else:
              output += str(node.get_data()	)
              q.push(node.get_left()	)
              q.push(node.get_right()	)
           output += space
           A_       :					str        =      cnt + 1
           for i in range(100	):
              if cnt == math.pow(2      ,   snake_case	) - 1:
                 A_       :					int        =      layer - 1
                 if layer == 0:
                    output += "\n*************************************"
                    return output
                 output += "\n"
                 break
        output += "\n*************************************"
        return output




def   __snake_case    (       )			->    None:
   import doctest

   doctest.testmod()


if __name__ == "__main__":
 _test()
 _lowerCAmelCase				:   int						       =						AVLtree()
 _lowerCAmelCase				:   Optional[int]						       =						list(range(10))
 random.shuffle(lst)
 for i in lst:
  t.insert(i)
  print(str(t))
 random.shuffle(lst)
 for i in lst:
  t.del_node(i)
  print(str(t))
