

'''simple docstring'''





import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import MobileNetVaImageProcessor


class  UpperCAmelCase (							unittest.TestCase    ):

		'''simple docstring'''






		def __init__(					self   ,			SCREAMING_SNAKE_CASE_   ,			SCREAMING_SNAKE_CASE_=7   ,			SCREAMING_SNAKE_CASE_=3   ,			SCREAMING_SNAKE_CASE_=18   ,			SCREAMING_SNAKE_CASE_=30   ,			SCREAMING_SNAKE_CASE_=400   ,			SCREAMING_SNAKE_CASE_=True   ,			SCREAMING_SNAKE_CASE_=None   ,			SCREAMING_SNAKE_CASE_=True   ,			SCREAMING_SNAKE_CASE_=None   ,			)  ->     str:






							'''simple docstring'''



							lowerCamelCase_  				=      size if size is not None else {"""shortest_edge""": 20}
							lowerCamelCase_  				=      crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
							lowerCamelCase_  				=      parent
							lowerCamelCase_  				=      batch_size
							lowerCamelCase_  				=      num_channels
							lowerCamelCase_  				=      image_size
							lowerCamelCase_  				=      min_resolution
							lowerCamelCase_  				=      max_resolution
							lowerCamelCase_  				=      do_resize
							lowerCamelCase_  				=      size
							lowerCamelCase_  				=      do_center_crop
							lowerCamelCase_  				=      crop_size






		def 			UpperCamelCase(					self		)  ->     Dict:






							'''simple docstring'''



							return {
							    "do_resize": self.do_resize,
							    "size": self.size,
							    "do_center_crop": self.do_center_crop,
							    "crop_size": self.crop_size,
							}


@require_torch
@require_vision
class  UpperCAmelCase (							snake_case_  , unittest.TestCase    ):

		'''simple docstring'''






		SCREAMING_SNAKE_CASE_           =					MobileNetVaImageProcessor if is_vision_available() else None
		def 			UpperCamelCase(					self		)  ->     List[str]:






							'''simple docstring'''



							lowerCamelCase_  				=      MobileNetVaImageProcessingTester(self		)
		@property
		def 			UpperCamelCase(					self		)  ->     Optional[Any]:






							'''simple docstring'''



							return self.image_processor_tester.prepare_image_processor_dict()
		def 			UpperCamelCase(					self		)  ->     List[str]:






							'''simple docstring'''



							lowerCamelCase_  				=      self.image_processing_class(**self.image_processor_dict		)
							self.assertTrue(hasattr(lowercase__   ,			'do_resize'		)		)
							self.assertTrue(hasattr(lowercase__   ,			'size'		)		)
							self.assertTrue(hasattr(lowercase__   ,			'do_center_crop'		)		)
							self.assertTrue(hasattr(lowercase__   ,			'crop_size'		)		)
		def 			UpperCamelCase(					self		)  ->     Optional[int]:






							'''simple docstring'''



							lowerCamelCase_  				=      self.image_processing_class.from_dict(self.image_processor_dict		)
							self.assertEqual(image_processor.size   ,			{'shortest_edge': 20}		)
							self.assertEqual(image_processor.crop_size   ,			{'height': 18, 'width': 18}		)

							lowerCamelCase_  				=      self.image_processing_class.from_dict(self.image_processor_dict   ,			size=42   ,			crop_size=84		)
							self.assertEqual(image_processor.size   ,			{'shortest_edge': 42}		)
							self.assertEqual(image_processor.crop_size   ,			{'height': 84, 'width': 84}		)
		def 			UpperCamelCase(					self		)  ->     Dict:






							'''simple docstring'''



							pass
		def 			UpperCamelCase(					self		)  ->     List[Any]:






							'''simple docstring'''



							lowerCamelCase_  				=      self.image_processing_class(**self.image_processor_dict		)
							# create random PIL images
							lowerCamelCase_  				=      prepare_image_inputs(self.image_processor_tester   ,			equal_resolution=lowercase__		)
							for image in image_inputs:
												self.assertIsInstance(lowercase__   ,			Image.Image		)

							# Test not batched input
							lowerCamelCase_  				=      image_processing(image_inputs[0]   ,			return_tensors='pt'		).pixel_values
							self.assertEqual(
							    encoded_images.shape   ,			(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    )   ,			)

							# Test batched
							lowerCamelCase_  				=      image_processing(lowercase__   ,			return_tensors='pt'		).pixel_values
							self.assertEqual(
							    encoded_images.shape   ,			(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    )   ,			)
		def 			UpperCamelCase(					self		)  ->     Dict:






							'''simple docstring'''



							lowerCamelCase_  				=      self.image_processing_class(**self.image_processor_dict		)
							# create random numpy tensors
							lowerCamelCase_  				=      prepare_image_inputs(self.image_processor_tester   ,			equal_resolution=lowercase__   ,			numpify=lowercase__		)
							for image in image_inputs:
												self.assertIsInstance(lowercase__   ,			np.ndarray		)

							# Test not batched input
							lowerCamelCase_  				=      image_processing(image_inputs[0]   ,			return_tensors='pt'		).pixel_values
							self.assertEqual(
							    encoded_images.shape   ,			(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    )   ,			)

							# Test batched
							lowerCamelCase_  				=      image_processing(lowercase__   ,			return_tensors='pt'		).pixel_values
							self.assertEqual(
							    encoded_images.shape   ,			(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    )   ,			)






		def 			UpperCamelCase(					self		)  ->     Optional[Any]:






							'''simple docstring'''



							lowerCamelCase_  				=      self.image_processing_class(**self.image_processor_dict		)
							# create random PyTorch tensors
							lowerCamelCase_  				=      prepare_image_inputs(self.image_processor_tester   ,			equal_resolution=lowercase__   ,			torchify=lowercase__		)
							for image in image_inputs:
												self.assertIsInstance(lowercase__   ,			torch.Tensor		)

							# Test not batched input
							lowerCamelCase_  				=      image_processing(image_inputs[0]   ,			return_tensors='pt'		).pixel_values
							self.assertEqual(
							    encoded_images.shape   ,			(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    )   ,			)

							# Test batched
							lowerCamelCase_  				=      image_processing(lowercase__   ,			return_tensors='pt'		).pixel_values
							self.assertEqual(
							    encoded_images.shape   ,			(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    )   ,			)









'''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()
