


"""simple docstring"""






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

import pytest
import requests

UpperCamelCase__							:str       =  pathlib.Path.cwd().joinpath("""project_euler""")
UpperCamelCase__							:Tuple       =  pathlib.Path.cwd().joinpath(
    """scripts""", """project_euler_answers.json"""
)

with open(PROJECT_EULER_ANSWERS_PATH) as file_handle:
     UpperCamelCase__							:dict[str, str]       =  json.load(file_handle)





def 							A_					(   snake_case__		)				->     ModuleType:
   _UpperCamelCase				:Tuple				    =  importlib.util.spec_from_file_location(file_path.name					,				str(snake_case__		)		)
   _UpperCamelCase				:Dict				    =  importlib.util.module_from_spec(snake_case__		)  # type: ignore
   spec.loader.exec_module(snake_case__		)  # type: ignore
   return module





def 							A_					(   )				->     list[pathlib.Path]:
   _UpperCamelCase				:Tuple				    =  []
   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(snake_case__		)
   return solution_file_paths





def 							A_					(   )				->     str:
   with open(os.environ['''GITHUB_EVENT_PATH''']		) as file:
      _UpperCamelCase				:List[Any]				    =  json.load(snake_case__		)
   return event["pull_request"]["url"] + "/files"





def 							A_					(   )				->     list[pathlib.Path]:
   _UpperCamelCase				:Tuple				    =  []
   _UpperCamelCase				:List[Any]				    =  {
       '''Accept''': '''application/vnd.github.v3+json''',
       '''Authorization''': '''token ''' + os.environ['''GITHUB_TOKEN'''],
   }
   _UpperCamelCase				:List[Any]				    =  requests.get(get_files_url()					,				headers=snake_case__		).json()
   for file in files:
      _UpperCamelCase				:Optional[int]				    =  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(snake_case__		)
   return solution_file_paths





def 							A_					(   )				->     list[pathlib.Path]:
   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 snake_case__		: f"{path.parent.name}/{path.name}"					,				)
def 							A_					(   snake_case__		)				->     None:
   _UpperCamelCase				:str				    =  solution_path.parent.name[8:].zfill(3		)
   _UpperCamelCase				:str				    =  PROBLEM_ANSWERS[problem_number]
   _UpperCamelCase				:Optional[Any]				    =  convert_path_to_module(snake_case__		)
   _UpperCamelCase				:Optional[int]				    =  str(solution_module.solution()		)  # type: ignore
   _UpperCamelCase				:str				    =  hashlib.shaaaa(answer.encode()		).hexdigest()
   assert (
       answer == expected
   ), f"Expected solution to {problem_number} to have hash {expected}, got {answer}"





"""simple docstring"""






import textwrap

import pyarrow as pa
import pytest

from datasets import Features, Value
from datasets.packaged_modules.json.json import Json





@pytest.fixture
def 							A_					(   snake_case__		)				->     Union[str, Any]:
			_UpperCamelCase				:int				    =  tmp_path / '''file.jsonl'''
			_UpperCamelCase				:Dict				    =  textwrap.dedent(
			    '''\
        {"col_1": -1}
        {"col_1": 1, "col_2": 2}
        {"col_1": 10, "col_2": 20}
        '''		)
			with open(snake_case__					,				'''w'''		) as f:
						f.write(snake_case__		)
			return str(snake_case__		)





@pytest.fixture
def 							A_					(   snake_case__		)				->     Optional[int]:
			_UpperCamelCase				:Dict				    =  tmp_path / '''file_utf16_encoded.jsonl'''
			_UpperCamelCase				:Dict				    =  textwrap.dedent(
			    '''\
        {"col_1": -1}
        {"col_1": 1, "col_2": 2}
        {"col_1": 10, "col_2": 20}
        '''		)
			with open(snake_case__					,				'''w'''					,				encoding='''utf-16'''		) as f:
						f.write(snake_case__		)
			return str(snake_case__		)





@pytest.fixture
def 							A_					(   snake_case__		)				->     Optional[int]:
			_UpperCamelCase				:Optional[Any]				    =  tmp_path / '''file_with_list_of_dicts.json'''
			_UpperCamelCase				:str				    =  textwrap.dedent(
			    '''\
        [
            {"col_1": -1},
            {"col_1": 1, "col_2": 2},
            {"col_1": 10, "col_2": 20}
        ]
        '''		)
			with open(snake_case__					,				'''w'''		) as f:
						f.write(snake_case__		)
			return str(snake_case__		)





@pytest.fixture
def 							A_					(   snake_case__		)				->     Union[str, Any]:
			_UpperCamelCase				:Dict				    =  tmp_path / '''file_with_list_of_dicts_field.json'''
			_UpperCamelCase				:Optional[int]				    =  textwrap.dedent(
			    '''\
        {
            "field1": 1,
            "field2": "aabb",
            "field3": [
                {"col_1": -1},
                {"col_1": 1, "col_2": 2},
                {"col_1": 10, "col_2": 20}
            ]
        }
        '''		)
			with open(snake_case__					,				'''w'''		) as f:
						f.write(snake_case__		)
			return str(snake_case__		)





@pytest.mark.parametrize(
    '''file_fixture, config_kwargs'''					,				[
        ('''jsonl_file''', {}),
        ('''jsonl_file_utf16_encoded''', {'''encoding''': '''utf-16'''}),
        ('''json_file_with_list_of_dicts''', {}),
        ('''json_file_with_list_of_dicts_field''', {'''field''': '''field3'''}),
    ]					,				)
def 							A_					(   snake_case__					,				snake_case__					,				snake_case__		)				->     int:
			_UpperCamelCase				:Any				    =  Json(**snake_case__		)
			_UpperCamelCase				:str				    =  json._generate_tables([[request.getfixturevalue(snake_case__		)]]		)
			_UpperCamelCase				:List[Any]				    =  pa.concat_tables([table for _, table in generator]		)
			assert pa_table.to_pydict() == {"col_1": [-1, 1, 10], "col_2": [None, 2, 20]}





@pytest.mark.parametrize(
    '''file_fixture, config_kwargs'''					,				[
        (
            '''jsonl_file''',
            {'''features''': Features({'''col_1''': Value('''int64'''		), '''col_2''': Value('''int64'''		), '''missing_col''': Value('''string'''		)}		)},
        ),
        (
            '''json_file_with_list_of_dicts''',
            {'''features''': Features({'''col_1''': Value('''int64'''		), '''col_2''': Value('''int64'''		), '''missing_col''': Value('''string'''		)}		)},
        ),
        (
            '''json_file_with_list_of_dicts_field''',
            {
                '''field''': '''field3''',
                '''features''': Features(
                    {'''col_1''': Value('''int64'''		), '''col_2''': Value('''int64'''		), '''missing_col''': Value('''string'''		)}		),
            },
        ),
    ]					,				)
def 							A_					(   snake_case__					,				snake_case__					,				snake_case__		)				->     Optional[int]:
			_UpperCamelCase				:Union[str, Any]				    =  Json(**snake_case__		)
			_UpperCamelCase				:List[str]				    =  json._generate_tables([[request.getfixturevalue(snake_case__		)]]		)
			_UpperCamelCase				:str				    =  pa.concat_tables([table for _, table in generator]		)
			assert pa_table.to_pydict() == {"col_1": [-1, 1, 10], "col_2": [None, 2, 20], "missing_col": [None, None, None]}

