


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


if is_torch_available():
       import torch

if is_vision_available():
       from PIL import Image

       from transformers import BlipImageProcessor







class  UpperCAmelCase (       unittest.TestCase):

 def __init__( self :	Union[str, Any],					a_ :	Optional[Any],					a_ :	Optional[Any]=7,					a_ :	str=3,					a_ :	Dict=18,					a_ :	Tuple=30,					a_ :	Tuple=400,					a_ :	Any=True,					a_ :	Optional[Any]=None,					a_ :	Optional[int]=True,					a_ :	int=False,					a_ :	Dict=[0.48_145_466, 0.4_578_275, 0.40_821_073],					a_ :	Any=[0.26_862_954, 0.26_130_258, 0.27_577_711],					a_ :	str=True,					):





    """simple docstring"""



    UpperCamelCase__ 						=						size if size is not None else {"height": 20, "width": 20}
    UpperCamelCase__ 						=						parent
    UpperCamelCase__ 						=						batch_size
    UpperCamelCase__ 						=						num_channels
    UpperCamelCase__ 						=						image_size
    UpperCamelCase__ 						=						min_resolution
    UpperCamelCase__ 						=						max_resolution
    UpperCamelCase__ 						=						do_resize
    UpperCamelCase__ 						=						size
    UpperCamelCase__ 						=						do_normalize
    UpperCamelCase__ 						=						image_mean
    UpperCamelCase__ 						=						image_std
    UpperCamelCase__ 						=						do_pad
    UpperCamelCase__ 						=						do_convert_rgb

 def 		lowercase_						( self :	Optional[int]					):





    """simple docstring"""



    return {
        "do_resize": self.do_resize,
        "size": self.size,
        "do_normalize": self.do_normalize,
        "image_mean": self.image_mean,
        "image_std": self.image_std,
        "do_convert_rgb": self.do_convert_rgb,
        "do_pad": self.do_pad,
    }

 def 		lowercase_						( self :	Dict,					a_ :	Any=False,					a_ :	Optional[Any]=False,					a_ :	Optional[Any]=False					):





    """simple docstring"""



    assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

    if equal_resolution:
       UpperCamelCase__ 						=						[]
       for i in range(self.batch_size					):
          image_inputs.append(
              np.random.randint(
                  255,					size=(self.num_channels, self.max_resolution, self.max_resolution),					dtype=np.uinta					)					)
    else:
       UpperCamelCase__ 						=						[]
       for i in range(self.batch_size					):
          UpperCamelCase__						,		UpperCamelCase__ 						=						np.random.choice(np.arange(self.min_resolution,					self.max_resolution					),					2					)
          image_inputs.append(np.random.randint(255,					size=(self.num_channels, width, height),					dtype=np.uinta					)					)

    if not numpify and not torchify:
       # PIL expects the channel dimension as last dimension
       UpperCamelCase__ 						=						[Image.fromarray(np.moveaxis(a_,					0,					-1					)					) for x in image_inputs]

    if torchify:
       UpperCamelCase__ 						=						[torch.from_numpy(a_					) for x in image_inputs]

    return image_inputs







@require_torch
@require_vision
class  UpperCAmelCase (       SCREAMING_SNAKE_CASE__		,			unittest.TestCase):
 _lowerCamelCase :					str    					=					BlipImageProcessor if is_vision_available() else None

 def 		lowercase_						( self :	Optional[int]					):





    """simple docstring"""



    UpperCamelCase__ 						=						BlipImageProcessingTester(self					)

 @property
 def 		lowercase_						( self :	Union[str, Any]					):





    """simple docstring"""



    return self.image_processor_tester.prepare_image_processor_dict()

 def 		lowercase_						( self :	Any					):





    """simple docstring"""



    UpperCamelCase__ 						=						self.image_processing_class(**self.image_processor_dict					)
    self.assertTrue(hasattr(a_,					"do_resize"					)					)
    self.assertTrue(hasattr(a_,					"size"					)					)
    self.assertTrue(hasattr(a_,					"do_normalize"					)					)
    self.assertTrue(hasattr(a_,					"image_mean"					)					)
    self.assertTrue(hasattr(a_,					"image_std"					)					)
    self.assertTrue(hasattr(a_,					"do_convert_rgb"					)					)

 def 		lowercase_						( self :	Optional[Any]					):





    """simple docstring"""



    pass

 def 		lowercase_						( self :	int					):





    """simple docstring"""



    UpperCamelCase__ 						=						self.image_processing_class(**self.image_processor_dict					)
    # create random PIL images
    UpperCamelCase__ 						=						self.image_processor_tester.prepare_inputs(equal_resolution=a_					)
    for image in image_inputs:
       self.assertIsInstance(a_,					Image.Image					)

    # Test not batched input
    UpperCamelCase__ 						=						image_processor(image_inputs[0],					return_tensors="pt"					).pixel_values
    self.assertEqual(
        encoded_images.shape,					(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.size["height"],
            self.image_processor_tester.size["width"],
        ),					)

    # Test batched
    UpperCamelCase__ 						=						image_processor(a_,					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.size["height"],
            self.image_processor_tester.size["width"],
        ),					)

 def 		lowercase_						( self :	int					):





    """simple docstring"""



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

    # Test not batched input
    UpperCamelCase__ 						=						image_processor(image_inputs[0],					return_tensors="pt"					).pixel_values
    self.assertEqual(
        encoded_images.shape,					(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.size["height"],
            self.image_processor_tester.size["width"],
        ),					)

    # Test batched
    UpperCamelCase__ 						=						image_processor(a_,					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.size["height"],
            self.image_processor_tester.size["width"],
        ),					)

 def 		lowercase_						( self :	Dict					):





    """simple docstring"""



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

    # Test not batched input
    UpperCamelCase__ 						=						image_processor(image_inputs[0],					return_tensors="pt"					).pixel_values
    self.assertEqual(
        encoded_images.shape,					(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.size["height"],
            self.image_processor_tester.size["width"],
        ),					)

    # Test batched
    UpperCamelCase__ 						=						image_processor(a_,					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.size["height"],
            self.image_processor_tester.size["width"],
        ),					)







