code: 
  
  
  
  
  
  
  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 TvltImageProcessor
  
  def 			snake_case__    (					SCREAMING_SNAKE_CASE_	:					List[Any]			,  SCREAMING_SNAKE_CASE_	:					List[str]=10			,  SCREAMING_SNAKE_CASE_	:					str=10			,  SCREAMING_SNAKE_CASE_	:					int=False			,  SCREAMING_SNAKE_CASE_	:					Any=False    ):
  
  
  
       '''simple docstring'''
  
  
  
  
  
       lowercase__					:     List[Any]   = []
       for i in range(image_processor_tester.num_frames    ):
            video.append(np.random.randint(255			,  size=(image_processor_tester.num_channels, width, height)			,  dtype=np.uinta    )    )
  
       if not numpify and not torchify:
            # PIL expects the channel dimension as last dimension
            lowercase__					:     Optional[Any]   = [Image.fromarray(np.moveaxis(SCREAMING_SNAKE_CASE_			,  0			,  -1    )    ) for frame in video]
  
       if torchify:
            lowercase__					:     Optional[int]   = [torch.from_numpy(SCREAMING_SNAKE_CASE_    ) for frame in video]
  
       return video
  
  def 			snake_case__    (					SCREAMING_SNAKE_CASE_	:					int			,  SCREAMING_SNAKE_CASE_	:					Optional[Any]=False			,  SCREAMING_SNAKE_CASE_	:					Optional[int]=False			,  SCREAMING_SNAKE_CASE_	:					Optional[Any]=False    ):
  
  
  
       '''simple docstring'''
  
  
  
  
  
       assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"
  
       lowercase__					:     Optional[int]   = []
       for i in range(image_processor_tester.batch_size    ):
            if equal_resolution:
                 lowercase__					:     List[str]   = image_processor_tester.max_resolution
            else:
                 lowercase__					:     Tuple   = np.random.choice(
                     np.arange(image_processor_tester.min_resolution			,  image_processor_tester.max_resolution    )			,  2    )
                 lowercase__					:     Any   = prepare_video(
                     image_processor_tester=SCREAMING_SNAKE_CASE_			,  width=SCREAMING_SNAKE_CASE_			,  height=SCREAMING_SNAKE_CASE_			,  numpify=SCREAMING_SNAKE_CASE_			,  torchify=SCREAMING_SNAKE_CASE_			,  )
            video_inputs.append(SCREAMING_SNAKE_CASE_    )
  
       return video_inputs
  
  
  class    SCREAMING_SNAKE_CASE__      (unittest.TestCase  ):
  
  
  
  
  
      def __init__(   self		,     a		,     a=7		,     a=3		,     a=4		,     a=18		,     a=30		,     a=400		,     a=True		,     a=None		,     a=True		,     a=[0.5, 0.5, 0.5]		,     a=[0.5, 0.5, 0.5]		,     a=True		,     a=None		,     ):
           lowercase__					:     Optional[Any]   = size if size is not None else {'shortest_edge': 18}
           lowercase__					:     Tuple   = crop_size if crop_size is not None else {'height': 18, 'width': 18}
  
           lowercase__					:     str   = parent
           lowercase__					:     Any   = batch_size
           lowercase__					:     Optional[int]   = num_channels
           lowercase__					:     int   = num_frames
           lowercase__					:     List[str]   = image_size
           lowercase__					:     List[Any]   = min_resolution
           lowercase__					:     Any   = max_resolution
           lowercase__					:     Dict   = do_resize
           lowercase__					:     List[Any]   = size
           lowercase__					:     Optional[Any]   = do_normalize
           lowercase__					:     List[Any]   = image_mean
           lowercase__					:     Any   = image_std
           lowercase__					:     Dict   = do_center_crop
           lowercase__					:     Union[str, Any]   = crop_size
  
  
  
  
  
      def    snake_case_       (   self):
           return {
               "image_mean": self.image_mean,
               "image_std": self.image_std,
               "do_normalize": self.do_normalize,
               "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    SCREAMING_SNAKE_CASE__      (__snake_case	, unittest.TestCase  ):
      __lowerCamelCase		: List[Any]														=  TvltImageProcessor if is_vision_available() else None
  
  
  
  
  
      def    snake_case_       (   self):
           lowercase__					:     str   = TvltImageProcessorTester(self)
  
  
  
  
  
      @property
      def    snake_case_       (   self):
           return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
  
  
      def    snake_case_       (   self):
           lowercase__					:     List[str]   = self.image_processing_class(**self.image_processor_dict)
           self.assertTrue(hasattr(a		,     'image_mean'))
           self.assertTrue(hasattr(a		,     'image_std'))
           self.assertTrue(hasattr(a		,     'do_normalize'))
           self.assertTrue(hasattr(a		,     'do_resize'))
           self.assertTrue(hasattr(a		,     'do_center_crop'))
           self.assertTrue(hasattr(a		,     'size'))
  
  
  
  
  
      def    snake_case_       (   self):
           # Initialize image_processor
           lowercase__					:     List[str]   = self.image_processing_class(**self.image_processor_dict)
           # create random PIL videos
           lowercase__					:     Optional[int]   = prepare_video_inputs(self.image_processor_tester		,     equal_resolution=a)
           for video in video_inputs:
                self.assertIsInstance(a		,     a)
                self.assertIsInstance(video[0]		,     Image.Image)
  
           # Test not batched input
           lowercase__					:     Optional[Any]   = image_processor(video_inputs[0]		,     return_tensors='pt').pixel_values
           self.assertEqual(
               encoded_videos.shape		,     (
                   1,
                   self.image_processor_tester.num_frames,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.crop_size['height'],
                   self.image_processor_tester.crop_size['width'],
               )		,     )
  
           # Test batched
           lowercase__					:     int   = image_processor(a		,     return_tensors='pt').pixel_values
           self.assertEqual(
               encoded_videos.shape		,     (
                   self.image_processor_tester.batch_size,
                   self.image_processor_tester.num_frames,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.crop_size['height'],
                   self.image_processor_tester.crop_size['width'],
               )		,     )
  
  
  
  
  
      def    snake_case_       (   self):
           # Initialize image_processor
           lowercase__					:     List[Any]   = self.image_processing_class(**self.image_processor_dict)
           # create random numpy tensors
           lowercase__					:     Any   = prepare_video_inputs(self.image_processor_tester		,     equal_resolution=a		,     numpify=a)
           for video in video_inputs:
                self.assertIsInstance(a		,     a)
                self.assertIsInstance(video[0]		,     np.ndarray)
  
           # Test not batched input
           lowercase__					:     Dict   = image_processor(video_inputs[0]		,     return_tensors='pt').pixel_values
           self.assertEqual(
               encoded_videos.shape		,     (
                   1,
                   self.image_processor_tester.num_frames,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.crop_size['height'],
                   self.image_processor_tester.crop_size['width'],
               )		,     )
  
           # Test batched
           lowercase__					:     int   = image_processor(a		,     return_tensors='pt').pixel_values
           self.assertEqual(
               encoded_videos.shape		,     (
                   self.image_processor_tester.batch_size,
                   self.image_processor_tester.num_frames,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.crop_size['height'],
                   self.image_processor_tester.crop_size['width'],
               )		,     )
  
  
  
  
  
      def    snake_case_       (   self):
           # Initialize image_processor
           lowercase__					:     Any   = self.image_processing_class(**self.image_processor_dict)
           # create random PyTorch tensors
           lowercase__					:     int   = prepare_video_inputs(self.image_processor_tester		,     equal_resolution=a		,     torchify=a)
           for video in video_inputs:
                self.assertIsInstance(a		,     a)
                self.assertIsInstance(video[0]		,     torch.Tensor)
  
           # Test not batched input
           lowercase__					:     Optional[int]   = image_processor(video_inputs[0]		,     return_tensors='pt').pixel_values
           self.assertEqual(
               encoded_videos.shape		,     (
                   1,
                   self.image_processor_tester.num_frames,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.crop_size['height'],
                   self.image_processor_tester.crop_size['width'],
               )		,     )
  
           # Test batched
           lowercase__					:     str   = image_processor(a		,     return_tensors='pt').pixel_values
           self.assertEqual(
               encoded_videos.shape		,     (
                   self.image_processor_tester.batch_size,
                   self.image_processor_tester.num_frames,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.crop_size['height'],
                   self.image_processor_tester.crop_size['width'],
               )		,     )
  
  
style_context: 
  
  from transformers.models.cpm.tokenization_cpm import CpmTokenizer
  from transformers.testing_utils import custom_tokenizers
  
  from ..xlnet.test_modeling_xlnet import XLNetModelTest
  
  
  @custom_tokenizers
  class    SCREAMING_SNAKE_CASE__      (__snake_case  ):
  
  
  
  
  
      def    snake_case_       (   self		,     a		,     a		,     a		,     a		,     a):
           return True
  
  
  
  
  
      def    snake_case_       (   self):
           lowercase__					:     Tuple   = CpmTokenizer.from_pretrained('TsinghuaAI/CPM-Generate')
           lowercase__					:     str   = 'Hugging Face大法好，谁用谁知道。'
           lowercase__					:     Optional[int]   = 'Hugging Face大法好,谁用谁知道。<unk>'
           lowercase__					:     Any   = '▁Hu gg ing ▁ ▂ ▁F ace ▁大法 ▁好 ▁ , ▁谁 ▁用 ▁谁 ▁知 道 ▁ 。'.split()
  
           lowercase__					:     Any   = tokenizer.tokenize(a)
           self.assertListEqual(a		,     a)
  
           lowercase__					:     List[Any]   = tokens + [tokenizer.unk_token]
  
           lowercase__					:     Any   = [1_3789, 1_3283, 1421, 8, 10, 1164, 1_3608, 1_6528, 63, 8, 9, 440, 108, 440, 121, 90, 8, 12, 0]
           self.assertListEqual(tokenizer.convert_tokens_to_ids(a)		,     a)
  
           lowercase__					:     Optional[Any]   = tokenizer.decode(a)
           self.assertEqual(a		,     a)
  
  