"""simple docstring"""
from copy import deepcopy
from unittest.case import TestCase

import pytest

from datasets.arrow_dataset import Dataset
from datasets.features import Audio, ClassLabel, Features, Image, Sequence, Value
from datasets.info import DatasetInfo
from datasets.tasks import (
    AudioClassification,
    AutomaticSpeechRecognition,
    ImageClassification,
    LanguageModeling,
    QuestionAnsweringExtractive,
    Summarization,
    TextClassification,
    task_template_from_dict,
)
from datasets.utils.py_utils import asdict


lowercase__   			=      {
    'id': '5733be284776f41900661182',
    'title': 'University_of_Notre_Dame',
    'context': 'Architecturally, the school has a Catholic character. Atop the Main Building\'s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend "Venite Ad Me Omnes". Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome), is a simple, modern stone statue of Mary.',
    'question': 'To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?',
    'answers': {'text': ['Saint Bernadette Soubirous'], 'answer_start': [515]},
}







@pytest.mark.parametrize(
    'task_cls'						,	[
        AudioClassification,
        AutomaticSpeechRecognition,
        ImageClassification,
        LanguageModeling,
        QuestionAnsweringExtractive,
        Summarization,
        TextClassification,
    ]						,	)
def 		__a  (      _SCREAMING_SNAKE_CASE  )      ->Union[str, Any]:
  a__:	List[str]     				=      task_cls()
  a__:	Tuple     				=      asdict(_SCREAMING_SNAKE_CASE  )
  a__:	int     				=      task_template_from_dict(_SCREAMING_SNAKE_CASE  )
  assert task == reloaded




class   __snake_case			:



      def     lowerCamelCase_  (		self)      ->     str:





        '''simple docstring'''





        a__:	Union[str, Any]     				=      LanguageModeling(text_column='input_text')
        assert {"input_text": "text"} == task.column_mapping



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





        '''simple docstring'''





        a__:	List[str]     				=      Features({'text': Value('string')})
        a__:	Optional[int]     				=      {'text_column': 'input_text'}
        a__:	Tuple     				=      LanguageModeling.from_dict(_SCREAMING_SNAKE_CASE)
        assert "language-modeling" == task.task
        assert input_schema == task.input_schema







class   __snake_case			(	snake_case__							):



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





        '''simple docstring'''





        a__:	Optional[int]     				=      sorted(['pos', 'neg'])



      def     lowerCamelCase_  (		self)      ->     str:





        '''simple docstring'''





        a__:	int     				=      TextClassification(text_column='input_text'       ,     label_column='input_label')
        self.assertDictEqual({'input_text': 'text', 'input_label': 'labels'}       ,     task.column_mapping)



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





        '''simple docstring'''





        a__:	List[str]     				=      Features({'text': Value('string')})
        # Labels are cast to tuple during `TextClassification.__post_init__`, so we do the same here
        a__:	List[str]     				=      Features({'labels': ClassLabel})
        a__:	Any     				=      {'text_column': 'input_text', 'label_column': 'input_labels'}
        a__:	Dict     				=      TextClassification.from_dict(_SCREAMING_SNAKE_CASE)
        self.assertEqual('text-classification'       ,     task.task)
        self.assertEqual(_SCREAMING_SNAKE_CASE       ,     task.input_schema)
        self.assertEqual(_SCREAMING_SNAKE_CASE       ,     task.label_schema)



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





        '''simple docstring'''





        a__:	str     				=      TextClassification(text_column='input_text'       ,     label_column='input_label')
        self.assertEqual(task.label_schema['labels']       ,     _SCREAMING_SNAKE_CASE)
        a__:	int     				=      task.align_with_features(Features({'input_label': ClassLabel(names=self.labels)}))
        self.assertEqual(task.label_schema['labels']       ,     ClassLabel(names=self.labels))







