
'''simple docstring'''







import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import is_speech_available, is_vision_available
from transformers.testing_utils import require_torch


if is_vision_available():
  from transformers import TvltImageProcessor

if is_speech_available():
  from transformers import TvltFeatureExtractor

from transformers import TvltProcessor







@require_torch
class UpperCAmelCase__	( unittest.TestCase	):





  """simple docstring"""

  def   __lowercase		(		self      :     Tuple       ):


     '''simple docstring'''






     _a				:	str			=   'ZinengTang/tvlt-base'
     _a				:	Optional[Any]			=   tempfile.mkdtemp()


  def   __lowercase		(		self      :     List[str]							,**_a      :     int       ):


     '''simple docstring'''






     return TvltImageProcessor.from_pretrained(self.checkpoint							,**_a       )


  def   __lowercase		(		self      :     List[str]							,**_a      :     Optional[Any]       ):


     '''simple docstring'''






     return TvltFeatureExtractor.from_pretrained(self.checkpoint							,**_a       )


  def   __lowercase		(		self      :     List[Any]       ):


     '''simple docstring'''






     shutil.rmtree(self.tmpdirname       )


  def   __lowercase		(		self      :     Union[str, Any]       ):


     '''simple docstring'''






     _a				:	int			=   self.get_image_processor()
     _a				:	Optional[Any]			=   self.get_feature_extractor()

     _a				:	Any			=   TvltProcessor(image_processor=_a							,feature_extractor=_a       )
     processor.save_pretrained(self.tmpdirname       )
     _a				:	Any			=   TvltProcessor.from_pretrained(self.tmpdirname       )

     self.assertIsInstance(processor.feature_extractor							,_a       )
     self.assertIsInstance(processor.image_processor							,_a       )


  def   __lowercase		(		self      :     Tuple       ):


     '''simple docstring'''






     _a				:	str			=   self.get_image_processor()
     _a				:	Any			=   self.get_feature_extractor()

     _a				:	List[str]			=   TvltProcessor(image_processor=_a							,feature_extractor=_a       )

     _a				:	Tuple			=   np.ones([1_2000]       )

     _a				:	Optional[Any]			=   feature_extractor(_a							,return_tensors='np'       )
     _a				:	str			=   processor(audio=_a							,return_tensors='np'       )

     for key in audio_dict.keys():
        self.assertAlmostEqual(audio_dict[key].sum()							,input_processor[key].sum()							,delta=1E-2       )


  def   __lowercase		(		self      :     str       ):


     '''simple docstring'''






     _a				:	Tuple			=   self.get_image_processor()
     _a				:	Tuple			=   self.get_feature_extractor()

     _a				:	List[str]			=   TvltProcessor(image_processor=_a							,feature_extractor=_a       )

     _a				:	Dict			=   np.ones([3, 224, 224]       )

     _a				:	List[str]			=   image_processor(_a							,return_tensors='np'       )
     _a				:	Tuple			=   processor(images=_a							,return_tensors='np'       )

     for key in image_dict.keys():
        self.assertAlmostEqual(image_dict[key].sum()							,input_processor[key].sum()							,delta=1E-2       )


  def   __lowercase		(		self      :     Optional[int]       ):


     '''simple docstring'''






     _a				:	int			=   self.get_image_processor()
     _a				:	List[str]			=   self.get_feature_extractor()

     _a				:	Optional[Any]			=   TvltProcessor(image_processor=_a							,feature_extractor=_a       )

     _a				:	int			=   np.ones([1_2000]       )
     _a				:	int			=   np.ones([3, 224, 224]       )

     _a				:	str			=   processor(audio=_a							,images=_a       )

     self.assertListEqual(list(inputs.keys()       )							,['audio_values', 'audio_mask', 'pixel_values', 'pixel_mask']       )

     # test if it raises when no input is passed
     with pytest.raises(_a       ):
        processor()


  def   __lowercase		(		self      :     Optional[Any]       ):


     '''simple docstring'''






     _a				:	int			=   self.get_image_processor()
     _a				:	Tuple			=   self.get_feature_extractor()

     _a				:	str			=   TvltProcessor(image_processor=_a							,feature_extractor=_a       )

     self.assertListEqual(
         processor.model_input_names							,image_processor.model_input_names + feature_extractor.model_input_names							,msg='`processor` and `image_processor`+`feature_extractor` model input names do not match'							,)





