





'''simple docstring'''

import json
import os
from pathlib import Path

import pytest

from datasets.download.download_config import DownloadConfig
from datasets.download.download_manager import DownloadManager
from datasets.utils.file_utils import hash_url_to_filename


lowercase__		:     str			=							'http://www.mocksite.com/file1.txt'
lowercase__		:     Union[str, Any]			=							'"text": ["foo", "foo"]'
lowercase__		:     str			=							'6d8ce9aa78a471c7477201efbeabd3bb01ac2e7d100a6dc024ba1608361f90a8'
class 							__lowerCAmelCase	:






       """simple docstring"""
       _snake_case      :	str									=       2_0_0
       _snake_case      :	Any									=       {'Content-Length': '100'}
       _snake_case      :	Dict									=       {}





       def snake_case__		(				self  :						Tuple			,					**lowerCAmelCase__  :						str	)       ->	Tuple:

            '''simple docstring'''




            return [bytes(lowerCAmelCase__			,					'''utf-8'''	)]







def    a__							(							*lowercase   :	List[str],   **lowercase   :	List[Any] )						->						Tuple:





     """simple docstring"""

     return MockResponse()







@pytest.mark.parametrize('''urls_type''',   [str, list, dict] )
def    a__							(							lowercase   :	Dict,   lowercase   :	str,   lowercase   :	Any )						->						str:





     """simple docstring"""

     import requests

     monkeypatch.setattr(lowercase,   '''request''',   lowercase )

     _UpperCamelCase							       =			URL
     if issubclass(lowercase,   lowercase ):
          _UpperCamelCase							       =			url
     elif issubclass(lowercase,   lowercase ):
          _UpperCamelCase							       =			[url]
     elif issubclass(lowercase,   lowercase ):
          _UpperCamelCase							       =			{'''train''': url}
     _UpperCamelCase							       =			'''dummy'''
     _UpperCamelCase							       =			'''downloads'''
     _UpperCamelCase							       =			tmp_path
     _UpperCamelCase							       =			DownloadConfig(
         cache_dir=os.path.join(lowercase,   lowercase ),   use_etag=lowercase,   )
     _UpperCamelCase							       =			DownloadManager(dataset_name=lowercase,   download_config=lowercase )
     _UpperCamelCase							       =			dl_manager.download(lowercase )
     _UpperCamelCase							       =			urls
     for downloaded_paths in [downloaded_paths]:
          if isinstance(lowercase,   lowercase ):
               _UpperCamelCase							       =			[downloaded_paths]
               _UpperCamelCase							       =			[urls]
          elif isinstance(lowercase,   lowercase ):
               assert "train" in downloaded_paths.keys()
               _UpperCamelCase							       =			downloaded_paths.values()
               _UpperCamelCase							       =			urls.values()
          assert downloaded_paths
          for downloaded_path, input_url in zip(lowercase,   lowercase ):
               assert downloaded_path == dl_manager.downloaded_paths[input_url]
               _UpperCamelCase							       =			Path(lowercase )
               _UpperCamelCase							       =			downloaded_path.parts
               assert parts[-1] == HASH
               assert parts[-2] == cache_subdir
               assert downloaded_path.exists()
               _UpperCamelCase							       =			downloaded_path.read_text()
               assert content == CONTENT
               _UpperCamelCase							       =			downloaded_path.with_suffix('''.json''' )
               assert metadata_downloaded_path.exists()
               _UpperCamelCase							       =			json.loads(metadata_downloaded_path.read_text() )
               assert metadata_content == {"url": URL, "etag": None}







@pytest.mark.parametrize('''paths_type''',   [str, list, dict] )
def    a__							(							lowercase   :	int,   lowercase   :	Union[str, Any],   lowercase   :	List[Any] )						->						Any:





     """simple docstring"""

     _UpperCamelCase							       =			str(lowercase )
     if issubclass(lowercase,   lowercase ):
          _UpperCamelCase							       =			filename
     elif issubclass(lowercase,   lowercase ):
          _UpperCamelCase							       =			[filename]
     elif issubclass(lowercase,   lowercase ):
          _UpperCamelCase							       =			{'''train''': filename}
     _UpperCamelCase							       =			'''dummy'''
     _UpperCamelCase							       =			xz_file.parent
     _UpperCamelCase							       =			'''extracted'''
     _UpperCamelCase							       =			DownloadConfig(
         cache_dir=lowercase,   use_etag=lowercase,   )
     _UpperCamelCase							       =			DownloadManager(dataset_name=lowercase,   download_config=lowercase )
     _UpperCamelCase							       =			dl_manager.extract(lowercase )
     _UpperCamelCase							       =			paths
     for extracted_paths in [extracted_paths]:
          if isinstance(lowercase,   lowercase ):
               _UpperCamelCase							       =			[extracted_paths]
               _UpperCamelCase							       =			[paths]
          elif isinstance(lowercase,   lowercase ):
               assert "train" in extracted_paths.keys()
               _UpperCamelCase							       =			extracted_paths.values()
               _UpperCamelCase							       =			paths.values()
          assert extracted_paths
          for extracted_path, input_path in zip(lowercase,   lowercase ):
               assert extracted_path == dl_manager.extracted_paths[input_path]
               _UpperCamelCase							       =			Path(lowercase )
               _UpperCamelCase							       =			extracted_path.parts
               assert parts[-1] == hash_url_to_filename(lowercase,   etag=lowercase )
               assert parts[-2] == extracted_subdir
               assert extracted_path.exists()
               _UpperCamelCase							       =			extracted_path.read_text()
               _UpperCamelCase							       =			text_file.read_text()
               assert extracted_file_content == expected_file_content







