





'''simple docstring'''







import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


_lowercase       						=			False
try:
   _lowercase       						=			_is_package_available('google.colab')
except ModuleNotFoundError:
   pass
@input.register
class 			_lowercase						:







     def __init__( self    ,   A__ = None    ,   A__ = []    ) ->	List[str]:
      snake_case				=			0
      snake_case				=			choices
      snake_case				=			prompt
      if sys.platform == "win32":
       snake_case				=			'''*'''
      else:
       snake_case				=			'''➔ '''







     def     UpperCamelCase			( self    ,   A__    ,   A__ = ""    ) ->	Optional[Any]:
      if sys.platform != "win32":
       writeColor(self.choices[index]    ,   32    ,   A__    )
      else:
       forceWrite(self.choices[index]    ,   A__    )







     def     UpperCamelCase			( self    ,   A__    ) ->	Union[str, Any]:
      if index == self.position:
       forceWrite(F""" {self.arrow_char} """    )
       self.write_choice(A__    )
      else:
       forceWrite(F"""    {self.choices[index]}"""    )
      reset_cursor()







     def     UpperCamelCase			( self    ,   A__    ,   A__ = 1    ) ->	str:
      snake_case				=			self.position
      if direction == Direction.DOWN:
       if self.position + 1 >= len(self.choices    ):
        return
       self.position += num_spaces
      else:
       if self.position - 1 < 0:
        return
       self.position -= num_spaces
      clear_line()
      self.print_choice(A__    )
      move_cursor(A__    ,   direction.name    )
      self.print_choice(self.position    )







     @input.mark(KEYMAP['''up''']    )
     def     UpperCamelCase			( self    ) ->	int:
      self.move_direction(Direction.UP    )







     @input.mark(KEYMAP['''down''']    )
     def     UpperCamelCase			( self    ) ->	Tuple:
      self.move_direction(Direction.DOWN    )







     @input.mark(KEYMAP['''newline''']    )
     def     UpperCamelCase			( self    ) ->	int:
      move_cursor(len(self.choices    ) - self.position    ,   '''DOWN'''    )
      return self.position







     @input.mark(KEYMAP['''interrupt''']    )
     def     UpperCamelCase			( self    ) ->	List[str]:
      move_cursor(len(self.choices    ) - self.position    ,   '''DOWN'''    )
      raise KeyboardInterrupt







     @input.mark_multiple(*[KEYMAP[str(A__    )] for number in range(10    )]    )
     def     UpperCamelCase			( self    ) ->	Tuple:
      snake_case				=			int(chr(self.current_selection    )    )
      snake_case				=			index - self.position
      if index == self.position:
       return
      if index < len(self.choices    ):
       if self.position > index:
        self.move_direction(Direction.UP    ,   -movement    )
       elif self.position < index:
        self.move_direction(Direction.DOWN    ,   A__    )
       else:
        return
      else:
       return







     def     UpperCamelCase			( self    ,   A__ = 0    ) ->	List[Any]:
      if self.prompt:
       linebreak()
       forceWrite(self.prompt    ,   '''\n'''    )
       if in_colab:
        forceWrite('''Please input a choice index (starting from 0), and press enter'''    ,   '''\n'''    )
       else:
        forceWrite('''Please select a choice using the arrow or number keys, and selecting with enter'''    ,   '''\n'''    )
      snake_case				=			default_choice
      for i in range(len(self.choices    )    ):
       self.print_choice(A__    )
       forceWrite('''\n'''    )
      move_cursor(len(self.choices    ) - self.position    ,   '''UP'''    )
      with cursor.hide():
       while True:
        if in_colab:
         try:
          snake_case				=			int(builtins.input()    )
         except ValueError:
          snake_case				=			default_choice
        else:
         snake_case				=			self.handle_input()
        if choice is not None:
         reset_cursor()
         for _ in range(len(self.choices    ) + 1    ):
          move_cursor(1    ,   '''UP'''    )
          clear_line()
         self.write_choice(A__    ,   '''\n'''    )
         return choice








'''simple docstring'''







import os
from tempfile import TemporaryDirectory
from unittest import TestCase

import pytest
from absl.testing import parameterized

