





"""simple docstring"""





import os

import pytest

from datasets import (
    get_dataset_config_info,
    get_dataset_config_names,
    get_dataset_infos,
    get_dataset_split_names,
    inspect_dataset,
    inspect_metric,
)


_UpperCamelCase					      =   pytest.mark.integration



@pytest.mark.parametrize('''path'''     ,    ['''paws''', '''csv'''] )
def 					lowerCAmelCase_      (   SCREAMING_SNAKE_CASE							:				List[str]     ,    SCREAMING_SNAKE_CASE							:				List[Any] ):


							'''simple docstring'''







							inspect_dataset(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE )
							__lowerCamelCase   :   Any       =path + '''.py'''
							assert script_name in os.listdir(SCREAMING_SNAKE_CASE )
							assert "__pycache__" not in os.listdir(SCREAMING_SNAKE_CASE )



@pytest.mark.filterwarnings('''ignore:inspect_metric is deprecated:FutureWarning''' )
@pytest.mark.filterwarnings('''ignore:metric_module_factory is deprecated:FutureWarning''' )
@pytest.mark.parametrize('''path'''     ,    ['''accuracy'''] )
def 					lowerCAmelCase_      (   SCREAMING_SNAKE_CASE							:				List[Any]     ,    SCREAMING_SNAKE_CASE							:				Optional[int] ):


							'''simple docstring'''







							inspect_metric(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE )
							__lowerCamelCase   :   str       =path + '''.py'''
							assert script_name in os.listdir(SCREAMING_SNAKE_CASE )
							assert "__pycache__" not in os.listdir(SCREAMING_SNAKE_CASE )



@pytest.mark.parametrize(
    '''path, config_name, expected_splits'''     ,    [
        ('''squad''', '''plain_text''', ['''train''', '''validation''']),
        ('''dalle-mini/wit''', '''dalle-mini--wit''', ['''train''']),
        ('''paws''', '''labeled_final''', ['''train''', '''test''', '''validation''']),
    ]     ,    )
def 					lowerCAmelCase_      (   SCREAMING_SNAKE_CASE							:				int     ,    SCREAMING_SNAKE_CASE							:				List[str]     ,    SCREAMING_SNAKE_CASE							:				Any ):


							'''simple docstring'''







							__lowerCamelCase   :   List[str]       =get_dataset_config_info(SCREAMING_SNAKE_CASE     ,    config_name=SCREAMING_SNAKE_CASE )
							assert info.config_name == config_name
							assert list(info.splits.keys() ) == expected_splits



@pytest.mark.parametrize(
    '''path, config_name, expected_exception'''     ,    [
        ('''paws''', None, ValueError),
    ]     ,    )
def 					lowerCAmelCase_      (   SCREAMING_SNAKE_CASE							:				str     ,    SCREAMING_SNAKE_CASE							:				Any     ,    SCREAMING_SNAKE_CASE							:				Optional[int] ):


							'''simple docstring'''







							with pytest.raises(SCREAMING_SNAKE_CASE ):
														get_dataset_config_info(SCREAMING_SNAKE_CASE     ,    config_name=SCREAMING_SNAKE_CASE )



@pytest.mark.parametrize(
    '''path, expected'''     ,    [
        ('''squad''', '''plain_text'''),
        ('''acronym_identification''', '''default'''),
        ('''lhoestq/squad''', '''plain_text'''),
        ('''lhoestq/test''', '''default'''),
        ('''lhoestq/demo1''', '''lhoestq--demo1'''),
        ('''dalle-mini/wit''', '''dalle-mini--wit'''),
    ]     ,    )
def 					lowerCAmelCase_      (   SCREAMING_SNAKE_CASE							:				Dict     ,    SCREAMING_SNAKE_CASE							:				Any ):


							'''simple docstring'''







							__lowerCamelCase   :   Any       =get_dataset_config_names(SCREAMING_SNAKE_CASE )
							assert expected in config_names



