


'''simple docstring'''


import contextlib
import importlib
import io
import unittest

import transformers

# Try to import everything from transformers to ensure every object can be loaded.
from transformers import *  # noqa F406
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, require_tf, require_torch
from transformers.utils import ContextManagers, find_labels, is_flax_available, is_tf_available, is_torch_available


if is_torch_available():
						from transformers import BertForPreTraining, BertForQuestionAnswering, BertForSequenceClassification

if is_tf_available():
						from transformers import TFBertForPreTraining, TFBertForQuestionAnswering, TFBertForSequenceClassification

if is_flax_available():
						from transformers import FlaxBertForPreTraining, FlaxBertForQuestionAnswering, FlaxBertForSequenceClassification


lowerCamelCase__    	=							DUMMY_UNKNOWN_IDENTIFIER
# An actual model hosted on huggingface.co

lowerCamelCase__    	=							'main'
# Default branch name
lowerCamelCase__    	=							'f2c752cfc5c0ab6f4bdec59acea69eefbee381c2'
# One particular commit (not the top of `main`)
lowerCamelCase__    	=							'aaaaaaa'
# This commit does not exist, so we should 404.

lowerCamelCase__    	=							'd9e9f15bc825e4b2c9249e9578f884bbcb5e3684'
# Sha-1 of config.json on the top of `main`, for checking purposes
lowerCamelCase__    	=							'4b243c475af8d0a7754e87d7d096c92e5199ec2fe168a2ee7998e3b8e9bcb1d3'






@contextlib.contextmanager
def  __lowerCAmelCase ():
		print("Welcome!"   )
		yield
		print("Bye!"   )






@contextlib.contextmanager
def  __lowerCAmelCase ():
		print("Bonjour!"   )
		yield
		print("Au revoir!"   )






class 	lowerCAmelCase__			(			unittest.TestCase	):




			def 							lowerCAmelCase__    (		self  :     Union[str, Any] )   ->Tuple:



					'''simple docstring'''







					assert transformers.__spec__ is not None
					assert importlib.util.find_spec("transformers" ) is not None






class 	lowerCAmelCase__			(			unittest.TestCase	):




			@unittest.mock.patch("sys.stdout"	,  new_callable=io.StringIO )
			def 							lowerCAmelCase__    (		self  :     Any	,  lowerCamelCase__  :     Optional[int] )   ->Any:



					'''simple docstring'''







					with ContextManagers([] ):
							print("Transformers are awesome!" )
					# The print statement adds a new line at the end of the output
					self.assertEqual(mock_stdout.getvalue()	,  "Transformers are awesome!\n" )




			@unittest.mock.patch("sys.stdout"	,  new_callable=io.StringIO )
			def 							lowerCAmelCase__    (		self  :     List[Any]	,  lowerCamelCase__  :     Dict )   ->Any:



					'''simple docstring'''







					with ContextManagers([context_en()] ):
							print("Transformers are awesome!" )
					# The output should be wrapped with an English welcome and goodbye
					self.assertEqual(mock_stdout.getvalue()	,  "Welcome!\nTransformers are awesome!\nBye!\n" )




			@unittest.mock.patch("sys.stdout"	,  new_callable=io.StringIO )
			def 							lowerCAmelCase__    (		self  :     str	,  lowerCamelCase__  :     int )   ->Tuple:



					'''simple docstring'''







					with ContextManagers([context_fr(), context_en()] ):
							print("Transformers are awesome!" )
					# The output should be wrapped with an English and French welcome and goodbye
					self.assertEqual(mock_stdout.getvalue()	,  "Bonjour!\nWelcome!\nTransformers are awesome!\nBye!\nAu revoir!\n" )




			@require_torch
			def 							lowerCAmelCase__    (		self  :     int )   ->Tuple:



					'''simple docstring'''







					self.assertEqual(find_labels(lowerCamelCase__ )	,  ["labels"] )
					self.assertEqual(find_labels(lowerCamelCase__ )	,  ["labels", "next_sentence_label"] )
					self.assertEqual(find_labels(lowerCamelCase__ )	,  ["start_positions", "end_positions"] )






					class 	lowerCAmelCase__			(			UpperCAmelCase__	):
								pass




					self.assertEqual(find_labels(lowerCamelCase__ )	,  ["labels"] )




			@require_tf
			def 							lowerCAmelCase__    (		self  :     Optional[Any] )   ->Union[str, Any]:



					'''simple docstring'''







					self.assertEqual(find_labels(lowerCamelCase__ )	,  ["labels"] )
					self.assertEqual(find_labels(lowerCamelCase__ )	,  ["labels", "next_sentence_label"] )
					self.assertEqual(find_labels(lowerCamelCase__ )	,  ["start_positions", "end_positions"] )






					class 	lowerCAmelCase__			(			UpperCAmelCase__	):
								pass




					self.assertEqual(find_labels(lowerCamelCase__ )	,  ["labels"] )






			@require_flax
			def 							lowerCAmelCase__    (		self  :     List[Any] )   ->Tuple:



					'''simple docstring'''







					self.assertEqual(find_labels(lowerCamelCase__ )	,  [] )
					self.assertEqual(find_labels(lowerCamelCase__ )	,  [] )
					self.assertEqual(find_labels(lowerCamelCase__ )	,  [] )






					class 	lowerCAmelCase__			(			UpperCAmelCase__	):
								pass




					self.assertEqual(find_labels(lowerCamelCase__ )	,  [] )