class   __snake_case			(	snake_case__							):



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





        '''simple docstring'''





        a__:	Any     				=      QuestionAnsweringExtractive(
            context_column='input_context'       ,     question_column='input_question'       ,     answers_column='input_answers')
        self.assertDictEqual(
            {'input_context': 'context', 'input_question': 'question', 'input_answers': 'answers'}       ,     task.column_mapping)



      def     lowerCamelCase_  (		self)      ->     Any:





        '''simple docstring'''





        a__:	List[str]     				=      Features({'question': Value('string'), 'context': Value('string')})
        a__:	Dict     				=      Features(
            {
                'answers': Sequence(
                    {
                        'text': Value('string'),
                        'answer_start': Value('int32'),
                    })
            })
        a__:	Union[str, Any]     				=      {
            'context_column': 'input_input_context',
            'question_column': 'input_question',
            'answers_column': 'input_answers',
        }
        a__:	Tuple     				=      QuestionAnsweringExtractive.from_dict(_SCREAMING_SNAKE_CASE)
        self.assertEqual('question-answering-extractive'       ,     task.task)
        self.assertEqual(_SCREAMING_SNAKE_CASE       ,     task.input_schema)
        self.assertEqual(_SCREAMING_SNAKE_CASE       ,     task.label_schema)







class   __snake_case			(	snake_case__							):



      def     lowerCamelCase_  (		self)      ->     Dict:





        '''simple docstring'''





        a__:	int     				=      Summarization(text_column='input_text'       ,     summary_column='input_summary')
        self.assertDictEqual({'input_text': 'text', 'input_summary': 'summary'}       ,     task.column_mapping)



      def     lowerCamelCase_  (		self)      ->     Dict:





        '''simple docstring'''





        a__:	List[Any]     				=      Features({'text': Value('string')})
        a__:	Optional[Any]     				=      Features({'summary': Value('string')})
        a__:	Dict     				=      {'text_column': 'input_text', 'summary_column': 'input_summary'}
        a__:	List[Any]     				=      Summarization.from_dict(_SCREAMING_SNAKE_CASE)
        self.assertEqual('summarization'       ,     task.task)
        self.assertEqual(_SCREAMING_SNAKE_CASE       ,     task.input_schema)
        self.assertEqual(_SCREAMING_SNAKE_CASE       ,     task.label_schema)







class   __snake_case			(	snake_case__							):



      def     lowerCamelCase_  (		self)      ->     List[str]:





        '''simple docstring'''





        a__:	Tuple     				=      AutomaticSpeechRecognition(audio_column='input_audio'       ,     transcription_column='input_transcription')
        self.assertDictEqual({'input_audio': 'audio', 'input_transcription': 'transcription'}       ,     task.column_mapping)



      def     lowerCamelCase_  (		self)      ->     Any:





        '''simple docstring'''





        a__:	Tuple     				=      Features({'audio': Audio()})
        a__:	List[Any]     				=      Features({'transcription': Value('string')})
        a__:	Union[str, Any]     				=      {
            'audio_column': 'input_audio',
            'transcription_column': 'input_transcription',
        }
        a__:	str     				=      AutomaticSpeechRecognition.from_dict(_SCREAMING_SNAKE_CASE)
        self.assertEqual('automatic-speech-recognition'       ,     task.task)
        self.assertEqual(_SCREAMING_SNAKE_CASE       ,     task.input_schema)
        self.assertEqual(_SCREAMING_SNAKE_CASE       ,     task.label_schema)