from datasets import config
from datasets.arrow_reader import HF_GCP_BASE_URL
from datasets.builder import DatasetBuilder
from datasets.dataset_dict import IterableDatasetDict
from datasets.iterable_dataset import IterableDataset
from datasets.load import dataset_module_factory, import_main_class
from datasets.utils.file_utils import cached_path


_lowercase       						=			[
    {'dataset': 'wikipedia', 'config_name': '20220301.de'},
    {'dataset': 'wikipedia', 'config_name': '20220301.en'},
    {'dataset': 'wikipedia', 'config_name': '20220301.fr'},
    {'dataset': 'wikipedia', 'config_name': '20220301.frr'},
    {'dataset': 'wikipedia', 'config_name': '20220301.it'},
    {'dataset': 'wikipedia', 'config_name': '20220301.simple'},
    {'dataset': 'snli', 'config_name': 'plain_text'},
    {'dataset': 'eli5', 'config_name': 'LFQA_reddit'},
    {'dataset': 'wiki40b', 'config_name': 'en'},
    {'dataset': 'wiki_dpr', 'config_name': 'psgs_w100.nq.compressed'},
    {'dataset': 'wiki_dpr', 'config_name': 'psgs_w100.nq.no_index'},
    {'dataset': 'wiki_dpr', 'config_name': 'psgs_w100.multiset.no_index'},
    {'dataset': 'natural_questions', 'config_name': 'default'},
]

def    __UpperCamelCase	(	a    : Dict=True     ) ->str:
 if with_config:
  return [
      {
          "testcase_name": d["dataset"] + "/" + d["config_name"],
          "dataset": d["dataset"],
          "config_name": d["config_name"],
      }
      for d in DATASETS_ON_HF_GCP
  ]
 else:
  return [
      {"testcase_name": dataset, "dataset": dataset} for dataset in {d["dataset"] for d in DATASETS_ON_HF_GCP}
  ]
@parameterized.named_parameters(list_datasets_on_hf_gcp_parameters(with_config=__a					)					)
class 			_lowercase						(       __a					):
     _UpperCAmelCase										=					None
     _UpperCAmelCase										=					None







     def     UpperCamelCase			( self    ,   A__    ,   A__    ) ->	str:
      with TemporaryDirectory() as tmp_dir:
       snake_case				=			dataset_module_factory(A__    ,   cache_dir=A__    )

       snake_case				=			import_main_class(dataset_module.module_path    ,   dataset=A__    )

       snake_case				=			builder_cls(
           cache_dir=A__    ,   config_name=A__    ,   hash=dataset_module.hash    ,   )

       snake_case				=			'''/'''.join(
           [
               HF_GCP_BASE_URL,
               builder_instance._relative_data_dir(with_hash=A__    ).replace(os.sep    ,   '''/'''    ),
               config.DATASET_INFO_FILENAME,
           ]    )
       snake_case				=			cached_path(A__    ,   cache_dir=A__    )
       self.assertTrue(os.path.exists(A__    )    )




@pytest.mark.integration
def    __UpperCamelCase	(	a    : List[str]     ) ->Any:
 snake_case				=			tmp_path_factory.mktemp('''test_hf_gcp'''     ) / '''test_wikipedia_simple'''
 snake_case				=			dataset_module_factory('''wikipedia'''					,   cache_dir=a     )
 snake_case				=			import_main_class(dataset_module.module_path     )
 snake_case				=			builder_cls(
     cache_dir=a					,   config_name='''20220301.frr'''					,   hash=dataset_module.hash					,   )
 # use the HF cloud storage, not the original download_and_prepare that uses apache-beam
 snake_case				=			None
 builder_instance.download_and_prepare()
 snake_case				=			builder_instance.as_dataset()
 assert ds






@pytest.mark.integration
def    __UpperCamelCase	(	a    : Any     ) ->Union[str, Any]:
 snake_case				=			dataset_module_factory('''wikipedia'''					,   cache_dir=a     )
 snake_case				=			import_main_class(dataset_module.module_path					,   dataset=a     )
 snake_case				=			builder_cls(
     cache_dir=a					,   config_name='''20220301.frr'''					,   hash=dataset_module.hash					,   )
 snake_case				=			builder_instance.as_streaming_dataset()
 assert ds
 assert isinstance(a					,   a     )
 assert "train" in ds
 assert isinstance(ds['''train''']					,   a     )
 assert next(iter(ds['''train''']     )     )

