



'''simple docstring'''





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
lowercase_									=    sys.version_info >= (3, 10)




def lowerCAmelCase    (__A=None    ,      __A=None):



     """simple docstring"""



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






@dataclass
class __A     :



 '''simple docstring'''







 __lowerCamelCase       :			int
 __lowerCamelCase       :			float
 __lowerCamelCase       :			str
 __lowerCamelCase       :			bool






@dataclass
class __A     :



 '''simple docstring'''







 __lowerCamelCase       :			int		=			42
 __lowerCamelCase       :			str		=			field(default='toto'  ,  metadata={'help': 'help message'}		)






@dataclass
class __A     :



 '''simple docstring'''







 __lowerCamelCase       :			bool		=			False
 __lowerCamelCase       :			bool		=			True
 __lowerCamelCase       :			Optional[bool]		=			None






class __A     (    A		):



 '''simple docstring'''







 __lowerCamelCase       :			Dict		=			'titi'
 __lowerCamelCase       :			Union[str, Any]		=			'toto'






class __A     (    A		):



 '''simple docstring'''







 __lowerCamelCase       :			Tuple		=			'titi'
 __lowerCamelCase       :			Union[str, Any]		=			'toto'
 __lowerCamelCase       :			Optional[int]		=			42






@dataclass
class __A     :



 '''simple docstring'''







 __lowerCamelCase       :			BasicEnum		=			"toto"



 def    a__    (self			)       ->	Dict:


      """simple docstring"""



      _a           =    BasicEnum(self.foo			)






@dataclass
class __A     :



 '''simple docstring'''







 __lowerCamelCase       :			MixedTypeEnum		=			"toto"



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


      """simple docstring"""



      _a           =    MixedTypeEnum(self.foo			)






@dataclass
class __A     :



 '''simple docstring'''







 __lowerCamelCase       :			Optional[int]		=			None
 __lowerCamelCase       :			Optional[float]		=			field(default=A  ,  metadata={'help': 'help message'}		)
 __lowerCamelCase       :			Optional[str]		=			None
 __lowerCamelCase       :			Optional[List[str]]		=			list_field(default=[]		)
 __lowerCamelCase       :			Optional[List[int]]		=			list_field(default=[]		)






@dataclass
class __A     :



 '''simple docstring'''







 __lowerCamelCase       :			List[int]		=			list_field(default=[]		)
 __lowerCamelCase       :			List[int]		=			list_field(default=[1, 2, 3]		)
 __lowerCamelCase       :			List[str]		=			list_field(default=['Hallo', 'Bonjour', 'Hello']		)
 __lowerCamelCase       :			List[float]		=			list_field(default=[0.1, 0.2, 0.3]		)






@dataclass
class __A     :



 '''simple docstring'''







 __lowerCamelCase       :			List[int]		=			field()
 __lowerCamelCase       :			str		=			field()
 __lowerCamelCase       :			BasicEnum		=			field()



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


      """simple docstring"""



      _a           =    BasicEnum(self.required_enum			)






@dataclass
class __A     :



 '''simple docstring'''







 __lowerCamelCase       :			int
 __lowerCamelCase       :			"BasicEnum"		=			field()
 __lowerCamelCase       :			"Optional[bool]"		=			None
 __lowerCamelCase       :			"str"		=			field(default='toto'  ,  metadata={'help': 'help message'}		)
 __lowerCamelCase       :			"List[str]"		=			list_field(default=['Hallo', 'Bonjour', 'Hello']		)


if is_python_no_less_than_3_10:






  @dataclass
  class __A     :



   '''simple docstring'''







   __lowerCamelCase       :			bool		=			False
   __lowerCamelCase       :			bool		=			True
   __lowerCamelCase       :			bool | None		=			None






  @dataclass
  class __A     :



   '''simple docstring'''







   __lowerCamelCase       :			int | None		=			None
   __lowerCamelCase       :			float | None		=			field(default=A  ,  metadata={'help': 'help message'}		)
   __lowerCamelCase       :			str | None		=			None
   __lowerCamelCase       :			list[str] | None		=			list_field(default=[]		)
   __lowerCamelCase       :			list[int] | None		=			list_field(default=[]		)