@pytest.mark.parametrize(
    '''path, expected_configs, expected_splits_in_first_config'''     ,    [
        ('''squad''', ['''plain_text'''], ['''train''', '''validation''']),
        ('''dalle-mini/wit''', ['''dalle-mini--wit'''], ['''train''']),
        ('''paws''', ['''labeled_final''', '''labeled_swap''', '''unlabeled_final'''], ['''train''', '''test''', '''validation''']),
    ]     ,    )
def 					lowerCAmelCase_      (   SCREAMING_SNAKE_CASE							:				List[Any]     ,    SCREAMING_SNAKE_CASE							:				List[Any]     ,    SCREAMING_SNAKE_CASE							:				List[Any] ):


							'''simple docstring'''







							__lowerCamelCase   :   Optional[int]       =get_dataset_infos(SCREAMING_SNAKE_CASE )
							assert list(infos.keys() ) == expected_configs
							__lowerCamelCase   :   int       =expected_configs[0]
							assert expected_config in infos
							__lowerCamelCase   :   Optional[int]       =infos[expected_config]
							assert info.config_name == expected_config
							assert list(info.splits.keys() ) == expected_splits_in_first_config



@pytest.mark.parametrize(
    '''path, expected_config, expected_splits'''     ,    [
        ('''squad''', '''plain_text''', ['''train''', '''validation''']),
        ('''dalle-mini/wit''', '''dalle-mini--wit''', ['''train''']),
        ('''paws''', '''labeled_final''', ['''train''', '''test''', '''validation''']),
    ]     ,    )
def 					lowerCAmelCase_      (   SCREAMING_SNAKE_CASE							:				Union[str, Any]     ,    SCREAMING_SNAKE_CASE							:				Tuple     ,    SCREAMING_SNAKE_CASE							:				Union[str, Any] ):


							'''simple docstring'''







							__lowerCamelCase   :   int       =get_dataset_infos(SCREAMING_SNAKE_CASE )
							assert expected_config in infos
							__lowerCamelCase   :   Tuple       =infos[expected_config]
							assert info.config_name == expected_config
							assert list(info.splits.keys() ) == expected_splits



@pytest.mark.parametrize(
    '''path, config_name, expected_exception'''     ,    [
        ('''paws''', None, ValueError),
    ]     ,    )
def 					lowerCAmelCase_      (   SCREAMING_SNAKE_CASE							:				Dict     ,    SCREAMING_SNAKE_CASE							:				Tuple     ,    SCREAMING_SNAKE_CASE							:				Union[str, Any] ):


							'''simple docstring'''







							with pytest.raises(SCREAMING_SNAKE_CASE ):
														get_dataset_split_names(SCREAMING_SNAKE_CASE     ,    config_name=SCREAMING_SNAKE_CASE )











"""simple docstring"""





import contextlib
import importlib
import io
import unittest

import transformers

# Try to import everything from transformers to ensure every object can be loaded.
from transformers import *  # noqa F406
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, require_tf, require_torch
from transformers.utils import ContextManagers, find_labels, is_flax_available, is_tf_available, is_torch_available


if is_torch_available():
							from transformers import BertForPreTraining, BertForQuestionAnswering, BertForSequenceClassification

if is_tf_available():
							from transformers import TFBertForPreTraining, TFBertForQuestionAnswering, TFBertForSequenceClassification

if is_flax_available():
							from transformers import FlaxBertForPreTraining, FlaxBertForQuestionAnswering, FlaxBertForSequenceClassification


_UpperCamelCase					      =   DUMMY_UNKNOWN_IDENTIFIER
# An actual model hosted on huggingface.co

_UpperCamelCase					      =   'main'
# Default branch name
_UpperCamelCase					      =   'f2c752cfc5c0ab6f4bdec59acea69eefbee381c2'
# One particular commit (not the top of `main`)
_UpperCamelCase					      =   'aaaaaaa'
# This commit does not exist, so we should 404.

_UpperCamelCase					      =   'd9e9f15bc825e4b2c9249e9578f884bbcb5e3684'
# Sha-1 of config.json on the top of `main`, for checking purposes
_UpperCamelCase					      =   '4b243c475af8d0a7754e87d7d096c92e5199ec2fe168a2ee7998e3b8e9bcb1d3'



