

'''simple docstring'''





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   _UpperCamelCase	(		__UpperCamelCase    ,__UpperCamelCase	)       ->			Tuple:
					assert isinstance(UpperCamelCase__    ,UpperCamelCase__	)
					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   _UpperCamelCase	(		__UpperCamelCase    ,__UpperCamelCase    ,__UpperCamelCase	)       ->			Dict:
					lowerCamelCase_  				=      tmp_path / """cache"""
					lowerCamelCase_  				=      {"""text""": """string"""}
					with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
										lowerCamelCase_  				=      TextDatasetReader(UpperCamelCase__    ,cache_dir=UpperCamelCase__    ,keep_in_memory=UpperCamelCase__	).read()
					_check_text_dataset(UpperCamelCase__    ,UpperCamelCase__	)







@pytest.mark.parametrize(
    'features'    ,[
        None,
        {'text': 'string'},
        {'text': 'int32'},
        {'text': 'float32'},
    ]    ,)
def   _UpperCamelCase	(		__UpperCamelCase    ,__UpperCamelCase    ,__UpperCamelCase	)       ->			Tuple:
					lowerCamelCase_  				=      tmp_path / """cache"""
					lowerCamelCase_  				=      {"""text""": """string"""}
					lowerCamelCase_  				=      features.copy() if features else default_expected_features
					lowerCamelCase_  				=      (
					    Features({feature: Value(UpperCamelCase__	) for feature, dtype in features.items()}	) if features is not None else None
					)
					lowerCamelCase_  				=      TextDatasetReader(UpperCamelCase__    ,features=UpperCamelCase__    ,cache_dir=UpperCamelCase__	).read()
					_check_text_dataset(UpperCamelCase__    ,UpperCamelCase__	)







@pytest.mark.parametrize('split'    ,[None, NamedSplit('train'	), 'train', 'test']	)
def   _UpperCamelCase	(		__UpperCamelCase    ,__UpperCamelCase    ,__UpperCamelCase	)       ->			List[Any]:
					lowerCamelCase_  				=      tmp_path / """cache"""
					lowerCamelCase_  				=      {"""text""": """string"""}
					lowerCamelCase_  				=      TextDatasetReader(UpperCamelCase__    ,cache_dir=UpperCamelCase__    ,split=UpperCamelCase__	).read()
					_check_text_dataset(UpperCamelCase__    ,UpperCamelCase__	)
					assert dataset.split == split if split else "train"







@pytest.mark.parametrize('path_type'    ,[str, list]	)
def   _UpperCamelCase	(		__UpperCamelCase    ,__UpperCamelCase    ,__UpperCamelCase	)       ->			Tuple:


					if issubclass(UpperCamelCase__    ,UpperCamelCase__	):
										lowerCamelCase_  				=      text_path
					elif issubclass(UpperCamelCase__    ,UpperCamelCase__	):
										lowerCamelCase_  				=      [text_path]
					lowerCamelCase_  				=      tmp_path / """cache"""
					lowerCamelCase_  				=      {"""text""": """string"""}
					lowerCamelCase_  				=      TextDatasetReader(UpperCamelCase__    ,cache_dir=UpperCamelCase__	).read()
					_check_text_dataset(UpperCamelCase__    ,UpperCamelCase__	)







def   _UpperCamelCase	(		__UpperCamelCase    ,__UpperCamelCase    ,__UpperCamelCase=("train",)	)       ->			Tuple:
					assert isinstance(UpperCamelCase__    ,UpperCamelCase__	)
					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   _UpperCamelCase	(		__UpperCamelCase    ,__UpperCamelCase    ,__UpperCamelCase	)       ->			List[Any]:
					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=UpperCamelCase__    ,keep_in_memory=UpperCamelCase__	).read()
					_check_text_datasetdict(UpperCamelCase__    ,UpperCamelCase__	)







@pytest.mark.parametrize(
    'features'    ,[
        None,
        {'text': 'string'},
        {'text': 'int32'},
        {'text': 'float32'},
    ]    ,)
def   _UpperCamelCase	(		__UpperCamelCase    ,__UpperCamelCase    ,__UpperCamelCase	)       ->			str:
					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(UpperCamelCase__	) for feature, dtype in features.items()}	) if features is not None else None
					)
					lowerCamelCase_  				=      TextDatasetReader({'train': text_path}    ,features=UpperCamelCase__    ,cache_dir=UpperCamelCase__	).read()
					_check_text_datasetdict(UpperCamelCase__    ,UpperCamelCase__	)







@pytest.mark.parametrize('split'    ,[None, NamedSplit('train'	), 'train', 'test']	)
def   _UpperCamelCase	(		__UpperCamelCase    ,__UpperCamelCase    ,__UpperCamelCase	)       ->			Optional[int]:


					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(UpperCamelCase__    ,cache_dir=UpperCamelCase__	).read()
					_check_text_datasetdict(UpperCamelCase__    ,UpperCamelCase__    ,splits=list(path.keys()	)	)
					assert all(dataset[split].split == split for split in path.keys()	)









'''simple docstring'''


from unittest.mock import Mock, patch

from file_transfer.send_file import send_file



@patch("""socket.socket"""				)
@patch("""builtins.open"""				)
def  _SCREAMING_SNAKE_CASE     (      UpperCamelCase__    :					Dict ,    UpperCamelCase__    :					Tuple				):




     """simple docstring"""


     a_     :							Dict     						=  Mock()
     a_     :							List[str]     						=  conn, Mock()
     a_     :							Optional[int]     						=  iter([1, None]				)
     a_     :							List[str]     						=  lambda UpperCamelCase__				: next(UpperCamelCase__				)

     # ===== invoke =====
     send_file(filename="""mytext.txt""" ,    testing=UpperCamelCase__				)

     # ===== ensurance =====
     sock.assert_called_once()
     sock.return_value.bind.assert_called_once()
     sock.return_value.listen.assert_called_once()
     sock.return_value.accept.assert_called_once()
     conn.recv.assert_called_once()

     file.return_value.__enter__.assert_called_once()
     file.return_value.__enter__.return_value.read.assert_called()

     conn.send.assert_called_once()
     conn.close.assert_called_once()
     sock.return_value.shutdown.assert_called_once()
     sock.return_value.close.assert_called_once()
