




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


_snake_case            = logging.getLogger()







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

     def       a__			(						self	,  _a	,  _a = None	,  _a = None	,  _a = None	,  _a = True	,  )		->							Any:
           _A							:  str    =		[file for file in os.listdir(_a       ) if os.path.isfile(os.path.join(_a	,  _a       )       )]

           if identifier is not None:
                 _A							:  Tuple    =		[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							:  Optional[Any]    =		[file for file in files if n_ not in file]
                 else:
                       _A							:  List[Any]    =		[file for file in files if n_identifier not in file]

           _A							:  Optional[Any]    =		ignore_files or []
           ignore_files.append("""__init__.py"""       )
           _A							:  Union[str, Any]    =		[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							:  str    =		file.split("""."""       )[0]
                       try:
                             _A							:  Union[str, Any]    =		getattr(_a	,  _a       )
                             _A							:  Dict    =		doctest.DocTestSuite(_a       )
                             _A							:  Tuple    =		unittest.TextTestRunner().run(_a       )
                             self.assertIs(len(result.failures       )	,  0       )
                       except AttributeError:
                             logger.info(F'''{module_identifier} is not a module.'''       )
                 else:
                       _A							:  Any    =		doctest.testfile(str("""..""" / directory / file       )	,  optionflags=doctest.ELLIPSIS       )
                       self.assertIs(result.failed	,  0       )

     def       a__			(						self       )		->							Optional[int]:
           _A							:  Optional[int]    =		Path("""src/transformers"""       )
           _A							:  Union[str, Any]    =		"""modeling"""
           _A							:  Optional[Any]    =		[
               """modeling_ctrl.py""",
               """modeling_tf_ctrl.py""",
           ]
           self.analyze_directory(_a	,  identifier=_a	,  ignore_files=_a       )

     def       a__			(						self       )		->							int:
           _A							:  int    =		Path("""src/transformers"""       )
           _A							:  List[str]    =		"""tokenization"""
           self.analyze_directory(_a	,  identifier=_a       )

     def       a__			(						self       )		->							Optional[int]:
           _A							:  List[str]    =		Path("""src/transformers"""       )
           _A							:  Dict    =		"""configuration"""
           self.analyze_directory(_a	,  identifier=_a       )

     def       a__			(						self       )		->							List[str]:
           _A							:  List[Any]    =		Path("""src/transformers"""       )
           _A							:  Union[str, Any]    =		["""configuration""", """modeling""", """tokenization"""]
           self.analyze_directory(_a	,  n_identifier=_a       )



     def       a__			(						self       )		->							int:
           _A							:  Optional[Any]    =		Path("""docs/source"""       )
           _A							:  int    =		["""favicon.ico"""]
           self.analyze_directory(_a	,  ignore_files=_a	,  only_modules=_a       )







from unittest import TestCase

from datasets import Sequence, Value
from datasets.arrow_dataset import Dataset







class 		lowercase							(     UpperCamelCase__	):

     def       a__			(						self       )		->							Optional[int]:
           return [
               {"col_1": 3, "col_2": "a"},
               {"col_1": 2, "col_2": "b"},
               {"col_1": 1, "col_2": "c"},
               {"col_1": 0, "col_2": "d"},
           ]

     def       a__			(						self       )		->							Optional[int]:
           _A							:  Union[str, Any]    =		{"""col_1""": [3, 2, 1, 0], """col_2""": ["""a""", """b""", """c""", """d"""]}
           return Dataset.from_dict(_a       )

     def       a__			(						self       )		->							Any:
           _A							:  str    =		self._create_example_records()
           _A							:  List[Any]    =		Dataset.from_list(_a       )
           self.assertListEqual(dset.column_names	,  ["""col_1""", """col_2"""]       )
           for i, r in enumerate(_a       ):
                 self.assertDictEqual(_a	,  example_records[i]       )

     def       a__			(						self       )		->							List[str]:
           _A							:  Dict    =		self._create_example_records()
           _A							:  List[str]    =		Dataset.from_list(_a       )
           _A							:  str    =		Dataset.from_dict({k: [r[k] for r in example_records] for k in example_records[0]}       )
           self.assertEqual(dset.info	,  dset_from_dict.info       )

     def       a__			(						self       )		->							str:  # checks what happens with missing columns
           _A							:  List[str]    =		[{"""col_1""": 1}, {"""col_2""": """x"""}]
           _A							:  List[str]    =		Dataset.from_list(_a       )
           self.assertDictEqual(dset[0]	,  {"""col_1""": 1}       )
           self.assertDictEqual(dset[1]	,  {"""col_1""": None}       )  # NB: first record is used for columns

     def       a__			(						self       )		->							Dict:  # checks if the type can be inferred from the second record
           _A							:  List[Any]    =		[{"""col_1""": []}, {"""col_1""": [1, 2]}]
           _A							:  str    =		Dataset.from_list(_a       )
           self.assertEqual(dset.info.features["""col_1"""]	,  Sequence(Value("""int64"""       )       )       )



     def       a__			(						self       )		->							Dict:
           _A							:  List[str]    =		Dataset.from_list([]       )
           self.assertEqual(len(_a       )	,  0       )
           self.assertListEqual(dset.column_names	,  []       )