class   __snake_case			(	snake_case__							):



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





        '''simple docstring'''





        a__:	Dict     				=      sorted(['pos', 'neg'])



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





        '''simple docstring'''





        a__:	int     				=      AudioClassification(audio_column='input_audio'       ,     label_column='input_label')
        self.assertDictEqual({'input_audio': 'audio', 'input_label': 'labels'}       ,     task.column_mapping)



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





        '''simple docstring'''





        a__:	Dict     				=      Features({'audio': Audio()})
        a__:	Any     				=      Features({'labels': ClassLabel})
        a__:	List[str]     				=      {
            'audio_column': 'input_image',
            'label_column': 'input_label',
        }
        a__:	Tuple     				=      AudioClassification.from_dict(_SCREAMING_SNAKE_CASE)
        self.assertEqual('audio-classification'       ,     task.task)
        self.assertEqual(_SCREAMING_SNAKE_CASE       ,     task.input_schema)
        self.assertEqual(_SCREAMING_SNAKE_CASE       ,     task.label_schema)



      def     lowerCamelCase_  (		self)      ->     List[str]:





        '''simple docstring'''





        a__:	int     				=      AudioClassification(audio_column='input_audio'       ,     label_column='input_label')
        self.assertEqual(task.label_schema['labels']       ,     _SCREAMING_SNAKE_CASE)
        a__:	Any     				=      task.align_with_features(Features({'input_label': ClassLabel(names=self.labels)}))
        self.assertEqual(task.label_schema['labels']       ,     ClassLabel(names=self.labels))







class   __snake_case			(	snake_case__							):



      def     lowerCamelCase_  (		self)      ->     List[str]:





        '''simple docstring'''





        a__:	Dict     				=      sorted(['pos', 'neg'])



      def     lowerCamelCase_  (		self)      ->     Dict:





        '''simple docstring'''





        a__:	Union[str, Any]     				=      ImageClassification(image_column='input_image'       ,     label_column='input_label')
        self.assertDictEqual({'input_image': 'image', 'input_label': 'labels'}       ,     task.column_mapping)



      def     lowerCamelCase_  (		self)      ->     List[str]:





        '''simple docstring'''





        a__:	Optional[int]     				=      Features({'image': Image()})
        a__:	Any     				=      Features({'labels': ClassLabel})
        a__:	List[str]     				=      {
            'image_column': 'input_image',
            'label_column': 'input_label',
        }
        a__:	Tuple     				=      ImageClassification.from_dict(_SCREAMING_SNAKE_CASE)
        self.assertEqual('image-classification'       ,     task.task)
        self.assertEqual(_SCREAMING_SNAKE_CASE       ,     task.input_schema)
        self.assertEqual(_SCREAMING_SNAKE_CASE       ,     task.label_schema)



      def     lowerCamelCase_  (		self)      ->     int:





        '''simple docstring'''





        a__:	Optional[Any]     				=      ImageClassification(image_column='input_image'       ,     label_column='input_label')
        self.assertEqual(task.label_schema['labels']       ,     _SCREAMING_SNAKE_CASE)
        a__:	str     				=      task.align_with_features(Features({'input_label': ClassLabel(names=self.labels)}))
        self.assertEqual(task.label_schema['labels']       ,     ClassLabel(names=self.labels))







class   __snake_case			(	snake_case__							):



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





        '''simple docstring'''





        a__:	int     				=      DatasetInfo(task_templates=QuestionAnsweringExtractive())
        a__:	Union[str, Any]     				=      Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()}       ,     info=_SCREAMING_SNAKE_CASE)
        assert isinstance(dataset.info.task_templates       ,     _SCREAMING_SNAKE_CASE)
        assert len(dataset.info.task_templates) == 1

        def keep_task(lowercase):
          return x

        def dont_keep_task(lowercase):
          a__:	Optional[Any]     				=      deepcopy(_SCREAMING_SNAKE_CASE)
          a__:	List[Any]     				=      0
          return out

        a__:	List[str]     				=      dataset.map(_SCREAMING_SNAKE_CASE)
        assert mapped_dataset.info.task_templates == dataset.info.task_templates
        # reload from cache
        a__:	Tuple     				=      dataset.map(_SCREAMING_SNAKE_CASE)
        assert mapped_dataset.info.task_templates == dataset.info.task_templates

        a__:	int     				=      dataset.map(_SCREAMING_SNAKE_CASE)
        assert mapped_dataset.info.task_templates == []
        # reload from cache
        a__:	Tuple     				=      dataset.map(_SCREAMING_SNAKE_CASE)
        assert mapped_dataset.info.task_templates == []



      def     lowerCamelCase_  (		self)      ->     Dict:





        '''simple docstring'''





        a__:	Any     				=      Features({'text': Value('string'), 'label': ClassLabel(names=('pos', 'neg'))})
        a__:	Any     				=      TextClassification(text_column='text'       ,     label_column='label')
        a__:	Optional[Any]     				=      DatasetInfo(features=_SCREAMING_SNAKE_CASE       ,     task_templates=_SCREAMING_SNAKE_CASE)
        a__:	Dict     				=      Dataset.from_dict({'text': ['A sentence.'], 'label': ['pos']}       ,     info=_SCREAMING_SNAKE_CASE)

        def process(lowercase):
          return example

        a__:	Optional[int]     				=      dataset.remove_columns('label')
        a__:	Optional[int]     				=      modified_dataset.map(_SCREAMING_SNAKE_CASE)
        assert mapped_dataset.info.task_templates == []










