



from unittest.mock import Mock, patch

from file_transfer.send_file import send_file


@patch("socket.socket"						)
@patch("builtins.open"						)
def  __lowerCamelCase (       lowerCamelCase__					,			lowerCamelCase__						):

				"""simple docstring"""


				lowercase__					:   List[Any]													=					Mock()
				lowercase__					:   Union[str, Any]													=					conn, Mock()
				lowercase__					:   List[str]													=					iter([1, None]						)
				lowercase__					:   int													=					lambda lowerCamelCase__						: next(lowerCamelCase__						)

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

				# ===== 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()









import unittest

from transformers import is_flax_available
from transformers.testing_utils import require_flax, require_sentencepiece, require_tokenizers, require_torch, slow


if is_flax_available():
				import optax
				from flax.training.common_utils import onehot

				from transformers import AutoTokenizer, FlaxMTaForConditionalGeneration
				from transformers.models.ta.modeling_flax_ta import shift_tokens_right

@require_torch
@require_sentencepiece
@require_tokenizers
@require_flax
class 				snake_case__(unittest.TestCase      ):

					"""simple docstring"""






					@slow
					def 			snake_case					(							self :     Optional[int]					):
									lowercase__					:   Dict													=					FlaxMTaForConditionalGeneration.from_pretrained("google/mt5-small"					)
									lowercase__					:   Dict													=					AutoTokenizer.from_pretrained("google/mt5-small"					)

									lowercase__					:   Optional[Any]													=					tokenizer("Hello there"				,       return_tensors="np"					).input_ids
									lowercase__					:   Optional[Any]													=					tokenizer("Hi I am"				,       return_tensors="np"					).input_ids

									lowercase__					:   int													=					shift_tokens_right(SCREAMING_SNAKE_CASE				,       model.config.pad_token_id				,       model.config.decoder_start_token_id					)

									lowercase__					:   Tuple													=					model(SCREAMING_SNAKE_CASE				,       decoder_input_ids=SCREAMING_SNAKE_CASE					).logits
									lowercase__					:   Dict													=					optax.softmax_cross_entropy(SCREAMING_SNAKE_CASE				,       onehot(SCREAMING_SNAKE_CASE				,       logits.shape[-1]					)					).mean()

									lowercase__					:   Union[str, Any]													=					-(labels.shape[-1] * loss.item())

									lowercase__					:   Union[str, Any]													=					-84.9_127
									self.assertTrue(abs(mtf_score - EXPECTED_SCORE					) < 1E-4					)