'''simple docstring'''







import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


__lowerCAmelCase         =    logging.getLogger()







@unittest.skip('''Temporarily disable the doc tests.'''	)
@require_torch
@require_tf
@slow
class UpperCAmelCase__	( unittest.TestCase	):





  """simple docstring"""

  def   __lowercase		(		self      :     str							,_a      :     Path							,_a      :     Union[str, None] = None							,_a      :     Union[List[str], None] = None							,_a      :     Union[str, List[str], None] = None							,_a      :     bool = True							,):


     '''simple docstring'''






     _a				:	Optional[int]			=   [file for file in os.listdir(_a       ) if os.path.isfile(os.path.join(_a							,_a       )       )]

     if identifier is not None:
        _a				:	List[str]			=   [file for file in files if identifier in file]

     if n_identifier is not None:
        if isinstance(_a							,_a       ):
           for n_ in n_identifier:
              _a				:	Tuple			=   [file for file in files if n_ not in file]
        else:
           _a				:	Optional[Any]			=   [file for file in files if n_identifier not in file]

     _a				:	List[str]			=   ignore_files or []
     ignore_files.append('__init__.py'       )
     _a				:	Tuple			=   [file for file in files if file not in ignore_files]

     for file in files:
        # Open all files
        print('Testing'							,_a       )

        if only_modules:
           _a				:	Any			=   file.split('.'       )[0]
           try:
              _a				:	List[str]			=   getattr(_a							,_a       )
              _a				:	int			=   doctest.DocTestSuite(_a       )
              _a				:	Any			=   unittest.TextTestRunner().run(_a       )
              self.assertIs(len(result.failures       )							,0       )
           except AttributeError:
              logger.info(F"""{module_identifier} is not a module."""       )
        else:
           _a				:	Union[str, Any]			=   doctest.testfile(str('..' / directory / file       )							,optionflags=doctest.ELLIPSIS       )
           self.assertIs(result.failed							,0       )


  def   __lowercase		(		self      :     Any       ):


     '''simple docstring'''






     _a				:	int			=   Path('src/transformers'       )
     _a				:	List[Any]			=   'modeling'
     _a				:	Optional[Any]			=   [
         'modeling_ctrl.py',
         'modeling_tf_ctrl.py',
     ]
     self.analyze_directory(_a							,identifier=_a							,ignore_files=_a       )


  def   __lowercase		(		self      :     Optional[int]       ):


     '''simple docstring'''






     _a				:	Optional[Any]			=   Path('src/transformers'       )
     _a				:	Optional[Any]			=   'tokenization'
     self.analyze_directory(_a							,identifier=_a       )


  def   __lowercase		(		self      :     List[str]       ):


     '''simple docstring'''






     _a				:	Dict			=   Path('src/transformers'       )
     _a				:	str			=   'configuration'
     self.analyze_directory(_a							,identifier=_a       )


  def   __lowercase		(		self      :     Any       ):


     '''simple docstring'''






     _a				:	Tuple			=   Path('src/transformers'       )
     _a				:	List[Any]			=   ['configuration', 'modeling', 'tokenization']
     self.analyze_directory(_a							,n_identifier=_a       )


  def   __lowercase		(		self      :     Tuple       ):


     '''simple docstring'''






     _a				:	List[Any]			=   Path('docs/source'       )
     _a				:	List[str]			=   ['favicon.ico']
     self.analyze_directory(_a							,ignore_files=_a							,only_modules=_a       )