@require_torch
@require_vision
class  UpperCAmelCase (       SCREAMING_SNAKE_CASE__		,			unittest.TestCase):
 _lowerCamelCase :					int    					=					BlipImageProcessor if is_vision_available() else None

 def 		lowercase_						( self :	str					):





    """simple docstring"""



    UpperCamelCase__ 						=						BlipImageProcessingTester(self,					num_channels=4					)
    UpperCamelCase__ 						=						3

 @property
 def 		lowercase_						( self :	str					):





    """simple docstring"""



    return self.image_processor_tester.prepare_image_processor_dict()

 def 		lowercase_						( self :	str					):





    """simple docstring"""



    UpperCamelCase__ 						=						self.image_processing_class(**self.image_processor_dict					)
    self.assertTrue(hasattr(a_,					"do_resize"					)					)
    self.assertTrue(hasattr(a_,					"size"					)					)
    self.assertTrue(hasattr(a_,					"do_normalize"					)					)
    self.assertTrue(hasattr(a_,					"image_mean"					)					)
    self.assertTrue(hasattr(a_,					"image_std"					)					)
    self.assertTrue(hasattr(a_,					"do_convert_rgb"					)					)

 def 		lowercase_						( self :	Any					):





    """simple docstring"""



    pass

 def 		lowercase_						( self :	List[str]					):





    """simple docstring"""



    UpperCamelCase__ 						=						self.image_processing_class(**self.image_processor_dict					)
    # create random PIL images
    UpperCamelCase__ 						=						self.image_processor_tester.prepare_inputs(equal_resolution=a_					)
    for image in image_inputs:
       self.assertIsInstance(a_,					Image.Image					)

    # Test not batched input
    UpperCamelCase__ 						=						image_processor(image_inputs[0],					return_tensors="pt"					).pixel_values
    self.assertEqual(
        encoded_images.shape,					(
            1,
            self.expected_encoded_image_num_channels,
            self.image_processor_tester.size["height"],
            self.image_processor_tester.size["width"],
        ),					)

    # Test batched
    UpperCamelCase__ 						=						image_processor(a_,					return_tensors="pt"					).pixel_values
    self.assertEqual(
        encoded_images.shape,					(
            self.image_processor_tester.batch_size,
            self.expected_encoded_image_num_channels,
            self.image_processor_tester.size["height"],
            self.image_processor_tester.size["width"],
        ),					)



'''simple docstring'''

from transformers import SqueezeBertTokenizer, SqueezeBertTokenizerFast
from transformers.testing_utils import require_tokenizers, slow

from ..bert.test_tokenization_bert import BertTokenizationTest







@require_tokenizers
class  UpperCAmelCase (       SCREAMING_SNAKE_CASE__):
 _lowerCamelCase :					Optional[int]    					=					SqueezeBertTokenizer
 _lowerCamelCase :					List[Any]    					=					SqueezeBertTokenizerFast
 _lowerCamelCase :					int    					=					True

 def 		lowercase_						( self :	List[str],					**a_ :	str					):





    """simple docstring"""



    return SqueezeBertTokenizerFast.from_pretrained(self.tmpdirname,					**a_					)

 @slow
 def 		lowercase_						( self :	int					):





    """simple docstring"""



    UpperCamelCase__ 						=						SqueezeBertTokenizer.from_pretrained("squeezebert/squeezebert-mnli-headless"					)

    UpperCamelCase__ 						=						tokenizer.encode("sequence builders",					add_special_tokens=a_					)
    UpperCamelCase__ 						=						tokenizer.encode("multi-sequence build",					add_special_tokens=a_					)

    UpperCamelCase__ 						=						tokenizer.build_inputs_with_special_tokens(a_					)
    UpperCamelCase__ 						=						tokenizer.build_inputs_with_special_tokens(a_,					a_					)

    assert encoded_sentence == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]
    assert encoded_pair == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [
        tokenizer.sep_token_id
    ]