import hashlib
import importlib.util
import json
import os
import pathlib
from types import ModuleType

import pytest
import requests

lowerCAmelCase_     =			pathlib.Path.cwd().joinpath('project_euler')
lowerCAmelCase_     =			pathlib.Path.cwd().joinpath(
    'scripts', 'project_euler_answers.json'
)

with open(PROJECT_EULER_ANSWERS_PATH) as file_handle:
					lowerCAmelCase_     =			json.load(file_handle)







def   snake_case		(				UpperCAmelCase						:							pathlib.Path ):
				A									=   importlib.util.spec_from_file_location(file_path.name,    str(UpperCAmelCase ) )
				A									=   importlib.util.module_from_spec(UpperCAmelCase )  # type: ignore
				spec.loader.exec_module(UpperCAmelCase )  # type: ignore
				return module







def   snake_case		(				):
				A									=   []
				for problem_dir_path in PROJECT_EULER_DIR_PATH.iterdir():
								if problem_dir_path.is_file() or problem_dir_path.name.startswith('_' ):
												continue
								for file_path in problem_dir_path.iterdir():
												if file_path.suffix != ".py" or file_path.name.startswith(('_', 'test') ):
																continue
												solution_file_paths.append(UpperCAmelCase )
				return solution_file_paths







def   snake_case		(				):
				with open(os.environ['GITHUB_EVENT_PATH'] ) as file:
								A									=   json.load(UpperCAmelCase )
				return event["pull_request"]["url"] + "/files"







def   snake_case		(				):
				A									=   []
				A									=   {
				    'Accept': 'application/vnd.github.v3+json',
				    'Authorization': 'token ' + os.environ['GITHUB_TOKEN'],
				}
				A									=   requests.get(get_files_url(),    headers=UpperCAmelCase ).json()
				for file in files:
								A									=   pathlib.Path.cwd().joinpath(file['filename'] )
								if (
								    filepath.suffix != ".py"
								    or filepath.name.startswith(('_', 'test') )
								    or not filepath.name.startswith('sol' )
								):
												continue
								solution_file_paths.append(UpperCAmelCase )
				return solution_file_paths







def   snake_case		(				):
				if os.environ.get('CI' ) and os.environ.get('GITHUB_EVENT_NAME' ) == "pull_request":
								# Return only if there are any, otherwise default to all solutions
								if filepaths := added_solution_file_path():
												return filepaths
				return all_solution_file_paths()







@pytest.mark.parametrize(
    'solution_path',    collect_solution_file_paths(),    ids=lambda UpperCAmelCase : f'{path.parent.name}/{path.name}',    )
def   snake_case		(				UpperCAmelCase						:							pathlib.Path ):
				A									=   solution_path.parent.name[8:].zfill(3 )
				A									=   PROBLEM_ANSWERS[problem_number]
				A									=   convert_path_to_module(UpperCAmelCase )
				A									=   str(solution_module.solution() )  # type: ignore
				A									=   hashlib.shaaaa(answer.encode() ).hexdigest()
				assert (
				    answer == expected
				), f'Expected solution to {problem_number} to have hash {expected}, got {answer}'





