

"""simple docstring"""




# This code is adapted from OpenAI's release
# https://github.com/openai/human-eval/blob/master/human_eval/execution.py

import contextlib
import faulthandler
import io
import multiprocessing
import os
import platform
import signal
import tempfile
def   lowerCAmelCase						(					__UpperCamelCase							,    __UpperCamelCase							,    __UpperCamelCase							,    __UpperCamelCase      ):
 '''simple docstring'''





 UpperCAmelCase__					:  Dict					   =					multiprocessing.Manager()
 UpperCAmelCase__					:  Optional[Any]					   =					manager.list()

 UpperCAmelCase__					:  Union[str, Any]					   =					multiprocessing.Process(target=__UpperCamelCase							,    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   lowerCAmelCase						(					__UpperCamelCase							,    __UpperCamelCase							,    __UpperCamelCase      ):
 '''simple docstring'''





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

  UpperCAmelCase__					:  Optional[Any]					   =					shutil.rmtree
  UpperCAmelCase__					:  Dict					   =					os.rmdir
  UpperCAmelCase__					:  Union[str, Any]					   =					os.chdir

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

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

  # Needed for cleaning up.
  UpperCAmelCase__					:  Tuple					   =					rmtree
  UpperCAmelCase__					:  Tuple					   =					rmdir
  UpperCAmelCase__					:  List[str]					   =					chdir
@contextlib.contextmanager
def   lowerCAmelCase						(					__UpperCamelCase      ):
 '''simple docstring'''





 def signal_handler(__UpperCamelCase							,    __UpperCamelCase      ):
  raise TimeoutException("""Timed out!"""      )

 signal.setitimer(signal.ITIMER_REAL							,    __UpperCamelCase      )
 signal.signal(signal.SIGALRM							,    __UpperCamelCase      )
 try:
  yield
 finally:
  signal.setitimer(signal.ITIMER_REAL							,    0      )
@contextlib.contextmanager
def   lowerCAmelCase						(					):
 '''simple docstring'''





 UpperCAmelCase__					:  Any					   =					WriteOnlyStringIO()
 with contextlib.redirect_stdout(__UpperCamelCase      ):
  with contextlib.redirect_stderr(__UpperCamelCase      ):
   with redirect_stdin(__UpperCamelCase      ):
    yield
@contextlib.contextmanager
def   lowerCAmelCase						(					):
 '''simple docstring'''





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







class      __lowercase			(    __lowerCamelCase					):
  pass







class      __lowercase			(    io.StringIO					):

  def    __lowercase       (  self		:			Tuple					,*A		:			Dict					,**A		:			Optional[Any]    ):






   '''simple docstring'''
   raise OSError

  def    __lowercase       (  self		:			Tuple					,*A		:			int					,**A		:			Tuple    ):






   '''simple docstring'''
   raise OSError

  def    __lowercase       (  self		:			List[Any]					,*A		:			Dict					,**A		:			Optional[Any]    ):






   '''simple docstring'''
   raise OSError




  def    __lowercase       (  self		:			int					,*A		:			Optional[Any]					,**A		:			List[str]    ):






   '''simple docstring'''
   return False







class      __lowercase			(    contextlib._RedirectStream					):  # type: ignore
  snake_case_				       =       """stdin"""







@contextlib.contextmanager
def   lowerCAmelCase						(					__UpperCamelCase      ):
 '''simple docstring'''





 if root == ".":
  yield
  return
 UpperCAmelCase__					:  Optional[int]					   =					os.getcwd()
 os.chdir(__UpperCamelCase      )
 try:
  yield
 except BaseException as exc:
  raise exc
 finally:
  os.chdir(__UpperCamelCase      )




def   lowerCAmelCase						(					__UpperCamelCase=None      ):
 '''simple docstring'''





 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__					:  str					   =					None
 UpperCAmelCase__					:  List[str]					   =					None

 import os

 UpperCAmelCase__					:  int					   =					"""1"""

 UpperCAmelCase__					:  Tuple					   =					None
 UpperCAmelCase__					:  Dict					   =					None
 UpperCAmelCase__					:  Tuple					   =					None
 UpperCAmelCase__					:  Optional[int]					   =					None
 UpperCAmelCase__					:  Optional[int]					   =					None
 UpperCAmelCase__					:  List[str]					   =					None
 UpperCAmelCase__					:  Tuple					   =					None
 UpperCAmelCase__					:  Tuple					   =					None
 UpperCAmelCase__					:  List[Any]					   =					None
 UpperCAmelCase__					:  Optional[int]					   =					None
 UpperCAmelCase__					:  str					   =					None
 UpperCAmelCase__					:  Optional[Any]					   =					None
 UpperCAmelCase__					:  Any					   =					None
 UpperCAmelCase__					:  Optional[int]					   =					None
 UpperCAmelCase__					:  Any					   =					None
 UpperCAmelCase__					:  int					   =					None
 UpperCAmelCase__					:  Tuple					   =					None
 UpperCAmelCase__					:  Dict					   =					None
 UpperCAmelCase__					:  int					   =					None
 UpperCAmelCase__					:  Any					   =					None
 UpperCAmelCase__					:  List[str]					   =					None
 UpperCAmelCase__					:  int					   =					None
 UpperCAmelCase__					:  Any					   =					None
 UpperCAmelCase__					:  Tuple					   =					None
 UpperCAmelCase__					:  str					   =					None
 UpperCAmelCase__					:  Optional[Any]					   =					None
 UpperCAmelCase__					:  Tuple					   =					None

 import shutil

 UpperCAmelCase__					:  Union[str, Any]					   =					None
 UpperCAmelCase__					:  List[str]					   =					None
 UpperCAmelCase__					:  str					   =					None

 import subprocess

 UpperCAmelCase__					:  Optional[int]					   =					None  # type: ignore

 UpperCAmelCase__					:  Optional[int]					   =					None

 import sys

 UpperCAmelCase__					:  Any					   =					None
 UpperCAmelCase__					:  int					   =					None
 UpperCAmelCase__					:  Dict					   =					None
 UpperCAmelCase__					:  Any					   =					None
 UpperCAmelCase__					:  str					   =					None








"""simple docstring"""




# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import sys
import warnings
from os.path import abspath, dirname, join


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
__UpperCAmelCase =				abspath(join(dirname(dirname(__file__)), 'src'))
sys.path.insert(1, git_repo_path)

# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action='ignore', category=FutureWarning)
def   lowerCAmelCase						(					__UpperCamelCase      ):
 '''simple docstring'''





 from diffusers.utils.testing_utils import pytest_addoption_shared

 pytest_addoption_shared(__UpperCamelCase      )




def   lowerCAmelCase						(					__UpperCamelCase      ):
 '''simple docstring'''





 from diffusers.utils.testing_utils import pytest_terminal_summary_main

 UpperCAmelCase__					:  Optional[Any]					   =					terminalreporter.config.getoption("""--make-reports"""      )
 if make_reports:
  pytest_terminal_summary_main(__UpperCamelCase							,    id=__UpperCamelCase      )





