




# 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       UpperCAmelCase       (     _snake_case							):
							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       UpperCAmelCase       (     _snake_case							):
							from transformers.testing_utils import pytest_addoption_shared

							pytest_addoption_shared(_snake_case							)



def       UpperCAmelCase       (     _snake_case							):
							from transformers.testing_utils import pytest_terminal_summary_main

							lowerCAmelCase   =		terminalreporter.config.getoption('''--make-reports'''							)
							if make_reports:
														pytest_terminal_summary_main(_snake_case						, id=_snake_case							)



def       UpperCAmelCase       (     _snake_case						, _snake_case							):
							# If no tests are collected, pytest exists with code 5, which makes the CI fail.
							if exitstatus == 5:
														lowerCAmelCase   =		0


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

UpperCAmelCase_						=doctest.OutputChecker


class 							__UpperCamelCase			( __UpperCAmelCase  ):





				'''simple docstring'''



				def       __snake_case		( self       , UpperCAmelCase_       , UpperCAmelCase_       , UpperCAmelCase_						):
											if IGNORE_RESULT & optionflags:
																		return True
											return OutputChecker.check_output(self       , UpperCAmelCase_       , UpperCAmelCase_       , UpperCAmelCase_						)




UpperCAmelCase_						=CustomOutputChecker
UpperCAmelCase_						=HfDoctestModule

UpperCAmelCase_						=HfDocTestParser









import unittest

from huggingface_hub import hf_hub_download

from transformers import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING, VideoMAEFeatureExtractor
from transformers.pipelines import VideoClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_decord,
    require_tf,
    require_torch,
    require_torch_or_tf,
    require_vision,
)

from .test_pipelines_common import ANY


@is_pipeline_test
@require_torch_or_tf
@require_vision
@require_decord
class 							__UpperCamelCase			( unittest.TestCase  ):





				'''simple docstring'''



				__a							: str										=MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING



				def       __snake_case		( self       , UpperCAmelCase_       , UpperCAmelCase_       , UpperCAmelCase_						):
											lowerCAmelCase   =		hf_hub_download(
											    repo_id='''nateraw/video-demo'''       , filename='''archery.mp4'''       , repo_type='''dataset'''						)
											lowerCAmelCase   =		VideoClassificationPipeline(model=UpperCAmelCase_       , image_processor=UpperCAmelCase_       , top_k=2						)
											lowerCAmelCase   =		[
											    example_video_filepath,
											    '''https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4''',
											]
											return video_classifier, examples



				def       __snake_case		( self       , UpperCAmelCase_       , UpperCAmelCase_						):
											for example in examples:
																		lowerCAmelCase   =		video_classifier(UpperCAmelCase_						)

																		self.assertEqual(
																		    UpperCAmelCase_       , [
																		        {'''score''': ANY(UpperCAmelCase_						), '''label''': ANY(UpperCAmelCase_						)},
																		        {'''score''': ANY(UpperCAmelCase_						), '''label''': ANY(UpperCAmelCase_						)},
																		    ]       , )



				@require_torch
				def       __snake_case		( self						):
											lowerCAmelCase   =		'''hf-internal-testing/tiny-random-VideoMAEForVideoClassification'''
											lowerCAmelCase   =		VideoMAEFeatureExtractor(
											    size={'''shortest_edge''': 10}       , crop_size={'''height''': 10, '''width''': 10}						)
											lowerCAmelCase   =		pipeline(
											    '''video-classification'''       , model=UpperCAmelCase_       , feature_extractor=UpperCAmelCase_       , frame_sampling_rate=4						)

											lowerCAmelCase   =		hf_hub_download(repo_id='''nateraw/video-demo'''       , filename='''archery.mp4'''       , repo_type='''dataset'''						)
											lowerCAmelCase   =		video_classifier(UpperCAmelCase_       , top_k=2						)
											self.assertEqual(
											    nested_simplify(UpperCAmelCase_       , decimals=4						)       , [{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}]       , )

											lowerCAmelCase   =		video_classifier(
											    [
											        video_file_path,
											        video_file_path,
											    ]       , top_k=2       , )
											self.assertEqual(
											    nested_simplify(UpperCAmelCase_       , decimals=4						)       , [
											        [{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}],
											        [{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}],
											    ]       , )






				@require_tf
				def       __snake_case		( self						):
											pass