'''simple docstring'''


import os
import re
import shutil
import sys
import tempfile
import unittest

import black


lowerCamelCase__    	=     os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, 'utils'))

import check_copies  # noqa: E402


# This is the reference code that will be used in the tests.
# If DDPMSchedulerOutput is changed in scheduling_ddpm.py, this code needs to be manually updated.
lowerCamelCase__    	=     '    \"""\n    Output class for the scheduler\'s step function output.\n\n    Args:\n        prev_sample (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)` for images):\n            Computed sample (x_{t-1}) of previous timestep. `prev_sample` should be used as next model input in the\n            denoising loop.\n        pred_original_sample (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)` for images):\n            The predicted denoised sample (x_{0}) based on the model output from the current timestep.\n            `pred_original_sample` can be used to preview progress or for guidance.\n    \"""\n\n    prev_sample: torch.FloatTensor\n    pred_original_sample: Optional[torch.FloatTensor] = None\n'






class 	lowerCAmelCase__			(			unittest.TestCase	):




			def 							lowerCAmelCase__    (		self  :     Any )   ->Any:



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[int]								=      tempfile.mkdtemp()
					os.makedirs(os.path.join(self.diffusers_dir	,  "schedulers/" ) )
					_UpperCAmelCase		:       Optional[Any]								=      self.diffusers_dir
					shutil.copy(
					    os.path.join(lowerCamelCase__	,  "src/diffusers/schedulers/scheduling_ddpm.py" )	,  os.path.join(self.diffusers_dir	,  "schedulers/scheduling_ddpm.py" )	,  )




			def 							lowerCAmelCase__    (		self  :     Union[str, Any] )   ->str:



					'''simple docstring'''







					_UpperCAmelCase		:       int								=      "src/diffusers"
					shutil.rmtree(self.diffusers_dir )




			def 							lowerCAmelCase__    (		self  :     str	,  lowerCamelCase__  :     List[str]	,  lowerCamelCase__  :     Optional[Any]	,  lowerCamelCase__  :     Union[str, Any]	,  lowerCamelCase__  :     Any=None )   ->List[str]:



					'''simple docstring'''







					_UpperCAmelCase		:       Union[str, Any]								=      comment + F"""\nclass {class_name}(nn.Module):\n""" + class_code
					if overwrite_result is not None:
							_UpperCAmelCase		:       Tuple								=      comment + F"""\nclass {class_name}(nn.Module):\n""" + overwrite_result
					_UpperCAmelCase		:       Optional[Any]								=      black.Mode(target_versions={black.TargetVersion.PYaa}	,  line_length=1_19 )
					_UpperCAmelCase		:       Tuple								=      black.format_str(lowerCamelCase__	,  mode=lowerCamelCase__ )
					_UpperCAmelCase		:       Optional[int]								=      os.path.join(self.diffusers_dir	,  "new_code.py" )
					with open(lowerCamelCase__	,  "w"	,  newline="\n" ) as f:
							f.write(lowerCamelCase__ )
					if overwrite_result is None:
							self.assertTrue(len(check_copies.is_copy_consistent(lowerCamelCase__ ) ) == 0 )
					else:
							check_copies.is_copy_consistent(f.name	,  overwrite=lowerCamelCase__ )
							with open(lowerCamelCase__	,  "r" ) as f:
									self.assertTrue(f.read()	,  lowerCamelCase__ )




			def 							lowerCAmelCase__    (		self  :     str )   ->Tuple:



					'''simple docstring'''







					_UpperCAmelCase		:       Tuple								=      check_copies.find_code_in_diffusers("schedulers.scheduling_ddpm.DDPMSchedulerOutput" )
					self.assertEqual(lowerCamelCase__	,  lowerCamelCase__ )






			def 							lowerCAmelCase__    (		self  :     Union[str, Any] )   ->Optional[int]:



					'''simple docstring'''







					self.check_copy_consistency(
					    "# Copied from diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput"	,  "DDPMSchedulerOutput"	,  REFERENCE_CODE + "\n"	,  )

					# With no empty line at the end
					self.check_copy_consistency(
					    "# Copied from diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput"	,  "DDPMSchedulerOutput"	,  lowerCamelCase__	,  )

					# Copy consistency with rename
					self.check_copy_consistency(
					    "# Copied from diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput with DDPM->Test"	,  "TestSchedulerOutput"	,  re.sub("DDPM"	,  "Test"	,  lowerCamelCase__ )	,  )

					# Copy consistency with a really long name
					_UpperCAmelCase		:       int								=      "TestClassWithAReallyLongNameBecauseSomePeopleLikeThatForSomeReason"
					self.check_copy_consistency(
					    F"""# Copied from diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput with DDPM->{long_class_name}"""	,  F"""{long_class_name}SchedulerOutput"""	,  re.sub("Bert"	,  lowerCamelCase__	,  lowerCamelCase__ )	,  )

					# Copy consistency with overwrite
					self.check_copy_consistency(
					    "# Copied from diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput with DDPM->Test"	,  "TestSchedulerOutput"	,  lowerCamelCase__	,  overwrite_result=re.sub("DDPM"	,  "Test"	,  lowerCamelCase__ )	,  )