@contextlib.contextmanager
def 					lowerCAmelCase_      (   ):


							'''simple docstring'''







							print('''Welcome!''' )
							yield
							print('''Bye!''' )



@contextlib.contextmanager
def 					lowerCAmelCase_      (   ):


							'''simple docstring'''







							print('''Bonjour!''' )
							yield
							print('''Au revoir!''' )
class 		SCREAMING_SNAKE_CASE_				(     unittest.TestCase ):
				"""simple docstring"""




				def        __lowercase	(  self	:str      ):
											# If the spec is missing, importlib would not be able to import the module dynamically.
											assert transformers.__spec__ is not None
											assert importlib.util.find_spec('''transformers'''      ) is not None

class 		SCREAMING_SNAKE_CASE_				(     unittest.TestCase ):
				"""simple docstring"""




				@unittest.mock.patch('''sys.stdout'''    ,     new_callable=io.StringIO      )
				def        __lowercase	(  self	:str    ,     __lowercase	:str      ):
											with ContextManagers([]      ):
																		print('''Transformers are awesome!'''      )
											# The print statement adds a new line at the end of the output
											self.assertEqual(mock_stdout.getvalue()    ,     '''Transformers are awesome!\n'''      )




				@unittest.mock.patch('''sys.stdout'''    ,     new_callable=io.StringIO      )
				def        __lowercase	(  self	:Any    ,     __lowercase	:Tuple      ):
											with ContextManagers([context_en()]      ):
																		print('''Transformers are awesome!'''      )
											# The output should be wrapped with an English welcome and goodbye
											self.assertEqual(mock_stdout.getvalue()    ,     '''Welcome!\nTransformers are awesome!\nBye!\n'''      )




				@unittest.mock.patch('''sys.stdout'''    ,     new_callable=io.StringIO      )
				def        __lowercase	(  self	:List[Any]    ,     __lowercase	:Optional[Any]      ):
											with ContextManagers([context_fr(), context_en()]      ):
																		print('''Transformers are awesome!'''      )
											# The output should be wrapped with an English and French welcome and goodbye
											self.assertEqual(mock_stdout.getvalue()    ,     '''Bonjour!\nWelcome!\nTransformers are awesome!\nBye!\nAu revoir!\n'''      )




				@require_torch
				def        __lowercase	(  self	:Tuple      ):
											self.assertEqual(find_labels(__lowercase      )    ,     ['''labels''']      )
											self.assertEqual(find_labels(__lowercase      )    ,     ['''labels''', '''next_sentence_label''']      )
											self.assertEqual(find_labels(__lowercase      )    ,     ['''start_positions''', '''end_positions''']      )
											class 		SCREAMING_SNAKE_CASE_				(     snake_case__ ):
															"""simple docstring"""
															pass

											self.assertEqual(find_labels(__lowercase      )    ,     ['''labels''']      )




				@require_tf
				def        __lowercase	(  self	:str      ):
											self.assertEqual(find_labels(__lowercase      )    ,     ['''labels''']      )
											self.assertEqual(find_labels(__lowercase      )    ,     ['''labels''', '''next_sentence_label''']      )
											self.assertEqual(find_labels(__lowercase      )    ,     ['''start_positions''', '''end_positions''']      )
											class 		SCREAMING_SNAKE_CASE_				(     snake_case__ ):
															"""simple docstring"""
															pass

											self.assertEqual(find_labels(__lowercase      )    ,     ['''labels''']      )




				@require_flax
				def        __lowercase	(  self	:str      ):
											# Flax models don't have labels
											self.assertEqual(find_labels(__lowercase      )    ,     []      )
											self.assertEqual(find_labels(__lowercase      )    ,     []      )
											self.assertEqual(find_labels(__lowercase      )    ,     []      )
											class 		SCREAMING_SNAKE_CASE_				(     snake_case__ ):
															"""simple docstring"""
															pass

											self.assertEqual(find_labels(__lowercase      )    ,     []      )




