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, prepare_image_inputs
  
  
  if is_torch_available():
  			import torch
  
  if is_vision_available():
  			from PIL import Image
  
  			from transformers import ConvNextImageProcessor
  
  class      UpperCAmelCase_						(     unittest.TestCase ):
  
  						'''simple docstring'''
  
  
  
  
  						def __init__(					self   ,							_A   ,							_A=7   ,							_A=3   ,							_A=18   ,							_A=30   ,							_A=400   ,							_A=True   ,							_A=None   ,							_A=0.8_7_5   ,							_A=True   ,							_A=[0.5, 0.5, 0.5]   ,							_A=[0.5, 0.5, 0.5]   ,							):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      size if size is not None else {'shortest_edge': 20}
  													__SCREAMING_SNAKE_CASE								=      parent
  													__SCREAMING_SNAKE_CASE								=      batch_size
  													__SCREAMING_SNAKE_CASE								=      num_channels
  													__SCREAMING_SNAKE_CASE								=      image_size
  													__SCREAMING_SNAKE_CASE								=      min_resolution
  													__SCREAMING_SNAKE_CASE								=      max_resolution
  													__SCREAMING_SNAKE_CASE								=      do_resize
  													__SCREAMING_SNAKE_CASE								=      size
  													__SCREAMING_SNAKE_CASE								=      crop_pct
  													__SCREAMING_SNAKE_CASE								=      do_normalize
  													__SCREAMING_SNAKE_CASE								=      image_mean
  													__SCREAMING_SNAKE_CASE								=      image_std
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													return {
  													    "image_mean": self.image_mean,
  													    "image_std": self.image_std,
  													    "do_normalize": self.do_normalize,
  													    "do_resize": self.do_resize,
  													    "size": self.size,
  													    "crop_pct": self.crop_pct,
  													}
  
  
  
  
  
  
  
  @require_torch
  @require_vision
  class      UpperCAmelCase_						(     UpperCamelCase_					,					unittest.TestCase ):
  
  						'''simple docstring'''
  
  
  
  
  						UpperCamelCase__    :				Union[str, Any]       						=						ConvNextImageProcessor if is_vision_available() else None
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      ConvNextImageProcessingTester(self	)
  
  
  
  
  
  
  						@property
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      self.image_processing_class(**self.image_processor_dict	)
  													self.assertTrue(hasattr(_A   ,							'do_resize'	)	)
  													self.assertTrue(hasattr(_A   ,							'size'	)	)
  													self.assertTrue(hasattr(_A   ,							'crop_pct'	)	)
  													self.assertTrue(hasattr(_A   ,							'do_normalize'	)	)
  													self.assertTrue(hasattr(_A   ,							'image_mean'	)	)
  													self.assertTrue(hasattr(_A   ,							'image_std'	)	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      self.image_processing_class.from_dict(self.image_processor_dict	)
  													self.assertEqual(image_processor.size   ,							{'shortest_edge': 20}	)
  
  													__SCREAMING_SNAKE_CASE								=      self.image_processing_class.from_dict(self.image_processor_dict   ,							size=42	)
  													self.assertEqual(image_processor.size   ,							{'shortest_edge': 42}	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													pass
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      self.image_processing_class(**self.image_processor_dict	)
  													# create random PIL images
  													__SCREAMING_SNAKE_CASE								=      prepare_image_inputs(self.image_processor_tester   ,							equal_resolution=_A	)
  													for image in image_inputs:
  																				self.assertIsInstance(_A   ,							Image.Image	)
  
  													# Test not batched input
  													__SCREAMING_SNAKE_CASE								=      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.size['shortest_edge'],
  													        self.image_processor_tester.size['shortest_edge'],
  													    )   ,							)
  
  													# Test batched
  													__SCREAMING_SNAKE_CASE								=      image_processing(_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['shortest_edge'],
  													        self.image_processor_tester.size['shortest_edge'],
  													    )   ,							)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      self.image_processing_class(**self.image_processor_dict	)
  													# create random numpy tensors
  													__SCREAMING_SNAKE_CASE								=      prepare_image_inputs(self.image_processor_tester   ,							equal_resolution=_A   ,							numpify=_A	)
  													for image in image_inputs:
  																				self.assertIsInstance(_A   ,							np.ndarray	)
  
  													# Test not batched input
  													__SCREAMING_SNAKE_CASE								=      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.size['shortest_edge'],
  													        self.image_processor_tester.size['shortest_edge'],
  													    )   ,							)
  
  													# Test batched
  													__SCREAMING_SNAKE_CASE								=      image_processing(_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['shortest_edge'],
  													        self.image_processor_tester.size['shortest_edge'],
  													    )   ,							)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      self.image_processing_class(**self.image_processor_dict	)
  													# create random PyTorch tensors
  													__SCREAMING_SNAKE_CASE								=      prepare_image_inputs(self.image_processor_tester   ,							equal_resolution=_A   ,							torchify=_A	)
  													for image in image_inputs:
  																				self.assertIsInstance(_A   ,							torch.Tensor	)
  
  													# Test not batched input
  													__SCREAMING_SNAKE_CASE								=      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.size['shortest_edge'],
  													        self.image_processor_tester.size['shortest_edge'],
  													    )   ,							)
  
  													# Test batched
  													__SCREAMING_SNAKE_CASE								=      image_processing(_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['shortest_edge'],
  													        self.image_processor_tester.size['shortest_edge'],
  													    )   ,							)
  
  
  
  
  
  
  
