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 ViltImageProcessor
  class        UpperCAmelCase__  (    unittest.TestCase):
  
  
  
   def __init__(  self		,	lowercase		,	lowercase=7		,	lowercase=3		,	lowercase=1_8		,	lowercase=3_0		,	lowercase=4_0_0		,	lowercase=True		,	lowercase=None		,	lowercase=2		,	lowercase=True		,	lowercase=[0.5, 0.5, 0.5]		,	lowercase=[0.5, 0.5, 0.5]		,	)  ->							Optional[int]:
    __UpperCamelCase				      =  size if size is not None else {"""shortest_edge""": 3_0}
    __UpperCamelCase				      =  parent
    __UpperCamelCase				      =  batch_size
    __UpperCamelCase				      =  num_channels
    __UpperCamelCase				      =  image_size
    __UpperCamelCase				      =  min_resolution
    __UpperCamelCase				      =  max_resolution
    __UpperCamelCase				      =  do_resize
    __UpperCamelCase				      =  size
    __UpperCamelCase				      =  size_divisor
    __UpperCamelCase				      =  do_normalize
    __UpperCamelCase				      =  image_mean
    __UpperCamelCase				      =  image_std
  
  
  
   def    __lowerCamelCase				(  self			)  ->							str:
    return {
        "image_mean": self.image_mean,
        "image_std": self.image_std,
        "do_normalize": self.do_normalize,
        "do_resize": self.do_resize,
        "size": self.size,
        "size_divisor": self.size_divisor,
    }
  
  
  
  
   def    __lowerCamelCase				(  self		,	lowercase		,	lowercase=False			)  ->							Dict:
    if not batched:
     __UpperCamelCase				      =  self.size["""shortest_edge"""]
     __UpperCamelCase				      =  image_inputs[0]
     if isinstance(__SCREAMING_SNAKE_CASE		,	Image.Image			):
      __UpperCamelCase      ,		__UpperCamelCase				      =  image.size
     else:
      __UpperCamelCase      ,		__UpperCamelCase				      =  image.shape[1], image.shape[2]
     __UpperCamelCase				      =  size / min(__SCREAMING_SNAKE_CASE		,	__SCREAMING_SNAKE_CASE			)
     if h < w:
      __UpperCamelCase      ,		__UpperCamelCase				      =  size, scale * w
     else:
      __UpperCamelCase      ,		__UpperCamelCase				      =  scale * h, size
  
     __UpperCamelCase				      =  int((1_3_3_3 / 8_0_0) * size			)
     if max(__SCREAMING_SNAKE_CASE		,	__SCREAMING_SNAKE_CASE			) > max_size:
      __UpperCamelCase				      =  max_size / max(__SCREAMING_SNAKE_CASE		,	__SCREAMING_SNAKE_CASE			)
      __UpperCamelCase				      =  newh * scale
      __UpperCamelCase				      =  neww * scale
  
     __UpperCamelCase      ,		__UpperCamelCase				      =  int(newh + 0.5			), int(neww + 0.5			)
     __UpperCamelCase      ,		__UpperCamelCase				      =  (
         newh // self.size_divisor * self.size_divisor,
         neww // self.size_divisor * self.size_divisor,
     )
  
    else:
     __UpperCamelCase				      =  []
     for image in image_inputs:
      __UpperCamelCase      ,		__UpperCamelCase				      =  self.get_expected_values([image]			)
      expected_values.append((expected_height, expected_width)			)
     __UpperCamelCase				      =  max(__SCREAMING_SNAKE_CASE		,	key=lambda lowercase			: item[0]			)[0]
     __UpperCamelCase				      =  max(__SCREAMING_SNAKE_CASE		,	key=lambda lowercase			: item[1]			)[1]
  
    return expected_height, expected_width
  
  
  @require_torch
  @require_vision
  class        UpperCAmelCase__  (    UpperCamelCase_							,			unittest.TestCase):
   __SCREAMING_SNAKE_CASE					      =				ViltImageProcessor if is_vision_available() else None
  
  
  
   def    __lowerCamelCase				(  self			)  ->							List[str]:
    __UpperCamelCase				      =  ViltImageProcessingTester(self			)
  
  
  
   @property
   def    __lowerCamelCase				(  self			)  ->							Tuple:
    return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
   def    __lowerCamelCase				(  self			)  ->							Union[str, Any]:
    __UpperCamelCase				      =  self.image_processing_class(**self.image_processor_dict			)
    self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE		,	"""image_mean"""			)			)
    self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE		,	"""image_std"""			)			)
    self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE		,	"""do_normalize"""			)			)
    self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE		,	"""do_resize"""			)			)
    self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE		,	"""size"""			)			)
    self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE		,	"""size_divisor"""			)			)
  
  
  
   def    __lowerCamelCase				(  self			)  ->							str:
    __UpperCamelCase				      =  self.image_processing_class.from_dict(self.image_processor_dict			)
    self.assertEqual(image_processor.size		,	{"""shortest_edge""": 3_0}			)
  
    __UpperCamelCase				      =  self.image_processing_class.from_dict(self.image_processor_dict		,	size=4_2			)
    self.assertEqual(image_processor.size		,	{"""shortest_edge""": 4_2}			)
  
  
  
   def    __lowerCamelCase				(  self			)  ->							List[str]:
    pass
  
  
  
   def    __lowerCamelCase				(  self			)  ->							Optional[Any]:
    # Initialize image_processing
    __UpperCamelCase				      =  self.image_processing_class(**self.image_processor_dict			)
    # create random PIL images
    __UpperCamelCase				      =  prepare_image_inputs(self.image_processor_tester		,	equal_resolution=__SCREAMING_SNAKE_CASE			)
    for image in image_inputs:
     self.assertIsInstance(__SCREAMING_SNAKE_CASE		,	Image.Image			)
  
    # Test not batched input
    __UpperCamelCase				      =  image_processing(image_inputs[0]		,	return_tensors="""pt"""			).pixel_values
  
    __UpperCamelCase      ,		__UpperCamelCase				      =  self.image_processor_tester.get_expected_values(__SCREAMING_SNAKE_CASE			)
    self.assertEqual(
        encoded_images.shape		,	(1, self.image_processor_tester.num_channels, expected_height, expected_width)		,	)
  
    # Test batched
    __UpperCamelCase				      =  image_processing(__SCREAMING_SNAKE_CASE		,	return_tensors="""pt"""			).pixel_values
  
    __UpperCamelCase      ,		__UpperCamelCase				      =  self.image_processor_tester.get_expected_values(__SCREAMING_SNAKE_CASE		,	batched=__SCREAMING_SNAKE_CASE			)
    self.assertEqual(
        encoded_images.shape		,	(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            expected_height,
            expected_width,
        )		,	)
  
  
  
   def    __lowerCamelCase				(  self			)  ->							Dict:
    # Initialize image_processing
    __UpperCamelCase				      =  self.image_processing_class(**self.image_processor_dict			)
    # create random numpy tensors
    __UpperCamelCase				      =  prepare_image_inputs(self.image_processor_tester		,	equal_resolution=__SCREAMING_SNAKE_CASE		,	numpify=__SCREAMING_SNAKE_CASE			)
    for image in image_inputs:
     self.assertIsInstance(__SCREAMING_SNAKE_CASE		,	np.ndarray			)
  
    # Test not batched input
    __UpperCamelCase				      =  image_processing(image_inputs[0]		,	return_tensors="""pt"""			).pixel_values
  
    __UpperCamelCase      ,		__UpperCamelCase				      =  self.image_processor_tester.get_expected_values(__SCREAMING_SNAKE_CASE			)
    self.assertEqual(
        encoded_images.shape		,	(1, self.image_processor_tester.num_channels, expected_height, expected_width)		,	)
  
    # Test batched
    __UpperCamelCase				      =  image_processing(__SCREAMING_SNAKE_CASE		,	return_tensors="""pt"""			).pixel_values
  
    __UpperCamelCase      ,		__UpperCamelCase				      =  self.image_processor_tester.get_expected_values(__SCREAMING_SNAKE_CASE		,	batched=__SCREAMING_SNAKE_CASE			)
    self.assertEqual(
        encoded_images.shape		,	(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            expected_height,
            expected_width,
        )		,	)
  
  
  
  
   def    __lowerCamelCase				(  self			)  ->							List[Any]:
    # Initialize image_processing
    __UpperCamelCase				      =  self.image_processing_class(**self.image_processor_dict			)
    # create random PyTorch tensors
    __UpperCamelCase				      =  prepare_image_inputs(self.image_processor_tester		,	equal_resolution=__SCREAMING_SNAKE_CASE		,	torchify=__SCREAMING_SNAKE_CASE			)
    for image in image_inputs:
     self.assertIsInstance(__SCREAMING_SNAKE_CASE		,	torch.Tensor			)
  
    # Test not batched input
    __UpperCamelCase				      =  image_processing(image_inputs[0]		,	return_tensors="""pt"""			).pixel_values
  
    __UpperCamelCase      ,		__UpperCamelCase				      =  self.image_processor_tester.get_expected_values(__SCREAMING_SNAKE_CASE			)
    self.assertEqual(
        encoded_images.shape		,	(1, self.image_processor_tester.num_channels, expected_height, expected_width)		,	)
  
    # Test batched
    __UpperCamelCase				      =  image_processing(__SCREAMING_SNAKE_CASE		,	return_tensors="""pt"""			).pixel_values
  
    __UpperCamelCase      ,		__UpperCamelCase				      =  self.image_processor_tester.get_expected_values(__SCREAMING_SNAKE_CASE		,	batched=__SCREAMING_SNAKE_CASE			)
    self.assertEqual(
        encoded_images.shape		,	(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            expected_height,
            expected_width,
        )		,	)
  
  
  
  
  
  
