
import os
import sys
import unittest


lowercase_ 				=			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_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
lowercase_ 				=			os.path.join(git_repo_path, """src""", """diffusers""")





class     __UpperCamelCase (							unittest.TestCase       ):






     """simple docstring"""







     def  UpperCAmelCase__							(				self							:							Union[str, Any] ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		find_backend('''    if not is_torch_available():''' )
       self.assertEqual(_A     ,						'''torch''' )

       # backend_with_underscore = find_backend("    if not is_tensorflow_text_available():")
       # self.assertEqual(backend_with_underscore, "tensorflow_text")

       __SCREAMING_SNAKE_CASE      :	List[str]					=		find_backend('''    if not (is_torch_available() and is_transformers_available()):''' )
       self.assertEqual(_A     ,						'''torch_and_transformers''' )

       # double_backend_with_underscore = find_backend(
       #    "    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"
       # )
       # self.assertEqual(double_backend_with_underscore, "sentencepiece_and_tensorflow_text")

       __SCREAMING_SNAKE_CASE      :	List[str]					=		find_backend(
           '''    if not (is_torch_available() and is_transformers_available() and is_onnx_available()):''' )
       self.assertEqual(_A     ,						'''torch_and_transformers_and_onnx''' )



     def  UpperCAmelCase__							(				self							:							Optional[Any] ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		read_init()
       # We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
       self.assertIn('''torch'''     ,						_A )
       self.assertIn('''torch_and_transformers'''     ,						_A )
       self.assertIn('''flax_and_transformers'''     ,						_A )
       self.assertIn('''torch_and_transformers_and_onnx'''     ,						_A )

       # Likewise, we can't assert on the exact content of a key
       self.assertIn('''UNet2DModel'''     ,						objects['''torch'''] )
       self.assertIn('''FlaxUNet2DConditionModel'''     ,						objects['''flax'''] )
       self.assertIn('''StableDiffusionPipeline'''     ,						objects['''torch_and_transformers'''] )
       self.assertIn('''FlaxStableDiffusionPipeline'''     ,						objects['''flax_and_transformers'''] )
       self.assertIn('''LMSDiscreteScheduler'''     ,						objects['''torch_and_scipy'''] )
       self.assertIn('''OnnxStableDiffusionPipeline'''     ,						objects['''torch_and_transformers_and_onnx'''] )



     def  UpperCAmelCase__							(				self							:							List[Any] ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		create_dummy_object('''CONSTANT'''     ,						'''\'torch\'''' )
       self.assertEqual(_A     ,						'''\nCONSTANT = None\n''' )

       __SCREAMING_SNAKE_CASE      :	Dict					=		create_dummy_object('''function'''     ,						'''\'torch\'''' )
       self.assertEqual(
           _A     ,						'''\ndef function(*args, **kwargs):\n    requires_backends(function, \'torch\')\n''' )

       __SCREAMING_SNAKE_CASE      :	List[Any]					=		'''
class FakeClass(metaclass=DummyObject):
    _backends = \'torch\'

    def __init__(self, *args, **kwargs):
        requires_backends(self, \'torch\')

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, \'torch\')

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, \'torch\')
'''
       __SCREAMING_SNAKE_CASE      :	List[Any]					=		create_dummy_object('''FakeClass'''     ,						'''\'torch\'''' )
       self.assertEqual(_A     ,						_A )




     def  UpperCAmelCase__							(				self							:							List[Any] ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Any					=		'''# This file is autogenerated by the command `make fix-copies`, do not edit.
from ..utils import DummyObject, requires_backends


CONSTANT = None


def function(*args, **kwargs):
    requires_backends(function, ["torch"])


class FakeClass(metaclass=DummyObject):
    _backends = ["torch"]

    def __init__(self, *args, **kwargs):
        requires_backends(self, ["torch"])

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, ["torch"])

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, ["torch"])
'''
       __SCREAMING_SNAKE_CASE      :	List[str]					=		create_dummy_files({'''torch''': ['''CONSTANT''', '''function''', '''FakeClass''']} )
       self.assertEqual(dummy_files['''torch''']     ,						_A )








"""simple docstring"""



from __future__ import annotations

from collections.abc import Iterator
from typing import Any




class 			lowerCAmelCase__			:
   def __init__(		self      :	Any							,			snake_case__      :	Any							):


        '''simple docstring'''
        UpperCAmelCase__						:    Any							=							data
        UpperCAmelCase__						:    Node | None							=							None




class 			lowerCAmelCase__			:
   def __init__(		self      :	Dict							):


        '''simple docstring'''
        UpperCAmelCase__						:    Tuple							=							None
        UpperCAmelCase__						:    Optional[int]							=							None
   def __iter__(		self      :	Tuple							):


        '''simple docstring'''
        UpperCAmelCase__						:    Optional[int]							=							self.head
        while self.head:
             yield node.data
             UpperCAmelCase__						:    Optional[Any]							=							node.next
             if node == self.head:
                  break
   def __len__(		self      :	Tuple							):


        '''simple docstring'''
        return sum(1 for _ in self							)
   def __repr__(		self      :	str							):


        '''simple docstring'''
        return "->".join(str(snake_case__							) for item in iter(self							)							)
   def       __a							(		self      :	Optional[Any]							,			snake_case__      :	Any							):


        '''simple docstring'''
        self.insert_nth(len(self							)							,			snake_case__							)
   def       __a							(		self      :	Optional[Any]							,			snake_case__      :	Any							):


        '''simple docstring'''
        self.insert_nth(0							,			snake_case__							)
   def       __a							(		self      :	Any							,			snake_case__      :	int							,			snake_case__      :	Any							):


        '''simple docstring'''
        if index < 0 or index > len(self							):
             raise IndexError("list index out of range."							)
        UpperCAmelCase__						:    Any							=							Node(snake_case__							)
        if self.head is None:
             UpperCAmelCase__						:    Union[str, Any]							=							new_node  # first node points itself
             UpperCAmelCase__						:    List[str]							=							new_node
        elif index == 0:  # insert at head
             UpperCAmelCase__						:    Optional[Any]							=							self.head
             UpperCAmelCase__						:    List[Any]							=							new_node
        else:
             UpperCAmelCase__						:    Union[str, Any]							=							self.head
             for _ in range(index - 1							):
                  UpperCAmelCase__						:    Dict							=							temp.next
             UpperCAmelCase__						:    Tuple							=							temp.next
             UpperCAmelCase__						:    str							=							new_node
             if index == len(self							) - 1:  # insert at tail
                  UpperCAmelCase__						:    Union[str, Any]							=							new_node
   def       __a							(		self      :	List[Any]							):


        '''simple docstring'''
        return self.delete_nth(0							)
   def       __a							(		self      :	Optional[Any]							):


        '''simple docstring'''
        return self.delete_nth(len(self							) - 1							)
   def       __a							(		self      :	Tuple							,			snake_case__      :	int = 0							):


        '''simple docstring'''
        if not 0 <= index < len(self							):
             raise IndexError("list index out of range."							)
        UpperCAmelCase__						:    Union[str, Any]							=							self.head
        if self.head == self.tail:  # just one node
             UpperCAmelCase__						:    str							=							None
        elif index == 0:  # delete head node
             UpperCAmelCase__						:    List[Any]							=							self.tail.next.next
             UpperCAmelCase__						:    Dict							=							self.head.next
        else:
             UpperCAmelCase__						:    List[Any]							=							self.head
             for _ in range(index - 1							):
                  UpperCAmelCase__						:    Tuple							=							temp.next
             UpperCAmelCase__						:    Dict							=							temp.next
             UpperCAmelCase__						:    Dict							=							temp.next.next
             if index == len(self							) - 1:  # delete at tail
                  UpperCAmelCase__						:    int							=							temp
        return delete_node.data




   def       __a							(		self      :	Any							):


        '''simple docstring'''
        return len(self							) == 0




def 	SCREAMING_SNAKE_CASE__       (  )->		None:






     '''simple docstring'''



     UpperCAmelCase__						:    str							=							CircularLinkedList()
     assert len(snake_case				) == 0
     assert circular_linked_list.is_empty() is True
     assert str(snake_case				) == ""

     try:
          circular_linked_list.delete_front()
          raise AssertionError  # This should not happen
     except IndexError:
          assert True  # This should happen

     try:
          circular_linked_list.delete_tail()
          raise AssertionError  # This should not happen
     except IndexError:
          assert True  # This should happen

     try:
          circular_linked_list.delete_nth(-1				)
          raise AssertionError
     except IndexError:
          assert True

     try:
          circular_linked_list.delete_nth(0				)
          raise AssertionError
     except IndexError:
          assert True

     assert circular_linked_list.is_empty() is True
     for i in range(5				):
          assert len(snake_case				) == i
          circular_linked_list.insert_nth(snake_case			,					i + 1				)
     assert str(snake_case				) == "->".join(str(snake_case				) for i in range(1			,					6				)				)

     circular_linked_list.insert_tail(6				)
     assert str(snake_case				) == "->".join(str(snake_case				) for i in range(1			,					7				)				)
     circular_linked_list.insert_head(0				)
     assert str(snake_case				) == "->".join(str(snake_case				) for i in range(0			,					7				)				)

     assert circular_linked_list.delete_front() == 0
     assert circular_linked_list.delete_tail() == 6
     assert str(snake_case				) == "->".join(str(snake_case				) for i in range(1			,					6				)				)
     assert circular_linked_list.delete_nth(2				) == 3

     circular_linked_list.insert_nth(2			,					3				)
     assert str(snake_case				) == "->".join(str(snake_case				) for i in range(1			,					6				)				)

     assert circular_linked_list.is_empty() is False


if __name__ == "__main__":
 import doctest

 doctest.testmod()


