


import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
A			:						Tuple        =  sys.version_info >= (3, 1_0)






def 					UpperCamelCase   (      __magic_name__	:				List[Any]=None       ,       __magic_name__	:				Tuple=None	)  ->    str:
		"""simple docstring"""




		return field(default_factory=lambda: default       ,       metadata=__magic_name__	)



@dataclass
class 				A       :
					'''simple docstring'''






					A__     =					42
					A__     =					42
					A__     =					42
					A__     =					42






@dataclass
class 				A       :
					'''simple docstring'''






					A__     =					42
					A__     =					field(default='''toto'''					,    metadata={'''help''': '''help message'''}				)






@dataclass
class 				A       :
					'''simple docstring'''






					A__     =					False
					A__     =					True
					A__     =					None






class 				A       (			UpperCAmelCase__				):
					'''simple docstring'''






					A__     =					'''titi'''
					A__     =					'''toto'''






class 				A       (			UpperCAmelCase__				):
					'''simple docstring'''






					A__     =					'''titi'''
					A__     =					'''toto'''
					A__     =					42






@dataclass
class 				A       :
					'''simple docstring'''






					A__     =					"toto"

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




							"""simple docstring"""


							lowercase__	     =						BasicEnum(self.foo						)






@dataclass
class 				A       :
					'''simple docstring'''






					A__     =					"toto"

					def     lowerCamelCase__	(self       :		List[str]						)		->  Tuple:




							"""simple docstring"""


							lowercase__	     =						MixedTypeEnum(self.foo						)






@dataclass
class 				A       :
					'''simple docstring'''






					A__     =					None
					A__     =					field(default=UpperCAmelCase__					,    metadata={'''help''': '''help message'''}				)
					A__     =					None
					A__     =					list_field(default=[]				)
					A__     =					list_field(default=[]				)






@dataclass
class 				A       :
					'''simple docstring'''






					A__     =					list_field(default=[]				)
					A__     =					list_field(default=[1, 2, 3]				)
					A__     =					list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']				)
					A__     =					list_field(default=[0.1, 0.2, 0.3]				)






@dataclass
class 				A       :
					'''simple docstring'''






					A__     =					field()
					A__     =					field()
					A__     =					field()

					def     lowerCamelCase__	(self       :		Optional[Any]						)		->  Dict:




							"""simple docstring"""


							lowercase__	     =						BasicEnum(self.required_enum						)






@dataclass
class 				A       :
					'''simple docstring'''






					A__     =					42
					A__     =					field()
					A__     =					None
					A__     =					field(default='''toto'''					,    metadata={'''help''': '''help message'''}				)
					A__     =					list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']				)


if is_python_no_less_than_3_10:



	@dataclass
	class 				A       :
						'''simple docstring'''






						A__     =					False
						A__     =					True
						A__     =					None






	@dataclass
	class 				A       :
						'''simple docstring'''






						A__     =					None
						A__     =					field(default=UpperCAmelCase__					,    metadata={'''help''': '''help message'''}				)
						A__     =					None
						A__     =					list_field(default=[]				)
						A__     =					list_field(default=[]				)







