

"""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_video_inputs


if is_torch_available():
			import torch

if is_vision_available():
			from PIL import Image

			from transformers import VivitImageProcessor





class        snake_case      (							unittest.TestCase    ):

				def __init__(      self				:							List[str]	,    UpperCamelCase__				:							str	,    UpperCamelCase__				:							Tuple=7	,    UpperCamelCase__				:							str=3	,    UpperCamelCase__				:							Union[str, Any]=1_0	,    UpperCamelCase__				:							int=1_8	,    UpperCamelCase__				:							Optional[int]=3_0	,    UpperCamelCase__				:							Dict=4_0_0	,    UpperCamelCase__				:							Union[str, Any]=True	,    UpperCamelCase__				:							int=None	,    UpperCamelCase__				:							Optional[int]=True	,    UpperCamelCase__				:							str=[0.5, 0.5, 0.5]	,    UpperCamelCase__				:							Optional[Any]=[0.5, 0.5, 0.5]	,    UpperCamelCase__				:							List[Any]=None	,    )->  Optional[Any]:



						'''simple docstring'''


						__lowerCAmelCase:			Optional[Any]        =     size if size is not None else {'''shortest_edge''': 1_8}
						__lowerCAmelCase:			Union[str, Any]        =     crop_size if crop_size is not None else {'''height''': 1_8, '''width''': 1_8}

						__lowerCAmelCase:			List[Any]        =     parent
						__lowerCAmelCase:			Optional[Any]        =     batch_size
						__lowerCAmelCase:			str        =     num_channels
						__lowerCAmelCase:			Any        =     num_frames
						__lowerCAmelCase:			Any        =     image_size
						__lowerCAmelCase:			Optional[Any]        =     min_resolution
						__lowerCAmelCase:			Tuple        =     max_resolution
						__lowerCAmelCase:			Any        =     do_resize
						__lowerCAmelCase:			Optional[int]        =     size
						__lowerCAmelCase:			int        =     do_normalize
						__lowerCAmelCase:			List[str]        =     image_mean
						__lowerCAmelCase:			Union[str, Any]        =     image_std
						__lowerCAmelCase:			int        =     crop_size




				def 				lowercase_	(      self				:							int)->  Optional[int]:



						'''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_size": self.crop_size,
						}





@require_torch
@require_vision
class        snake_case      (							lowercase__,				unittest.TestCase    ):
				SCREAMING_SNAKE_CASE_  : Union[str, Any]   =    VivitImageProcessor if is_vision_available() else None

				def 				lowercase_	(      self				:							List[Any])->  int:



						'''simple docstring'''


						__lowerCAmelCase:			Optional[int]        =     VivitImageProcessingTester(self)

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



						'''simple docstring'''


						return self.image_processor_tester.prepare_image_processor_dict()

				def 				lowercase_	(      self				:							Union[str, Any])->  Tuple:



						'''simple docstring'''


						__lowerCAmelCase:			int        =     self.image_processing_class(**self.image_processor_dict)
						self.assertTrue(hasattr(UpperCAmelCase__	,    "image_mean"))
						self.assertTrue(hasattr(UpperCAmelCase__	,    "image_std"))
						self.assertTrue(hasattr(UpperCAmelCase__	,    "do_normalize"))
						self.assertTrue(hasattr(UpperCAmelCase__	,    "do_resize"))
						self.assertTrue(hasattr(UpperCAmelCase__	,    "do_center_crop"))
						self.assertTrue(hasattr(UpperCAmelCase__	,    "size"))

				def 				lowercase_	(      self				:							Optional[int])->  str:



						'''simple docstring'''


						__lowerCAmelCase:			Dict        =     self.image_processing_class.from_dict(self.image_processor_dict)
						self.assertEqual(image_processor.size	,    {"shortest_edge": 1_8})
						self.assertEqual(image_processor.crop_size	,    {"height": 1_8, "width": 1_8})

						__lowerCAmelCase:			Dict        =     self.image_processing_class.from_dict(self.image_processor_dict	,    size=4_2	,    crop_size=8_4)
						self.assertEqual(image_processor.size	,    {"shortest_edge": 4_2})
						self.assertEqual(image_processor.crop_size	,    {"height": 8_4, "width": 8_4})

				def 				lowercase_	(      self				:							int)->  List[str]:



						'''simple docstring'''


						__lowerCAmelCase:			Optional[int]        =     self.image_processing_class(**self.image_processor_dict)
						# create random PIL videos
						__lowerCAmelCase:			Tuple        =     prepare_video_inputs(self.image_processor_tester	,    equal_resolution=UpperCAmelCase__)
						for video in video_inputs:
								self.assertIsInstance(UpperCAmelCase__	,    UpperCAmelCase__)
								self.assertIsInstance(video[0]	,    Image.Image)

						# Test not batched input
						__lowerCAmelCase:			Union[str, Any]        =     image_processing(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
						__lowerCAmelCase:			Optional[int]        =     image_processing(UpperCAmelCase__	,    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 				lowercase_	(      self				:							List[str])->  int:



						'''simple docstring'''


						__lowerCAmelCase:			List[str]        =     self.image_processing_class(**self.image_processor_dict)
						# create random numpy tensors
						__lowerCAmelCase:			List[Any]        =     prepare_video_inputs(self.image_processor_tester	,    equal_resolution=UpperCAmelCase__	,    numpify=UpperCAmelCase__)
						for video in video_inputs:
								self.assertIsInstance(UpperCAmelCase__	,    UpperCAmelCase__)
								self.assertIsInstance(video[0]	,    np.ndarray)

						# Test not batched input
						__lowerCAmelCase:			Tuple        =     image_processing(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
						__lowerCAmelCase:			str        =     image_processing(UpperCAmelCase__	,    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 				lowercase_	(      self				:							Any)->  int:



						'''simple docstring'''


						__lowerCAmelCase:			Optional[Any]        =     self.image_processing_class(**self.image_processor_dict)
						# create random PyTorch tensors
						__lowerCAmelCase:			Optional[int]        =     prepare_video_inputs(self.image_processor_tester	,    equal_resolution=UpperCAmelCase__	,    torchify=UpperCAmelCase__)
						for video in video_inputs:
								self.assertIsInstance(UpperCAmelCase__	,    UpperCAmelCase__)
								self.assertIsInstance(video[0]	,    torch.Tensor)

						# Test not batched input
						__lowerCAmelCase:			str        =     image_processing(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
						__lowerCAmelCase:			Any        =     image_processing(UpperCAmelCase__	,    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"],
						    )	,    )





'''simple docstring'''





# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import doctest
import sys
import warnings
from os.path import abspath, dirname, join

import _pytest

from transformers.testing_utils import HfDoctestModule, HfDocTestParser


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
UpperCamelCase_    						=       abspath(join(dirname(__file__), """src"""))
sys.path.insert(1, git_repo_path)

# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action="""ignore""", category=FutureWarning)






def 				_lowerCAmelCase			(   __magic_name__						:     int						)				->  Tuple:
						config.addinivalue_line(
						    '''markers'''   , '''is_pt_tf_cross_test: mark test to run only when PT and TF interactions are tested'''						)
						config.addinivalue_line(
						    '''markers'''   , '''is_pt_flax_cross_test: mark test to run only when PT and FLAX interactions are tested'''						)
						config.addinivalue_line('''markers'''   , '''is_pipeline_test: mark test to run only when pipelines are tested'''						)
						config.addinivalue_line('''markers'''   , '''is_staging_test: mark test to run only in the staging environment'''						)
						config.addinivalue_line('''markers'''   , '''accelerate_tests: mark test that require accelerate'''						)
						config.addinivalue_line('''markers'''   , '''tool_tests: mark the tool tests that are run on their specific schedule'''						)






def 				_lowerCAmelCase			(   __magic_name__						:     int						)				->  Any:
						from transformers.testing_utils import pytest_addoption_shared

						pytest_addoption_shared(__magic_name__						)






def 				_lowerCAmelCase			(   __magic_name__						:     Any						)				->  Any:
						from transformers.testing_utils import pytest_terminal_summary_main

						lowercase :							Optional[Any]    		=terminalreporter.config.getoption('''--make-reports'''						)
						if make_reports:
												pytest_terminal_summary_main(__magic_name__   , id=__magic_name__						)






def 				_lowerCAmelCase			(   __magic_name__						:     Tuple   , __magic_name__						:     Union[str, Any]						)				->  List[str]:
						# If no tests are collected, pytest exists with code 5, which makes the CI fail.
						if exitstatus == 5:
												lowercase :							Optional[int]    		=0


# Doctest custom flag to ignore output.
UpperCamelCase_    						=       doctest.register_optionflag("""IGNORE_RESULT""")

UpperCamelCase_    						=       doctest.OutputChecker





class 		__SCREAMING_SNAKE_CASE							(			lowercase__      ):







				def  lowerCamelCase_	(       self     :		Optional[Any]		,					UpperCAmelCase__     :		Union[str, Any]		,					UpperCAmelCase__     :		List[Any]		,					UpperCAmelCase__     :		List[Any]   ):
										'''simple docstring'''
										if IGNORE_RESULT & optionflags:
																return True
										return OutputChecker.check_output(self		,					UpperCAmelCase__		,					UpperCAmelCase__		,					UpperCAmelCase__   )



UpperCamelCase_    						=       CustomOutputChecker
UpperCamelCase_    						=       HfDoctestModule







UpperCamelCase_    						=       HfDocTestParser





