




import pytest

from datasets import Dataset, DatasetDict, Features, NamedSplit, Value
from datasets.io.text import TextDatasetReader

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases
def 		a_							( __lowerCAmelCase   , __lowerCAmelCase				):
  assert isinstance(__lowerCAmelCase   , __lowerCAmelCase				)
  assert dataset.num_rows == 4
  assert dataset.num_columns == 1
  assert dataset.column_names == ["text"]
  for feature, expected_dtype in expected_features.items():
    assert dataset.features[feature].dtype == expected_dtype
@pytest.mark.parametrize('''keep_in_memory'''   , [False, True]				)
def 		a_							( __lowerCAmelCase   , __lowerCAmelCase   , __lowerCAmelCase				):
  lowerCAmelCase__										=      tmp_path / '''cache'''
  lowerCAmelCase__										=      {'''text''': '''string'''}
  with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
    lowerCAmelCase__										=      TextDatasetReader(__lowerCAmelCase   , cache_dir=__lowerCAmelCase   , keep_in_memory=__lowerCAmelCase				).read()
  _check_text_dataset(__lowerCAmelCase   , __lowerCAmelCase				)
@pytest.mark.parametrize(
    '''features'''   , [
        None,
        {'''text''': '''string'''},
        {'''text''': '''int32'''},
        {'''text''': '''float32'''},
    ]   , )
def 		a_							( __lowerCAmelCase   , __lowerCAmelCase   , __lowerCAmelCase				):
  lowerCAmelCase__										=      tmp_path / '''cache'''
  lowerCAmelCase__										=      {'''text''': '''string'''}
  lowerCAmelCase__										=      features.copy() if features else default_expected_features
  lowerCAmelCase__										=      (
      Features({feature: Value(__lowerCAmelCase				) for feature, dtype in features.items()}				) if features is not None else None
  )
  lowerCAmelCase__										=      TextDatasetReader(__lowerCAmelCase   , features=__lowerCAmelCase   , cache_dir=__lowerCAmelCase				).read()
  _check_text_dataset(__lowerCAmelCase   , __lowerCAmelCase				)
@pytest.mark.parametrize('''split'''   , [None, NamedSplit('''train'''				), '''train''', '''test''']				)
def 		a_							( __lowerCAmelCase   , __lowerCAmelCase   , __lowerCAmelCase				):
  lowerCAmelCase__										=      tmp_path / '''cache'''
  lowerCAmelCase__										=      {'''text''': '''string'''}
  lowerCAmelCase__										=      TextDatasetReader(__lowerCAmelCase   , cache_dir=__lowerCAmelCase   , split=__lowerCAmelCase				).read()
  _check_text_dataset(__lowerCAmelCase   , __lowerCAmelCase				)
  assert dataset.split == split if split else "train"
@pytest.mark.parametrize('''path_type'''   , [str, list]				)
def 		a_							( __lowerCAmelCase   , __lowerCAmelCase   , __lowerCAmelCase				):




  if issubclass(__lowerCAmelCase   , __lowerCAmelCase				):
    lowerCAmelCase__										=      text_path
  elif issubclass(__lowerCAmelCase   , __lowerCAmelCase				):
    lowerCAmelCase__										=      [text_path]
  lowerCAmelCase__										=      tmp_path / '''cache'''
  lowerCAmelCase__										=      {'''text''': '''string'''}
  lowerCAmelCase__										=      TextDatasetReader(__lowerCAmelCase   , cache_dir=__lowerCAmelCase				).read()
  _check_text_dataset(__lowerCAmelCase   , __lowerCAmelCase				)
def 		a_							( __lowerCAmelCase   , __lowerCAmelCase   , __lowerCAmelCase=("train",)				):
  assert isinstance(__lowerCAmelCase   , __lowerCAmelCase				)
  for split in splits:
    lowerCAmelCase__										=      dataset_dict[split]
    assert dataset.num_rows == 4
    assert dataset.num_columns == 1
    assert dataset.column_names == ["text"]
    for feature, expected_dtype in expected_features.items():
      assert dataset.features[feature].dtype == expected_dtype
@pytest.mark.parametrize('''keep_in_memory'''   , [False, True]				)
def 		a_							( __lowerCAmelCase   , __lowerCAmelCase   , __lowerCAmelCase				):
  lowerCAmelCase__										=      tmp_path / '''cache'''
  lowerCAmelCase__										=      {'''text''': '''string'''}
  with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
    lowerCAmelCase__										=      TextDatasetReader({'''train''': text_path}   , cache_dir=__lowerCAmelCase   , keep_in_memory=__lowerCAmelCase				).read()
  _check_text_datasetdict(__lowerCAmelCase   , __lowerCAmelCase				)
