





'''simple docstring'''


import posixpath
from pathlib import Path
from unittest.mock import patch

import pytest
from fsspec.implementations.local import AbstractFileSystem, LocalFileSystem, stringify_path
from fsspec.registry import _registry as _fsspec_registry



class 							__UpperCAmelCase  (       A__						):







		'''simple docstring'''







		__lowerCAmelCase 				=    '''mock'''







		def __init__(self						:      str      ,      *_lowerCAmelCase						:      List[str]      ,      _lowerCAmelCase						:      Tuple      ,      **_lowerCAmelCase						:      str      ):
			super().__init__()
			A							  =      LocalFileSystem(*_lowerCAmelCase      ,      **_lowerCAmelCase      )
			A							  =      Path(_lowerCAmelCase      ).resolve().as_posix() + """/"""







		def        A     (self						:      int      ,      _lowerCAmelCase						:      str      ,      *_lowerCAmelCase						:      Dict      ,      **_lowerCAmelCase						:      Optional[Any]      ):
			A							  =      posixpath.join(self.local_root_dir      ,      self._strip_protocol(_lowerCAmelCase      )      )
			return self._fs.mkdir(_lowerCAmelCase      ,      *_lowerCAmelCase      ,      **_lowerCAmelCase      )







		def        A     (self						:      List[Any]      ,      _lowerCAmelCase						:      List[str]      ,      *_lowerCAmelCase						:      Optional[Any]      ,      **_lowerCAmelCase						:      str      ):
			A							  =      posixpath.join(self.local_root_dir      ,      self._strip_protocol(_lowerCAmelCase      )      )
			return self._fs.makedirs(_lowerCAmelCase      ,      *_lowerCAmelCase      ,      **_lowerCAmelCase      )







		def        A     (self						:      List[str]      ,      _lowerCAmelCase						:      Dict      ):
			A							  =      posixpath.join(self.local_root_dir      ,      self._strip_protocol(_lowerCAmelCase      )      )
			return self._fs.rmdir(_lowerCAmelCase      )







		def        A     (self						:      Dict      ,      _lowerCAmelCase						:      List[str]      ,      _lowerCAmelCase						:      Optional[Any]=True      ,      *_lowerCAmelCase						:      List[str]      ,      **_lowerCAmelCase						:      str      ):
			A							  =      posixpath.join(self.local_root_dir      ,      self._strip_protocol(_lowerCAmelCase      )      )
			A							  =      self._fs.ls(_lowerCAmelCase      ,      detail=_lowerCAmelCase      ,      *_lowerCAmelCase      ,      **_lowerCAmelCase      )
			if detail:
				return [{**info, "name": info["name"][len(self.local_root_dir      ) :]} for info in out]
			else:
				return [name[len(self.local_root_dir      ) :] for name in out]







		def        A     (self						:      Dict      ,      _lowerCAmelCase						:      List[Any]      ,      *_lowerCAmelCase						:      Dict      ,      **_lowerCAmelCase						:      Any      ):
			A							  =      posixpath.join(self.local_root_dir      ,      self._strip_protocol(_lowerCAmelCase      )      )
			A							  =      dict(self._fs.info(_lowerCAmelCase      ,      *_lowerCAmelCase      ,      **_lowerCAmelCase      )      )
			A							  =      out["""name"""][len(self.local_root_dir      ) :]
			return out







		def        A     (self						:      List[str]      ,      _lowerCAmelCase						:      List[str]      ,      _lowerCAmelCase						:      Tuple      ,      *_lowerCAmelCase						:      str      ,      **_lowerCAmelCase						:      List[str]      ):
			A							  =      posixpath.join(self.local_root_dir      ,      self._strip_protocol(_lowerCAmelCase      )      )
			A							  =      posixpath.join(self.local_root_dir      ,      self._strip_protocol(_lowerCAmelCase      )      )
			return self._fs.cp_file(_lowerCAmelCase      ,      _lowerCAmelCase      ,      *_lowerCAmelCase      ,      **_lowerCAmelCase      )







		def        A     (self						:      List[str]      ,      _lowerCAmelCase						:      Any      ,      *_lowerCAmelCase						:      Dict      ,      **_lowerCAmelCase						:      List[Any]      ):
			A							  =      posixpath.join(self.local_root_dir      ,      self._strip_protocol(_lowerCAmelCase      )      )
			return self._fs.rm_file(_lowerCAmelCase      ,      *_lowerCAmelCase      ,      **_lowerCAmelCase      )







		def        A     (self						:      Any      ,      _lowerCAmelCase						:      Dict      ,      *_lowerCAmelCase						:      Optional[int]      ,      **_lowerCAmelCase						:      List[str]      ):
			A							  =      posixpath.join(self.local_root_dir      ,      self._strip_protocol(_lowerCAmelCase      )      )
			return self._fs.rm(_lowerCAmelCase      ,      *_lowerCAmelCase      ,      **_lowerCAmelCase      )







		def        A     (self						:      Tuple      ,      _lowerCAmelCase						:      Dict      ,      *_lowerCAmelCase						:      Optional[Any]      ,      **_lowerCAmelCase						:      Dict      ):
			A							  =      posixpath.join(self.local_root_dir      ,      self._strip_protocol(_lowerCAmelCase      )      )
			return self._fs._open(_lowerCAmelCase      ,      *_lowerCAmelCase      ,      **_lowerCAmelCase      )







		def        A     (self						:      Union[str, Any]      ,      _lowerCAmelCase						:      int      ):
			A							  =      posixpath.join(self.local_root_dir      ,      self._strip_protocol(_lowerCAmelCase      )      )
			return self._fs.created(_lowerCAmelCase      )







		def        A     (self						:      Tuple      ,      _lowerCAmelCase						:      Any      ):
			A							  =      posixpath.join(self.local_root_dir      ,      self._strip_protocol(_lowerCAmelCase      )      )
			return self._fs.modified(_lowerCAmelCase      )







		@classmethod
		def        A     (cls						:      List[str]      ,      _lowerCAmelCase						:      Dict      ):
			A							  =      stringify_path(_lowerCAmelCase      )
			if path.startswith("""mock://"""      ):
				A							  =      path[7:]
			return path