class __A     (    unittest.TestCase		):



 '''simple docstring'''







 def    a__    (self					,  A					,  A			)       ->	List[Any]:


      """simple docstring"""



      self.assertEqual(len(a._actions			)					,  len(b._actions			)			)
      for x, y in zip(a._actions					,  b._actions			):
           _a           =    {k: v for k, v in vars(A			).items() if k != '''container'''}
           _a           =    {k: v for k, v in vars(A			).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'''					,  A			) and yy.get('''choices'''					,  A			):
                for expected_choice in yy["choices"] + xx["choices"]:
                     self.assertEqual(xx['''type'''](A			)					,  yy['''type'''](A			)			)
                del xx["type"], yy["type"]

           self.assertEqual(A					,  A			)



 def    a__    (self			)       ->	Tuple:


      """simple docstring"""



      _a           =    HfArgumentParser(A			)

      _a           =    argparse.ArgumentParser()
      expected.add_argument('''--foo'''					,  type=A					,  required=A			)
      expected.add_argument('''--bar'''					,  type=A					,  required=A			)
      expected.add_argument('''--baz'''					,  type=A					,  required=A			)
      expected.add_argument('''--flag'''					,  type=A					,  default=A					,  const=A					,  nargs='''?'''			)
      self.argparsersEqual(A					,  A			)

      _a           =    ['''--foo''', '''1''', '''--baz''', '''quux''', '''--bar''', '''0.5''']
      ((_a)    ,       )           =    parser.parse_args_into_dataclasses(A					,  look_for_args_file=A			)
      self.assertFalse(example.flag			)



 def    a__    (self			)       ->	Any:


      """simple docstring"""



      _a           =    HfArgumentParser(A			)

      _a           =    argparse.ArgumentParser()
      expected.add_argument('''--foo'''					,  default=42					,  type=A			)
      expected.add_argument('''--baz'''					,  default='''toto'''					,  type=A					,  help='''help message'''			)
      self.argparsersEqual(A					,  A			)



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


      """simple docstring"""



      _a           =    argparse.ArgumentParser()
      expected.add_argument('''--foo'''					,  type=A					,  default=A					,  const=A					,  nargs='''?'''			)
      expected.add_argument('''--baz'''					,  type=A					,  default=A					,  const=A					,  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=A					,  dest='''baz'''			)
      expected.add_argument('''--opt'''					,  type=A					,  default=A			)

      _a           =    [WithDefaultBoolExample]
      if is_python_no_less_than_3_10:
           dataclass_types.append(A			)

      for dataclass_type in dataclass_types:
           _a           =    HfArgumentParser(A			)
           self.argparsersEqual(A					,  A			)

           _a           =    parser.parse_args([]			)
           self.assertEqual(A					,  Namespace(foo=A					,  baz=A					,  opt=A			)			)

           _a           =    parser.parse_args(['''--foo''', '''--no_baz''']			)
           self.assertEqual(A					,  Namespace(foo=A					,  baz=A					,  opt=A			)			)

           _a           =    parser.parse_args(['''--foo''', '''--baz''']			)
           self.assertEqual(A					,  Namespace(foo=A					,  baz=A					,  opt=A			)			)

           _a           =    parser.parse_args(['''--foo''', '''True''', '''--baz''', '''True''', '''--opt''', '''True''']			)
           self.assertEqual(A					,  Namespace(foo=A					,  baz=A					,  opt=A			)			)

           _a           =    parser.parse_args(['''--foo''', '''False''', '''--baz''', '''False''', '''--opt''', '''False''']			)
           self.assertEqual(A					,  Namespace(foo=A					,  baz=A					,  opt=A			)			)



 def    a__    (self			)       ->	Dict:


      """simple docstring"""



      _a           =    HfArgumentParser(A			)

      _a           =    argparse.ArgumentParser()
      expected.add_argument(
          '''--foo'''					,  default='''toto'''					,  choices=['''titi''', '''toto''', 42]					,  type=make_choice_type_function(['''titi''', '''toto''', 42]			)					,  )
      self.argparsersEqual(A					,  A			)

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

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

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



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


      """simple docstring"""



      @dataclass
      class __A     :



       '''simple docstring'''







       __lowerCamelCase       :			Literal["titi", "toto", 42]		=			"toto"





      _a           =    HfArgumentParser(A			)

      _a           =    argparse.ArgumentParser()
      expected.add_argument(
          '''--foo'''					,  default='''toto'''					,  choices=('''titi''', '''toto''', 42)					,  type=make_choice_type_function(['''titi''', '''toto''', 42]			)					,  )
      self.argparsersEqual(A					,  A			)

      _a           =    parser.parse_args([]			)
      self.assertEqual(args.foo					,  '''toto'''			)

      _a           =    parser.parse_args(['''--foo''', '''titi''']			)
      self.assertEqual(args.foo					,  '''titi'''			)

      _a           =    parser.parse_args(['''--foo''', '''42''']			)
      self.assertEqual(args.foo					,  42			)



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


      """simple docstring"""



      _a           =    HfArgumentParser(A			)

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

      self.argparsersEqual(A					,  A			)

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

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



 def    a__    (self			)       ->	Tuple:


      """simple docstring"""



      _a           =    argparse.ArgumentParser()
      expected.add_argument('''--foo'''					,  default=A					,  type=A			)
      expected.add_argument('''--bar'''					,  default=A					,  type=A					,  help='''help message'''			)
      expected.add_argument('''--baz'''					,  default=A					,  type=A			)
      expected.add_argument('''--ces'''					,  nargs='''+'''					,  default=[]					,  type=A			)
      expected.add_argument('''--des'''					,  nargs='''+'''					,  default=[]					,  type=A			)

      _a           =    [OptionalExample]
      if is_python_no_less_than_3_10:
           dataclass_types.append(A			)

      for dataclass_type in dataclass_types:
           _a           =    HfArgumentParser(A			)

           self.argparsersEqual(A					,  A			)

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

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



 def    a__    (self			)       ->	Dict:


      """simple docstring"""



      _a           =    HfArgumentParser(A			)

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



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


      """simple docstring"""



      _a           =    HfArgumentParser(A			)

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



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


      """simple docstring"""



      _a           =    HfArgumentParser(A			)

      _a           =    {
          '''foo''': 12,
          '''bar''': 3.14,
          '''baz''': '''42''',
          '''flag''': True,
      }

      _a           =    parser.parse_dict(A			)[0]
      _a           =    BasicExample(**A			)
      self.assertEqual(A					,  A			)



 def    a__    (self			)       ->	str:


      """simple docstring"""



      _a           =    HfArgumentParser(A			)

      _a           =    {
          '''foo''': 12,
          '''bar''': 3.14,
          '''baz''': '''42''',
          '''flag''': True,
          '''extra''': 42,
      }

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



 def    a__    (self			)       ->	Any:


      """simple docstring"""



      _a           =    HfArgumentParser(A			)

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

      _a           =    BasicExample(**A			)
      self.assertEqual(A					,  A			)



 def    a__    (self			)       ->	Tuple:


      """simple docstring"""



      _a           =    HfArgumentParser(A			)

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



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


      """simple docstring"""



      _a           =    HfArgumentParser(A			)
      self.assertIsNotNone(A			)








'''simple docstring'''





import unittest

import numpy as np

from transformers.file_utils import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision

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 DPTImageProcessor






class __A     (    unittest.TestCase		):



 '''simple docstring'''







 def __init__(self					,  A					,  A=7					,  A=3					,  A=18					,  A=30					,  A=400					,  A=True					,  A=None					,  A=True					,  A=[0.5, 0.5, 0.5]					,  A=[0.5, 0.5, 0.5]					,  )       ->	str:


      """simple docstring"""



      _a           =    size if size is not None else {'''height''': 18, '''width''': 18}
      _a           =    parent
      _a           =    batch_size
      _a           =    num_channels
      _a           =    image_size
      _a           =    min_resolution
      _a           =    max_resolution
      _a           =    do_resize
      _a           =    size
      _a           =    do_normalize
      _a           =    image_mean
      _a           =    image_std



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


      """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,
      }






@require_torch
@require_vision
class __A     (    A  ,  unittest.TestCase		):



 '''simple docstring'''







 __lowerCamelCase       :			str		=			DPTImageProcessor if is_vision_available() else None



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


      """simple docstring"""



      _a           =    DPTImageProcessingTester(self			)



 @property
 def    a__    (self			)       ->	int:


      """simple docstring"""



      return self.image_processor_tester.prepare_image_processor_dict()



 def    a__    (self			)       ->	Dict:


      """simple docstring"""



      _a           =    self.image_processing_class(**self.image_processor_dict			)
      self.assertTrue(hasattr(A					,  '''image_mean'''			)			)
      self.assertTrue(hasattr(A					,  '''image_std'''			)			)
      self.assertTrue(hasattr(A					,  '''do_normalize'''			)			)
      self.assertTrue(hasattr(A					,  '''do_resize'''			)			)
      self.assertTrue(hasattr(A					,  '''size'''			)			)



 def    a__    (self			)       ->	Any:


      """simple docstring"""



      _a           =    self.image_processing_class.from_dict(self.image_processor_dict			)
      self.assertEqual(image_processor.size					,  {'''height''': 18, '''width''': 18}			)

      _a           =    self.image_processing_class.from_dict(self.image_processor_dict					,  size=42			)
      self.assertEqual(image_processor.size					,  {'''height''': 42, '''width''': 42}			)



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


      """simple docstring"""



      _a           =    self.image_processing_class(**self.image_processor_dict			)
      # create random PIL images
      _a           =    prepare_image_inputs(self.image_processor_tester					,  equal_resolution=A			)
      for image in image_inputs:
           self.assertIsInstance(A					,  Image.Image			)

      # Test not batched input
      _a           =    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['''height'''],
              self.image_processor_tester.size['''width'''],
          )					,  )

      # Test batched
      _a           =    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['''height'''],
              self.image_processor_tester.size['''width'''],
          )					,  )



 def    a__    (self			)       ->	str:


      """simple docstring"""



      _a           =    self.image_processing_class(**self.image_processor_dict			)
      # create random numpy tensors
      _a           =    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
      _a           =    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['''height'''],
              self.image_processor_tester.size['''width'''],
          )					,  )

      # Test batched
      _a           =    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['''height'''],
              self.image_processor_tester.size['''width'''],
          )					,  )



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


      """simple docstring"""



      _a           =    self.image_processing_class(**self.image_processor_dict			)
      # create random PyTorch tensors
      _a           =    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
      _a           =    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['''height'''],
              self.image_processor_tester.size['''width'''],
          )					,  )

      # Test batched
      _a           =    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['''height'''],
              self.image_processor_tester.size['''width'''],
          )					,  )



