

from unittest import TestCase

from datasets import Sequence, Value
from datasets.arrow_dataset import Dataset







class 					__lowercase  (						_SCREAMING_SNAKE_CASE				):





							"""simple docstring"""

							def       snake_case			(					self						)		->       int:
														return [
														    {"col_1": 3, "col_2": "a"},
														    {"col_1": 2, "col_2": "b"},
														    {"col_1": 1, "col_2": "c"},
														    {"col_1": 0, "col_2": "d"},
														]




							def       snake_case			(					self						)		->       int:
														A      :					List[str]      		=					{'''col_1''': [3, 2, 1, 0], '''col_2''': ['''a''', '''b''', '''c''', '''d''']}
														return Dataset.from_dict(__UpperCAmelCase						)




							def       snake_case			(					self						)		->       Optional[int]:
														A      :					int      		=					self._create_example_records()
														A      :					Optional[Any]      		=					Dataset.from_list(__UpperCAmelCase						)
														self.assertListEqual(dset.column_names    ,						['''col_1''', '''col_2''']						)
														for i, r in enumerate(__UpperCAmelCase						):
																					self.assertDictEqual(__UpperCAmelCase    ,						example_records[i]						)




							def       snake_case			(					self						)		->       Optional[int]:
														A      :					List[str]      		=					self._create_example_records()
														A      :					Optional[Any]      		=					Dataset.from_list(__UpperCAmelCase						)
														A      :					Tuple      		=					Dataset.from_dict({k: [r[k] for r in example_records] for k in example_records[0]}						)
														self.assertEqual(dset.info    ,						dset_from_dict.info						)




							def       snake_case			(					self						)		->       Dict:  # checks what happens with missing columns
														A      :					Tuple      		=					[{'''col_1''': 1}, {'''col_2''': '''x'''}]
														A      :					Dict      		=					Dataset.from_list(__UpperCAmelCase						)
														self.assertDictEqual(dset[0]    ,						{'''col_1''': 1}						)
														self.assertDictEqual(dset[1]    ,						{'''col_1''': None}						)  # NB: first record is used for columns




							def       snake_case			(					self						)		->       int:  # checks if the type can be inferred from the second record
														A      :					Optional[Any]      		=					[{'''col_1''': []}, {'''col_1''': [1, 2]}]
														A      :					str      		=					Dataset.from_list(__UpperCAmelCase						)
														self.assertEqual(dset.info.features['''col_1''']    ,						Sequence(Value('''int64'''						)						)						)






							def       snake_case			(					self						)		->       Tuple:
														A      :					Dict      		=					Dataset.from_list([]						)
														self.assertEqual(len(__UpperCAmelCase						)    ,						0						)
														self.assertListEqual(dset.column_names    ,						[]						)









import unittest

from transformers import load_tool
from transformers.utils import is_torch_available


if is_torch_available():
		import torch

from transformers.testing_utils import require_torch

from .test_tools_common import ToolTesterMixin







@require_torch
class 					__lowercase  (						unittest.TestCase		,       _SCREAMING_SNAKE_CASE				):





							"""simple docstring"""

							def       snake_case			(					self						)		->       Optional[Any]:
														A      :					Optional[Any]      		=					load_tool('''text-to-speech'''						)
														self.tool.setup()




							def       snake_case			(					self						)		->       Union[str, Any]:
														# SpeechT5 isn't deterministic
														torch.manual_seed(0						)
														A      :					Optional[Any]      		=					self.tool('''hey'''						)
														A      :					List[str]      		=					result.to_raw()
														self.assertTrue(
														    torch.allclose(
														        resulting_tensor[:3]    ,						torch.tensor([-0.0_0_0_5_9_6_6_6_6_8_8_3_2_1_1_5_8_2_9, -0.0_0_0_3_6_5_7_6_4_0_1_9_0_7_9_5_0_6_4, -0.0_0_0_1_3_4_3_9_5_0_2_7_9_9_8_8_3_4_8_5]						)    ,						)						)






							def       snake_case			(					self						)		->       Optional[Any]:
														# SpeechT5 isn't deterministic
														torch.manual_seed(0						)
														A      :					int      		=					self.tool('''hey'''						)
														A      :					Any      		=					result.to_raw()
														self.assertTrue(
														    torch.allclose(
														        resulting_tensor[:3]    ,						torch.tensor([-0.0_0_0_5_9_6_6_6_6_8_8_3_2_1_1_5_8_2_9, -0.0_0_0_3_6_5_7_6_4_0_1_9_0_7_9_5_0_6_4, -0.0_0_0_1_3_4_3_9_5_0_2_7_9_9_8_8_3_4_8_5]						)    ,						)						)






