


"""simple docstring"""




import pytest

from datasets.splits import SplitDict, SplitInfo
from datasets.utils.py_utils import asdict

@pytest.mark.parametrize(
    '''split_dict'''    ,					[
        SplitDict(),
        SplitDict({'''train''': SplitInfo(name='''train'''    ,					num_bytes=1337    ,					num_examples=42    ,					dataset_name='''my_dataset'''			)}			),
        SplitDict({'''train''': SplitInfo(name='''train'''    ,					num_bytes=1337    ,					num_examples=42			)}			),
        SplitDict({'''train''': SplitInfo()}			),
    ]    ,					)
def        lowercase							(		lowerCAmelCase__ :     SplitDict			) ->      List[Any]:
		__a           =			split_dict._to_yaml_list()
		assert len(lowerCAmelCase__			) == len(lowerCAmelCase__			)
		__a           =			SplitDict._from_yaml_list(lowerCAmelCase__			)
		for split_name, split_info in split_dict.items():
				# dataset_name field is deprecated, and is therefore not part of the YAML dump
				__a           =			None
				# the split name of split_dict takes over the name of the split info object
				__a           =			split_name
		assert split_dict == reloaded




@pytest.mark.parametrize(
    '''split_info'''    ,					[SplitInfo(), SplitInfo(dataset_name=lowerCAmelCase__			), SplitInfo(dataset_name='''my_dataset'''			)]			)
def        lowercase							(		lowerCAmelCase__ :     int			) ->      List[str]:
		# For backward compatibility, we need asdict(split_dict) to return split info dictrionaries with the "dataset_name"
		# field even if it's deprecated. This way old versionso of `datasets` can still reload dataset_infos.json files
		__a           =			asdict(SplitDict({'''train''': split_info}			)			)
		assert "dataset_name" in split_dict_asdict["train"]
		assert split_dict_asdict["train"]["dataset_name"] == split_info.dataset_name








'''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       )