style_context: 
  
  
  
  import unittest
  
  from cer import CER
  
  
  lowerCAmelCase__	:  Dict 		=CER()
  
  class      UpperCAmelCase_						(     unittest.TestCase ):
  
  						'''simple docstring'''
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      ['White House']
  													__SCREAMING_SNAKE_CASE								=      ['white house']
  													# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertTrue(abs(char_error_rate - 0.1_8_1_8_1_8_1_8_1_8	) < 1e-6	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      ['were wolf']
  													__SCREAMING_SNAKE_CASE								=      ['werewolf']
  													# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertTrue(abs(char_error_rate - 0.1_1_1_1_1_1_1	) < 1e-6	)
  
  													__SCREAMING_SNAKE_CASE								=      ['werewolf']
  													__SCREAMING_SNAKE_CASE								=      ['weae     wolf']
  													# S = 1, D = 1, I = 0, N = 8, CER = 0.25
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertTrue(abs(char_error_rate - 0.2_5	) < 1e-6	)
  
  													# consecutive whitespaces case 1
  													__SCREAMING_SNAKE_CASE								=      ['were wolf']
  													__SCREAMING_SNAKE_CASE								=      ['were               wolf']
  													# S = 0, D = 0, I = 0, N = 9, CER = 0
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertTrue(abs(char_error_rate - 0.0	) < 1e-6	)
  
  													# consecutive whitespaces case 2
  													__SCREAMING_SNAKE_CASE								=      ['were   wolf']
  													__SCREAMING_SNAKE_CASE								=      ['were               wolf']
  													# S = 0, D = 0, I = 0, N = 9, CER = 0
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertTrue(abs(char_error_rate - 0.0	) < 1e-6	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      ['werewolf']
  													__SCREAMING_SNAKE_CASE								=      ['weaewolf']
  													# S = 1, D = 0, I = 0, N = 8, CER = 0.125
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertTrue(abs(char_error_rate - 0.1_2_5	) < 1e-6	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      ['werewolf']
  													__SCREAMING_SNAKE_CASE								=      ['wereawolf']
  													# S = 0, D = 1, I = 0, N = 8, CER = 0.125
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertTrue(abs(char_error_rate - 0.1_2_5	) < 1e-6	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      ['werewolf']
  													__SCREAMING_SNAKE_CASE								=      ['wereolf']
  													# S = 0, D = 0, I = 1, N = 8, CER = 0.125
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertTrue(abs(char_error_rate - 0.1_2_5	) < 1e-6	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      ['werewolf']
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertEqual(_A   ,							0.0	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      ['werewolf', 'I am your father']
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertEqual(_A   ,							0.0	)
  
  													__SCREAMING_SNAKE_CASE								=      ['werewolf', 'I am your father', 'doge']
  													__SCREAMING_SNAKE_CASE								=      ['werxwolf', 'I       am your father', 'doge']
  													# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertTrue(abs(char_error_rate - 0.0_3_5_7_1_4_2_8	) < 1e-6	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      ['My hovercraft', 'is full of eels']
  													__SCREAMING_SNAKE_CASE								=      ['My hovercraft is full', ' of eels']
  													# S = 0, D = 0, I = 2, N = 28, CER = 2 / 28
  													# whitespace at the front of " of eels" will be strip during preporcessing
  													# so need to insert 2 whitespaces
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A   ,							concatenate_texts=_A	)
  													self.assertTrue(abs(char_error_rate - 0.0_7_1_4_2_8	) < 1e-6	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      ['我能吞下玻璃而不伤身体']
  													__SCREAMING_SNAKE_CASE								=      [' 能吞虾玻璃而 不霜身体啦']
  													# S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertTrue(abs(char_error_rate - 0.4_5_4_5_4_5_4_5_4_5	) < 1e-6	)
  
  													__SCREAMING_SNAKE_CASE								=      ['我能吞下玻璃', '而不伤身体']
  													__SCREAMING_SNAKE_CASE								=      ['我    能 吞 下 玻 璃', '而不伤身体']
  													# S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertTrue(abs(char_error_rate - 0.4_5_4_5_4_5_4_5_4_5_4_5	) < 1e-6	)
  
  													__SCREAMING_SNAKE_CASE								=      ['我能吞下玻璃而不伤身体']
  													__SCREAMING_SNAKE_CASE								=      cer.compute(predictions=_A   ,							references=_A	)
  													self.assertFalse(_A   ,							0.0	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      ['']
  													__SCREAMING_SNAKE_CASE								=      ['Hypothesis']
  													with self.assertRaises(_A	):
  																				cer.compute(predictions=_A   ,							references=_A	)
  
  
  if __name__ == "__main__":
  			unittest.main()
  
  
  
  
  
  
  