style_context: 
  
  
  
  '''simple docstring'''
  
  
  
  import textwrap
  
  import pyarrow as pa
  import pytest
  
  from datasets import Features, Image
  from datasets.packaged_modules.text.text import Text
  
  from ..utils import require_pil
  
  
  
  
  
  
  
  @pytest.fixture
  def _lowercase   (  __A       ):
  
  
  
   '''simple docstring'''
  
  
  
   __UpperCamelCase				      =  tmp_path / """text.txt"""
   __UpperCamelCase				      =  textwrap.dedent(
       """\
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
          Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
          Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
          Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  
          Second paragraph:
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
          Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
          Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
          Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
          """       )
   with open(__A							,"""w"""							,encoding="""utf-8"""       ) as f:
    f.write(__A       )
   return str(__A       )
  
  
  
  
  
  
  
  @pytest.fixture
  def _lowercase   (  __A							,__A       ):
  
  
  
   '''simple docstring'''
  
  
  
   __UpperCamelCase				      =  tmp_path / """text_with_image.txt"""
   with open(__A							,"""w"""							,encoding="""utf-8"""       ) as f:
    f.write(__A       )
   return str(__A       )
  
  
  
  
  
  
  
  @pytest.mark.parametrize("""keep_linebreaks"""							,[True, False]       )
  def _lowercase   (  __A							,__A       ):
  
  
  
   '''simple docstring'''
  
  
  
   with open(__A							,encoding="""utf-8"""       ) as f:
    __UpperCamelCase				      =  f.read().splitlines(keepends=__A       )
   __UpperCamelCase				      =  Text(keep_linebreaks=__A							,encoding="""utf-8"""       )
   __UpperCamelCase				      =  text._generate_tables([[text_file]]       )
   __UpperCamelCase				      =  pa.concat_tables([table for _, table in generator]       ).to_pydict()["""text"""]
   assert generated_content == expected_content
  
  
  
  
  
  
  
  @require_pil
  def _lowercase   (  __A       ):
  
  
  
   '''simple docstring'''
  
  
  
   with open(__A							,encoding="""utf-8"""       ) as f:
    __UpperCamelCase				      =  f.read().splitlines()[0]
   __UpperCamelCase				      =  Text(encoding="""utf-8"""							,features=Features({"""image""": Image()}       )       )
   __UpperCamelCase				      =  text._generate_tables([[text_file_with_image]]       )
   __UpperCamelCase				      =  pa.concat_tables([table for _, table in generator]       )
   assert pa_table.schema.field("""image"""       ).type == Image()()
   __UpperCamelCase				      =  pa_table.to_pydict()["""image"""]
   assert generated_content == [{"path": image_file, "bytes": None}]
  
  
  
  
  
  
  
  @pytest.mark.parametrize("""sample_by"""							,["""line""", """paragraph""", """document"""]       )
  def _lowercase   (  __A							,__A       ):
  
  
  
   '''simple docstring'''
  
  
  
   with open(__A							,encoding="""utf-8"""       ) as f:
    __UpperCamelCase				      =  f.read()
   if sample_by == "line":
    __UpperCamelCase				      =  expected_content.splitlines()
   elif sample_by == "paragraph":
    __UpperCamelCase				      =  expected_content.split("""\n\n"""       )
   elif sample_by == "document":
    __UpperCamelCase				      =  [expected_content]
   __UpperCamelCase				      =  Text(sample_by=__A							,encoding="""utf-8"""							,chunksize=100       )
   __UpperCamelCase				      =  text._generate_tables([[text_file]]       )
   __UpperCamelCase				      =  pa.concat_tables([table for _, table in generator]       ).to_pydict()["""text"""]
   assert generated_content == expected_content
  
  
  
  
  
  