def    a__							(							lowercase   :	Tuple,   lowercase   :	Tuple )						->						Tuple:





     """simple docstring"""

     assert path.endswith('''.jsonl''' )
     for num_items, line in enumerate(lowercase,   start=1 ):
          _UpperCamelCase							       =			json.loads(line.decode('''utf-8''' ) )
          assert item.keys() == {"col_1", "col_2", "col_3"}
     assert num_items == 4







@pytest.mark.parametrize('''archive_jsonl''',   ['''tar_jsonl_path''', '''zip_jsonl_path'''] )
def    a__							(							lowercase   :	List[Any],   lowercase   :	Optional[Any] )						->						Optional[int]:





     """simple docstring"""

     _UpperCamelCase							       =			request.getfixturevalue(lowercase )
     _UpperCamelCase							       =			DownloadManager()
     for num_jsonl, (path, file) in enumerate(dl_manager.iter_archive(lowercase ),   start=1 ):
          _test_jsonl(lowercase,   lowercase )
     assert num_jsonl == 2







@pytest.mark.parametrize('''archive_nested_jsonl''',   ['''tar_nested_jsonl_path''', '''zip_nested_jsonl_path'''] )
def    a__							(							lowercase   :	List[Any],   lowercase   :	Union[str, Any] )						->						Union[str, Any]:





     """simple docstring"""

     _UpperCamelCase							       =			request.getfixturevalue(lowercase )
     _UpperCamelCase							       =			DownloadManager()
     for num_tar, (path, file) in enumerate(dl_manager.iter_archive(lowercase ),   start=1 ):
          for num_jsonl, (subpath, subfile) in enumerate(dl_manager.iter_archive(lowercase ),   start=1 ):
               _test_jsonl(lowercase,   lowercase )
     assert num_tar == 1
     assert num_jsonl == 2







def    a__							(							lowercase   :	Tuple )						->						Tuple:





     """simple docstring"""

     _UpperCamelCase							       =			DownloadManager()
     for num_file, file in enumerate(dl_manager.iter_files(lowercase ),   start=1 ):
          assert os.path.basename(lowercase ) == ("test.txt" if num_file == 1 else "train.txt")
     assert num_file == 2










'''simple docstring'''

import math_equivalence  # From: git+https://github.com/hendrycks/math.git

import datasets


lowercase__		:     str			=							'\\n@article{hendrycksmath2021,\n  title={Measuring Mathematical Problem Solving With the MATH Dataset},\n  author={Dan Hendrycks\n    and Collin Burns\n    and Saurav Kadavath\n    and Akul Arora\n    and Steven Basart\n    and Eric Tang\n    and Dawn Song\n    and Jacob Steinhardt},\n  journal={arXiv preprint arXiv:2103.03874},\n  year={2021}\n}\n'


lowercase__		:     str			=							'\\nThis metric is used to assess performance on the Mathematics Aptitude Test of Heuristics (MATH) dataset.\nIt first canonicalizes the inputs (e.g., converting "1/2" to "\\frac{1}{2}") and then computes accuracy.\n'


lowercase__		:     Dict			=							R'\nCalculates accuracy after canonicalizing inputs.\n\nArgs:\n    predictions: list of predictions to score. Each prediction\n        is a string that contains natural language and LaTex.\n    references: list of reference for each prediction. Each\n        reference is a string that contains natural language\n        and LaTex.\nReturns:\n    accuracy: accuracy after canonicalizing inputs\n        (e.g., converting "1/2" to "\\frac{1}{2}")\n\nExamples:\n    >>> metric = datasets.load_metric("competition_math")\n    >>> results = metric.compute(references=["\\frac{1}{2}"], predictions=["1/2"])\n    >>> print(results)\n    {\'accuracy\': 1.0}\n'
@datasets.utils.file_utils.add_end_docstrings(_DESCRIPTION		,		_KWARGS_DESCRIPTION					)
class 							__lowerCAmelCase	(       datasets.Metric					):






       """simple docstring"""





       def snake_case__		(				self  :						Dict	)       ->	Any:

            '''simple docstring'''




            return datasets.MetricInfo(
                description=_DESCRIPTION			,					citation=_CITATION			,					inputs_description=_KWARGS_DESCRIPTION			,					features=datasets.Features(
                    {
                        '''predictions''': datasets.Value('''string'''	),
                        '''references''': datasets.Value('''string'''	),
                    }	)			,					homepage='''https://github.com/hendrycks/math'''			,					codebase_urls=['''https://github.com/hendrycks/math''']			,					)







       def snake_case__		(				self  :						List[Any]			,					lowerCAmelCase__  :						Dict			,					lowerCAmelCase__  :						int	)       ->	List[str]:

            '''simple docstring'''




            _UpperCamelCase							       =			0.0
            for i, j in zip(lowerCAmelCase__			,					lowerCAmelCase__	):
                 n_correct += 1.0 if math_equivalence.is_equiv(lowerCAmelCase__			,					lowerCAmelCase__	) else 0.0
            _UpperCamelCase							       =			n_correct / len(lowerCAmelCase__	)
            return {
                "accuracy": accuracy,
            }



