
"""simple docstring"""

import contextlib
import faulthandler
import io
import multiprocessing
import os
import platform
import signal
import tempfile






def 							A						(    snake_case				:Union[str, Any]    , snake_case				:Optional[int]    , snake_case				:Tuple    , snake_case				:str		)				->     int:
 __UpperCamelCase      =	multiprocessing.Manager()
 __UpperCamelCase      =	manager.list()

 __UpperCamelCase      =	multiprocessing.Process(target=snake_case_    , args=(check_program, result, timeout)		)
 p.start()
 p.join(timeout=timeout + 1		)
 if p.is_alive():
  p.kill()

 if not result:
  result.append('timed out'		)

 return {
     "task_id": task_id,
     "passed": result[0] == "passed",
     "result": result[0],
     "completion_id": completion_id,
 }






def 							A						(    snake_case				:int    , snake_case				:Optional[Any]    , snake_case				:int		)				->     List[str]:




 with create_tempdir():
  # These system calls are needed when cleaning up tempdir.
  import os
  import shutil

  __UpperCamelCase      =	shutil.rmtree
  __UpperCamelCase      =	os.rmdir
  __UpperCamelCase      =	os.chdir

  # Disable functionalities that can make destructive changes to the test.
  reliability_guard()

  # Run program.
  try:
   __UpperCamelCase      =	{}
   with swallow_io():
    with time_limit(snake_case_		):
     exec(snake_case_    , snake_case_		)
   result.append('passed'		)
  except TimeoutException:
   result.append('timed out'		)
  except BaseException as e:
   result.append(f'failed: {e}'		)

  # Needed for cleaning up.
  __UpperCamelCase      =	rmtree
  __UpperCamelCase      =	rmdir
  __UpperCamelCase      =	chdir






@contextlib.contextmanager
def 							A						(    snake_case				:Dict		)				->     List[Any]:




 def signal_handler(snake_case				:Optional[Any]    , snake_case				:int		):
  raise TimeoutException('Timed out!'		)

 signal.setitimer(signal.ITIMER_REAL    , snake_case_		)
 signal.signal(signal.SIGALRM    , snake_case_		)
 try:
  yield
 finally:
  signal.setitimer(signal.ITIMER_REAL    , 0		)






@contextlib.contextmanager
def 							A						(    )				->     Any:
 __UpperCamelCase      =	WriteOnlyStringIO()
 with contextlib.redirect_stdout(snake_case_		):
  with contextlib.redirect_stderr(snake_case_		):
   with redirect_stdin(snake_case_		):
    yield






@contextlib.contextmanager
def 							A						(    )				->     Dict:




 with tempfile.TemporaryDirectory() as dirname:
  with chdir(snake_case_		):
   yield dirname

class __lowerCAmelCase		(				UpperCamelCase__      ):
     pass


class __lowerCAmelCase		(				io.StringIO      ):





     def 						UpperCAmelCase (     self     ,					*__UpperCAmelCase     ,					**__UpperCAmelCase				):

      '''simple docstring'''




      raise OSError





     def 						UpperCAmelCase (     self     ,					*__UpperCAmelCase     ,					**__UpperCAmelCase				):

      '''simple docstring'''




      raise OSError





     def 						UpperCAmelCase (     self     ,					*__UpperCAmelCase     ,					**__UpperCAmelCase				):

      '''simple docstring'''




      raise OSError







     def 						UpperCAmelCase (     self     ,					*__UpperCAmelCase     ,					**__UpperCAmelCase				):

      '''simple docstring'''




      return False


class __lowerCAmelCase		(				contextlib._RedirectStream      ):  # type: ignore
     lowercase						       =						"""stdin"""






@contextlib.contextmanager
def 							A						(    snake_case				:str		)				->     Tuple:




 if root == ".":
  yield
  return
 __UpperCamelCase      =	os.getcwd()
 os.chdir(snake_case_		)
 try:
  yield
 except BaseException as exc:
  raise exc
 finally:
  os.chdir(snake_case_		)






def 							A						(    snake_case				:Any=None		)				->     Tuple:




 if maximum_memory_bytes is not None:
  import resource

  resource.setrlimit(resource.RLIMIT_AS    , (maximum_memory_bytes, maximum_memory_bytes)		)
  resource.setrlimit(resource.RLIMIT_DATA    , (maximum_memory_bytes, maximum_memory_bytes)		)
  if not platform.uname().system == "Darwin":
   resource.setrlimit(resource.RLIMIT_STACK    , (maximum_memory_bytes, maximum_memory_bytes)		)

 faulthandler.disable()

 import builtins

 __UpperCamelCase      =	None
 __UpperCamelCase      =	None

 import os

 __UpperCamelCase      =	'1'

 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None

 import shutil

 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None

 import subprocess

 __UpperCamelCase      =	None  # type: ignore

 __UpperCamelCase      =	None

 import sys

 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None
 __UpperCamelCase      =	None





"""simple docstring"""

from unittest import TestCase

from datasets import Dataset
from minhash_deduplication import deduplicate_dataset, make_duplicate_clusters






def 							A						(    )				->     Any:
 __UpperCamelCase      =	{
     'repo_name': ['test_repo1', 'test_repo2', 'test_repo3'],
     'path': ['test_1.py', 'test_2.py', 'unit_test.py'],
     'content': ['a ' * 2_0, 'a ' * 3_0, 'b ' * 7],
 }
 __UpperCamelCase      =	Dataset.from_dict(snake_case		)
 return dataset





class __lowerCAmelCase		(				__SCREAMING_SNAKE_CASE      ):





     def 						UpperCAmelCase (     self				):

      '''simple docstring'''




      __UpperCamelCase      =	get_dataset()
      __UpperCamelCase      =	make_duplicate_clusters(__UpperCAmelCase     ,					0.8_5				)
      self.assertEqual(len(duplicate_clusters[0]				)     ,					2				)







     def 						UpperCAmelCase (     self				):

      '''simple docstring'''




      __UpperCamelCase      =	get_dataset()
      __UpperCamelCase  ,     __UpperCamelCase      =	deduplicate_dataset(__UpperCAmelCase				)
      self.assertEqual(len(__UpperCAmelCase				)     ,					2				)
      print(__UpperCAmelCase				)
      self.assertEqual(duplicate_clusters[0][0]['copies']     ,					2				)
      self.assertEqual(duplicate_clusters[0][0]['is_extreme']     ,					__UpperCAmelCase				)