class 							__UpperCAmelCase  (       A__						):







		'''simple docstring'''







		__lowerCAmelCase 				=    '''tmp'''
		__lowerCAmelCase 				=    None







		def __init__(self						:      List[str]      ,      *_lowerCAmelCase						:      Union[str, Any]      ,      **_lowerCAmelCase						:      str      ):
			assert self.tmp_dir is not None, "TmpDirFileSystem.tmp_dir is not set"
			super().__init__(*_lowerCAmelCase      ,      **_lowerCAmelCase      ,      local_root_dir=self.tmp_dir      ,      auto_mkdir=_lowerCAmelCase      )







		@classmethod
		def        A     (cls						:      Dict      ,      _lowerCAmelCase						:      Dict      ):
			A							  =      stringify_path(_lowerCAmelCase      )
			if path.startswith("""tmp://"""      ):
				A							  =      path[6:]
			return path






@pytest.fixture
def    __a (     )      ->Dict:



	"""simple docstring"""







	A							  =      MockFileSystem
	A							  =      TmpDirFileSystem
	yield
	del _fsspec_registry["mock"]
	del _fsspec_registry["tmp"]




@pytest.fixture
def    __a (     UpperCAmelCase       ,			UpperCAmelCase    )      ->List[Any]:



	"""simple docstring"""







	A							  =      tmp_path_factory.mktemp("""mockfs"""    )
	return MockFileSystem(local_root_dir=UpperCAmelCase       ,			auto_mkdir=UpperCAmelCase    )




@pytest.fixture
def    __a (     UpperCAmelCase       ,			UpperCAmelCase    )      ->int:



	"""simple docstring"""







	A							  =      tmp_path_factory.mktemp("""tmpfs"""    )
	with patch.object(UpperCAmelCase       ,			"""tmp_dir"""       ,			UpperCAmelCase    ):
		yield TmpDirFileSystem()








'''simple docstring'''


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

import pytest
import requests

_lowerCamelCase				:	Optional[Any]				    =       pathlib.Path.cwd().joinpath('project_euler')
_lowerCamelCase				:	Optional[int]				    =       pathlib.Path.cwd().joinpath(
    'scripts', 'project_euler_answers.json'
)

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




def    __a (     UpperCAmelCase    )      ->ModuleType:



	"""simple docstring"""







	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    __a (     )      ->list[pathlib.Path]:



	"""simple docstring"""







	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    __a (     )      ->str:



	"""simple docstring"""







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




def    __a (     )      ->list[pathlib.Path]:



	"""simple docstring"""







	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    __a (     )      ->list[pathlib.Path]:



	"""simple docstring"""







	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    __a (     UpperCAmelCase    )      ->None:



	"""simple docstring"""







	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}"""