@pytest.mark.parametrize(
    '''features'''   , [
        None,
        {'''text''': '''string'''},
        {'''text''': '''int32'''},
        {'''text''': '''float32'''},
    ]   , )
def 		a_							( __lowerCAmelCase   , __lowerCAmelCase   , __lowerCAmelCase				):
  lowerCAmelCase__										=      tmp_path / '''cache'''
  # CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
  lowerCAmelCase__										=      {'''text''': '''string'''}
  lowerCAmelCase__										=      features.copy() if features else default_expected_features
  lowerCAmelCase__										=      (
      Features({feature: Value(__lowerCAmelCase				) for feature, dtype in features.items()}				) if features is not None else None
  )
  lowerCAmelCase__										=      TextDatasetReader({'''train''': text_path}   , features=__lowerCAmelCase   , cache_dir=__lowerCAmelCase				).read()
  _check_text_datasetdict(__lowerCAmelCase   , __lowerCAmelCase				)




@pytest.mark.parametrize('''split'''   , [None, NamedSplit('''train'''				), '''train''', '''test''']				)
def 		a_							( __lowerCAmelCase   , __lowerCAmelCase   , __lowerCAmelCase				):




  if split:
    lowerCAmelCase__										=      {split: text_path}
  else:
    lowerCAmelCase__										=      '''train'''
    lowerCAmelCase__										=      {'''train''': text_path, '''test''': text_path}
  lowerCAmelCase__										=      tmp_path / '''cache'''
  lowerCAmelCase__										=      {'''text''': '''string'''}
  lowerCAmelCase__										=      TextDatasetReader(__lowerCAmelCase   , cache_dir=__lowerCAmelCase				).read()
  _check_text_datasetdict(__lowerCAmelCase   , __lowerCAmelCase   , splits=list(path.keys()				)				)
  assert all(dataset[split].split == split for split in path.keys()				)








"""simple docstring"""





def      UpperCAmelCase__				(    SCREAMING_SNAKE_CASE	:		str     ):







      '''simple docstring'''




      lowerCAmelCase    		=			""""""
      for ch in key:
            if ch == " " or ch not in key_no_dups and ch.isalpha():
                  key_no_dups += ch
      return key_no_dups


def      UpperCAmelCase__				(    SCREAMING_SNAKE_CASE	:		str     ):







      '''simple docstring'''




      lowerCAmelCase    		=			[chr(i + 65     ) for i in range(26     )]
      # Remove duplicate characters from key
      lowerCAmelCase    		=			remove_duplicates(key.upper()     )
      lowerCAmelCase    		=			len(SCREAMING_SNAKE_CASE     )
      # First fill cipher with key characters
      lowerCAmelCase    		=			{alphabet[i]: char for i, char in enumerate(SCREAMING_SNAKE_CASE     )}
      # Then map remaining characters in alphabet to
      # the alphabet from the beginning
      for i in range(len(SCREAMING_SNAKE_CASE     )				,		26     ):
            lowerCAmelCase    		=			alphabet[i - offset]
            # Ensure we are not mapping letters to letters previously mapped
            while char in key:
                  offset -= 1
                  lowerCAmelCase    		=			alphabet[i - offset]
            lowerCAmelCase    		=			char
      return cipher_alphabet


def      UpperCAmelCase__				(    SCREAMING_SNAKE_CASE	:		str				,		SCREAMING_SNAKE_CASE	:		dict[str, str]     ):







      '''simple docstring'''




      return "".join(cipher_map.get(SCREAMING_SNAKE_CASE				,		SCREAMING_SNAKE_CASE     ) for ch in message.upper()     )


def      UpperCAmelCase__				(    SCREAMING_SNAKE_CASE	:		str				,		SCREAMING_SNAKE_CASE	:		dict[str, str]     ):







      '''simple docstring'''




      lowerCAmelCase    		=			{v: k for k, v in cipher_map.items()}
      return "".join(rev_cipher_map.get(SCREAMING_SNAKE_CASE				,		SCREAMING_SNAKE_CASE     ) for ch in message.upper()     )


def      UpperCAmelCase__				(    ):







      '''simple docstring'''




      lowerCAmelCase    		=			input("""Enter message to encode or decode: """     ).strip()
      lowerCAmelCase    		=			input("""Enter keyword: """     ).strip()
      lowerCAmelCase    		=			input("""Encipher or decipher? E/D:"""     ).strip()[0].lower()
      try:
            lowerCAmelCase    		=			{"""e""": encipher, """d""": decipher}[option]
      except KeyError:
            raise KeyError("""invalid input option"""     )
      lowerCAmelCase    		=			create_cipher_map(SCREAMING_SNAKE_CASE     )
      print(func(SCREAMING_SNAKE_CASE				,		SCREAMING_SNAKE_CASE     )     )


if __name__ == "__main__":
       import doctest

       doctest.testmod()
       main()