class 				A       (			unittest.TestCase				):
					'''simple docstring'''






					def     lowerCamelCase__	(self       :		Any ,   _UpperCAmelCase       :		argparse.ArgumentParser ,   _UpperCAmelCase       :		argparse.ArgumentParser						)		->  int:




							"""simple docstring"""


							self.assertEqual(len(a._actions						) ,   len(b._actions						)						)
							for x, y in zip(a._actions ,   b._actions						):
									lowercase__	     =						{k: v for k, v in vars(_UpperCAmelCase						).items() if k != """container"""}
									lowercase__	     =						{k: v for k, v in vars(_UpperCAmelCase						).items() if k != """container"""}

									# Choices with mixed type have custom function as "type"
									# So we need to compare results directly for equality
									if xx.get("""choices""" ,   _UpperCAmelCase						) and yy.get("""choices""" ,   _UpperCAmelCase						):
											for expected_choice in yy["choices"] + xx["choices"]:
													self.assertEqual(xx["""type"""](_UpperCAmelCase						) ,   yy["""type"""](_UpperCAmelCase						)						)
											del xx["type"], yy["type"]

									self.assertEqual(_UpperCAmelCase ,   _UpperCAmelCase						)

					def     lowerCamelCase__	(self       :		Any						)		->  Optional[Any]:




							"""simple docstring"""


							lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)

							lowercase__	     =						argparse.ArgumentParser()
							expected.add_argument("""--foo""" ,   type=_UpperCAmelCase ,   required=_UpperCAmelCase						)
							expected.add_argument("""--bar""" ,   type=_UpperCAmelCase ,   required=_UpperCAmelCase						)
							expected.add_argument("""--baz""" ,   type=_UpperCAmelCase ,   required=_UpperCAmelCase						)
							expected.add_argument("""--flag""" ,   type=_UpperCAmelCase ,   default=_UpperCAmelCase ,   const=_UpperCAmelCase ,   nargs="""?"""						)
							self.argparsersEqual(_UpperCAmelCase ,   _UpperCAmelCase						)

							lowercase__	     =						["""--foo""", """1""", """--baz""", """quux""", """--bar""", """0.5"""]
							((lowercase__)     ,      )	     =						parser.parse_args_into_dataclasses(_UpperCAmelCase ,   look_for_args_file=_UpperCAmelCase						)
							self.assertFalse(example.flag						)

					def     lowerCamelCase__	(self       :		Optional[Any]						)		->  Any:




							"""simple docstring"""


							lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)

							lowercase__	     =						argparse.ArgumentParser()
							expected.add_argument("""--foo""" ,   default=42 ,   type=_UpperCAmelCase						)
							expected.add_argument("""--baz""" ,   default="""toto""" ,   type=_UpperCAmelCase ,   help="""help message"""						)
							self.argparsersEqual(_UpperCAmelCase ,   _UpperCAmelCase						)

					def     lowerCamelCase__	(self       :		Any						)		->  Optional[Any]:




							"""simple docstring"""


							lowercase__	     =						argparse.ArgumentParser()
							expected.add_argument("""--foo""" ,   type=_UpperCAmelCase ,   default=_UpperCAmelCase ,   const=_UpperCAmelCase ,   nargs="""?"""						)
							expected.add_argument("""--baz""" ,   type=_UpperCAmelCase ,   default=_UpperCAmelCase ,   const=_UpperCAmelCase ,   nargs="""?"""						)
							# A boolean no_* argument always has to come after its "default: True" regular counter-part
							# and its default must be set to False
							expected.add_argument("""--no_baz""" ,   action="""store_false""" ,   default=_UpperCAmelCase ,   dest="""baz"""						)
							expected.add_argument("""--opt""" ,   type=_UpperCAmelCase ,   default=_UpperCAmelCase						)

							lowercase__	     =						[WithDefaultBoolExample]
							if is_python_no_less_than_3_10:
									dataclass_types.append(_UpperCAmelCase						)

							for dataclass_type in dataclass_types:
									lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)
									self.argparsersEqual(_UpperCAmelCase ,   _UpperCAmelCase						)

									lowercase__	     =						parser.parse_args([]						)
									self.assertEqual(_UpperCAmelCase ,   Namespace(foo=_UpperCAmelCase ,   baz=_UpperCAmelCase ,   opt=_UpperCAmelCase						)						)

									lowercase__	     =						parser.parse_args(["""--foo""", """--no_baz"""]						)
									self.assertEqual(_UpperCAmelCase ,   Namespace(foo=_UpperCAmelCase ,   baz=_UpperCAmelCase ,   opt=_UpperCAmelCase						)						)

									lowercase__	     =						parser.parse_args(["""--foo""", """--baz"""]						)
									self.assertEqual(_UpperCAmelCase ,   Namespace(foo=_UpperCAmelCase ,   baz=_UpperCAmelCase ,   opt=_UpperCAmelCase						)						)

									lowercase__	     =						parser.parse_args(["""--foo""", """True""", """--baz""", """True""", """--opt""", """True"""]						)
									self.assertEqual(_UpperCAmelCase ,   Namespace(foo=_UpperCAmelCase ,   baz=_UpperCAmelCase ,   opt=_UpperCAmelCase						)						)

									lowercase__	     =						parser.parse_args(["""--foo""", """False""", """--baz""", """False""", """--opt""", """False"""]						)
									self.assertEqual(_UpperCAmelCase ,   Namespace(foo=_UpperCAmelCase ,   baz=_UpperCAmelCase ,   opt=_UpperCAmelCase						)						)

					def     lowerCamelCase__	(self       :		Tuple						)		->  Optional[int]:




							"""simple docstring"""


							lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)

							lowercase__	     =						argparse.ArgumentParser()
							expected.add_argument(
							    """--foo""" ,   default="""toto""" ,   choices=["""titi""", """toto""", 42] ,   type=make_choice_type_function(["""titi""", """toto""", 42]						) ,   )
							self.argparsersEqual(_UpperCAmelCase ,   _UpperCAmelCase						)

							lowercase__	     =						parser.parse_args([]						)
							self.assertEqual(args.foo ,   """toto"""						)
							lowercase__	     =						parser.parse_args_into_dataclasses([]						)[0]
							self.assertEqual(enum_ex.foo ,   MixedTypeEnum.toto						)

							lowercase__	     =						parser.parse_args(["""--foo""", """titi"""]						)
							self.assertEqual(args.foo ,   """titi"""						)
							lowercase__	     =						parser.parse_args_into_dataclasses(["""--foo""", """titi"""]						)[0]
							self.assertEqual(enum_ex.foo ,   MixedTypeEnum.titi						)

							lowercase__	     =						parser.parse_args(["""--foo""", """42"""]						)
							self.assertEqual(args.foo ,   42						)
							lowercase__	     =						parser.parse_args_into_dataclasses(["""--foo""", """42"""]						)[0]
							self.assertEqual(enum_ex.foo ,   MixedTypeEnum.fourtytwo						)

					def     lowerCamelCase__	(self       :		List[str]						)		->  Union[str, Any]:




							"""simple docstring"""


							@dataclass
							class 				A       :
												'''simple docstring'''






												A__     =					"toto"






							lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)

							lowercase__	     =						argparse.ArgumentParser()
							expected.add_argument(
							    """--foo""" ,   default="""toto""" ,   choices=("""titi""", """toto""", 42) ,   type=make_choice_type_function(["""titi""", """toto""", 42]						) ,   )
							self.argparsersEqual(_UpperCAmelCase ,   _UpperCAmelCase						)

							lowercase__	     =						parser.parse_args([]						)
							self.assertEqual(args.foo ,   """toto"""						)

							lowercase__	     =						parser.parse_args(["""--foo""", """titi"""]						)
							self.assertEqual(args.foo ,   """titi"""						)

							lowercase__	     =						parser.parse_args(["""--foo""", """42"""]						)
							self.assertEqual(args.foo ,   42						)

					def     lowerCamelCase__	(self       :		int						)		->  Union[str, Any]:




							"""simple docstring"""


							lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)

							lowercase__	     =						argparse.ArgumentParser()
							expected.add_argument("""--foo_int""" ,   nargs="""+""" ,   default=[] ,   type=_UpperCAmelCase						)
							expected.add_argument("""--bar_int""" ,   nargs="""+""" ,   default=[1, 2, 3] ,   type=_UpperCAmelCase						)
							expected.add_argument("""--foo_str""" ,   nargs="""+""" ,   default=["""Hallo""", """Bonjour""", """Hello"""] ,   type=_UpperCAmelCase						)
							expected.add_argument("""--foo_float""" ,   nargs="""+""" ,   default=[0.1, 0.2, 0.3] ,   type=_UpperCAmelCase						)

							self.argparsersEqual(_UpperCAmelCase ,   _UpperCAmelCase						)

							lowercase__	     =						parser.parse_args([]						)
							self.assertEqual(
							    _UpperCAmelCase ,   Namespace(foo_int=[] ,   bar_int=[1, 2, 3] ,   foo_str=["""Hallo""", """Bonjour""", """Hello"""] ,   foo_float=[0.1, 0.2, 0.3]						) ,   )

							lowercase__	     =						parser.parse_args("""--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7""".split()						)
							self.assertEqual(_UpperCAmelCase ,   Namespace(foo_int=[1] ,   bar_int=[2, 3] ,   foo_str=["""a""", """b""", """c"""] ,   foo_float=[0.1, 0.7]						)						)

					def     lowerCamelCase__	(self       :		int						)		->  str:




							"""simple docstring"""


							lowercase__	     =						argparse.ArgumentParser()
							expected.add_argument("""--foo""" ,   default=_UpperCAmelCase ,   type=_UpperCAmelCase						)
							expected.add_argument("""--bar""" ,   default=_UpperCAmelCase ,   type=_UpperCAmelCase ,   help="""help message"""						)
							expected.add_argument("""--baz""" ,   default=_UpperCAmelCase ,   type=_UpperCAmelCase						)
							expected.add_argument("""--ces""" ,   nargs="""+""" ,   default=[] ,   type=_UpperCAmelCase						)
							expected.add_argument("""--des""" ,   nargs="""+""" ,   default=[] ,   type=_UpperCAmelCase						)

							lowercase__	     =						[OptionalExample]
							if is_python_no_less_than_3_10:
									dataclass_types.append(_UpperCAmelCase						)

							for dataclass_type in dataclass_types:
									lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)

									self.argparsersEqual(_UpperCAmelCase ,   _UpperCAmelCase						)

									lowercase__	     =						parser.parse_args([]						)
									self.assertEqual(_UpperCAmelCase ,   Namespace(foo=_UpperCAmelCase ,   bar=_UpperCAmelCase ,   baz=_UpperCAmelCase ,   ces=[] ,   des=[]						)						)

									lowercase__	     =						parser.parse_args("""--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3""".split()						)
									self.assertEqual(_UpperCAmelCase ,   Namespace(foo=12 ,   bar=3.14 ,   baz="""42""" ,   ces=["""a""", """b""", """c"""] ,   des=[1, 2, 3]						)						)

					def     lowerCamelCase__	(self       :		str						)		->  Dict:




							"""simple docstring"""


							lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)

							lowercase__	     =						argparse.ArgumentParser()
							expected.add_argument("""--required_list""" ,   nargs="""+""" ,   type=_UpperCAmelCase ,   required=_UpperCAmelCase						)
							expected.add_argument("""--required_str""" ,   type=_UpperCAmelCase ,   required=_UpperCAmelCase						)
							expected.add_argument(
							    """--required_enum""" ,   type=make_choice_type_function(["""titi""", """toto"""]						) ,   choices=["""titi""", """toto"""] ,   required=_UpperCAmelCase ,   )
							self.argparsersEqual(_UpperCAmelCase ,   _UpperCAmelCase						)

					def     lowerCamelCase__	(self       :		Optional[int]						)		->  Any:




							"""simple docstring"""


							lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)

							lowercase__	     =						argparse.ArgumentParser()
							expected.add_argument("""--foo""" ,   type=_UpperCAmelCase ,   required=_UpperCAmelCase						)
							expected.add_argument(
							    """--required_enum""" ,   type=make_choice_type_function(["""titi""", """toto"""]						) ,   choices=["""titi""", """toto"""] ,   required=_UpperCAmelCase ,   )
							expected.add_argument("""--opt""" ,   type=_UpperCAmelCase ,   default=_UpperCAmelCase						)
							expected.add_argument("""--baz""" ,   default="""toto""" ,   type=_UpperCAmelCase ,   help="""help message"""						)
							expected.add_argument("""--foo_str""" ,   nargs="""+""" ,   default=["""Hallo""", """Bonjour""", """Hello"""] ,   type=_UpperCAmelCase						)
							self.argparsersEqual(_UpperCAmelCase ,   _UpperCAmelCase						)

					def     lowerCamelCase__	(self       :		Optional[Any]						)		->  Optional[int]:




							"""simple docstring"""


							lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)

							lowercase__	     =						{
							    """foo""": 12,
							    """bar""": 3.14,
							    """baz""": """42""",
							    """flag""": True,
							}

							lowercase__	     =						parser.parse_dict(_UpperCAmelCase						)[0]
							lowercase__	     =						BasicExample(**_UpperCAmelCase						)
							self.assertEqual(_UpperCAmelCase ,   _UpperCAmelCase						)

					def     lowerCamelCase__	(self       :		Optional[Any]						)		->  List[str]:




							"""simple docstring"""


							lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)

							lowercase__	     =						{
							    """foo""": 12,
							    """bar""": 3.14,
							    """baz""": """42""",
							    """flag""": True,
							    """extra""": 42,
							}

							self.assertRaises(_UpperCAmelCase ,   parser.parse_dict ,   _UpperCAmelCase ,   allow_extra_keys=_UpperCAmelCase						)

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




							"""simple docstring"""


							lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)

							lowercase__	     =						{
							    """foo""": 12,
							    """bar""": 3.14,
							    """baz""": """42""",
							    """flag""": True,
							}
							with tempfile.TemporaryDirectory() as tmp_dir:
									lowercase__	     =						os.path.join(_UpperCAmelCase ,   """temp_json"""						)
									os.mkdir(_UpperCAmelCase						)
									with open(temp_local_path + """.json""" ,   """w+"""						) as f:
											json.dump(_UpperCAmelCase ,   _UpperCAmelCase						)
									lowercase__	     =						parser.parse_yaml_file(Path(temp_local_path + """.json"""						)						)[0]

							lowercase__	     =						BasicExample(**_UpperCAmelCase						)
							self.assertEqual(_UpperCAmelCase ,   _UpperCAmelCase						)

					def     lowerCamelCase__	(self       :		int						)		->  Union[str, Any]:




							"""simple docstring"""


							lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)

							lowercase__	     =						{
							    """foo""": 12,
							    """bar""": 3.14,
							    """baz""": """42""",
							    """flag""": True,
							}
							with tempfile.TemporaryDirectory() as tmp_dir:
									lowercase__	     =						os.path.join(_UpperCAmelCase ,   """temp_yaml"""						)
									os.mkdir(_UpperCAmelCase						)
									with open(temp_local_path + """.yaml""" ,   """w+"""						) as f:
											yaml.dump(_UpperCAmelCase ,   _UpperCAmelCase						)
									lowercase__	     =						parser.parse_yaml_file(Path(temp_local_path + """.yaml"""						)						)[0]
							lowercase__	     =						BasicExample(**_UpperCAmelCase						)
							self.assertEqual(_UpperCAmelCase ,   _UpperCAmelCase						)


					def     lowerCamelCase__	(self       :		Any						)		->  List[Any]:




							"""simple docstring"""


							lowercase__	     =						HfArgumentParser(_UpperCAmelCase						)
							self.assertIsNotNone(_UpperCAmelCase						)





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 				A       (			unittest.TestCase				):
					'''simple docstring'''






					A__     =					MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING

					def     lowerCamelCase__	(self       :		List[str] ,   _UpperCAmelCase       :		List[str] ,   _UpperCAmelCase       :		Dict ,   _UpperCAmelCase       :		Tuple						)		->  Tuple:




							"""simple docstring"""


							lowercase__	     =						hf_hub_download(
							    repo_id="""nateraw/video-demo""" ,   filename="""archery.mp4""" ,   repo_type="""dataset"""						)
							lowercase__	     =						VideoClassificationPipeline(model=_UpperCAmelCase ,   image_processor=_UpperCAmelCase ,   top_k=2						)
							lowercase__	     =						[
							    example_video_filepath,
							    """https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4""",
							]
							return video_classifier, examples

					def     lowerCamelCase__	(self       :		List[str] ,   _UpperCAmelCase       :		Union[str, Any] ,   _UpperCAmelCase       :		Tuple						)		->  List[Any]:




							"""simple docstring"""


							for example in examples:
									lowercase__	     =						video_classifier(_UpperCAmelCase						)

									self.assertEqual(
									    _UpperCAmelCase ,   [
									        {"""score""": ANY(_UpperCAmelCase						), """label""": ANY(_UpperCAmelCase						)},
									        {"""score""": ANY(_UpperCAmelCase						), """label""": ANY(_UpperCAmelCase						)},
									    ] ,   )

					@require_torch
					def     lowerCamelCase__	(self       :		str						)		->  List[Any]:




							"""simple docstring"""


							lowercase__	     =						"""hf-internal-testing/tiny-random-VideoMAEForVideoClassification"""
							lowercase__	     =						VideoMAEFeatureExtractor(
							    size={"""shortest_edge""": 10} ,   crop_size={"""height""": 10, """width""": 10}						)
							lowercase__	     =						pipeline(
							    """video-classification""" ,   model=_UpperCAmelCase ,   feature_extractor=_UpperCAmelCase ,   frame_sampling_rate=4						)

							lowercase__	     =						hf_hub_download(repo_id="""nateraw/video-demo""" ,   filename="""archery.mp4""" ,   repo_type="""dataset"""						)
							lowercase__	     =						video_classifier(_UpperCAmelCase ,   top_k=2						)
							self.assertEqual(
							    nested_simplify(_UpperCAmelCase ,   decimals=4						) ,   [{"""score""": 0.5_199, """label""": """LABEL_0"""}, {"""score""": 0.4_801, """label""": """LABEL_1"""}] ,   )

							lowercase__	     =						video_classifier(
							    [
							        video_file_path,
							        video_file_path,
							    ] ,   top_k=2 ,   )
							self.assertEqual(
							    nested_simplify(_UpperCAmelCase ,   decimals=4						) ,   [
							        [{"""score""": 0.5_199, """label""": """LABEL_0"""}, {"""score""": 0.4_801, """label""": """LABEL_1"""}],
							        [{"""score""": 0.5_199, """label""": """LABEL_0"""}, {"""score""": 0.4_801, """label""": """LABEL_1"""}],
							    ] ,   )


					@require_tf
					def     lowerCamelCase__	(self       :		Any						)		->  Union[str, Any]:




							"""simple docstring"""


							pass

