



import os
import sys
import unittest


snake_case__					:     Optional[Any]    		=   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
snake_case__					:     Optional[int]    		=   os.path.join(git_repo_path, """src""", """transformers""")

snake_case__					:     Tuple    		=   """
{0} = None
"""

snake_case__					:     List[str]    		=   """
class {0}(metaclass=DummyObject):
    _backends = {1}

    def __init__(self, *args, **kwargs):
        requires_backends(self, {1})
"""


snake_case__					:     Dict    		=   """
def {0}(*args, **kwargs):
    requires_backends({0}, {1})
"""

class   _A   ( unittest.TestCase	):


						'''simple docstring'''





						def     _snake_case	(	self	:							str	):






							'''simple docstring'''



							__lowercase		       =			find_backend("    _import_structure[\"models.albert\"].append(\"AlbertTokenizerFast\")"	)
							self.assertIsNone(lowerCamelCase	)

							__lowercase		       =			find_backend("    if not is_tokenizers_available():"	)
							self.assertEqual(lowerCamelCase							,      "tokenizers"	)

							__lowercase		       =			find_backend("    if not is_tensorflow_text_available():"	)
							self.assertEqual(lowerCamelCase							,      "tensorflow_text"	)

							__lowercase		       =			find_backend("    if not (is_sentencepiece_available() and is_tokenizers_available()):"	)
							self.assertEqual(lowerCamelCase							,      "sentencepiece_and_tokenizers"	)

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

							__lowercase		       =			find_backend(
							    "    if not (is_sentencepiece_available() and is_tokenizers_available() and is_vision_available()):"	)
							self.assertEqual(lowerCamelCase							,      "sentencepiece_and_tokenizers_and_vision"	)



						def     _snake_case	(	self	:							Optional[int]	):






							'''simple docstring'''



							__lowercase		       =			read_init()
							# We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
							self.assertIn("torch"							,      lowerCamelCase	)
							self.assertIn("tensorflow_text"							,      lowerCamelCase	)
							self.assertIn("sentencepiece_and_tokenizers"							,      lowerCamelCase	)

							# Likewise, we can't assert on the exact content of a key
							self.assertIn("BertModel"							,      objects["torch"]	)
							self.assertIn("TFBertModel"							,      objects["tf"]	)
							self.assertIn("FlaxBertModel"							,      objects["flax"]	)
							self.assertIn("BertModel"							,      objects["torch"]	)
							self.assertIn("TFBertTokenizer"							,      objects["tensorflow_text"]	)
							self.assertIn("convert_slow_tokenizer"							,      objects["sentencepiece_and_tokenizers"]	)



						def     _snake_case	(	self	:							Optional[int]	):






							'''simple docstring'''



							__lowercase		       =			create_dummy_object("CONSTANT"							,      "'torch'"	)
							self.assertEqual(lowerCamelCase							,      "\nCONSTANT = None\n"	)

							__lowercase		       =			create_dummy_object("function"							,      "'torch'"	)
							self.assertEqual(
							    lowerCamelCase							,      "\ndef function(*args, **kwargs):\n    requires_backends(function, 'torch')\n"	)

							__lowercase		       =			"\nclass FakeClass(metaclass=DummyObject):\n    _backends = 'torch'\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, 'torch')\n"
							__lowercase		       =			create_dummy_object("FakeClass"							,      "'torch'"	)
							self.assertEqual(lowerCamelCase							,      lowerCamelCase	)



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






							'''simple docstring'''



							__lowercase		       =			"# This file is autogenerated by the command `make fix-copies`, do not edit.\nfrom ..utils import DummyObject, requires_backends\n\n\nCONSTANT = None\n\n\ndef function(*args, **kwargs):\n    requires_backends(function, [\"torch\"])\n\n\nclass FakeClass(metaclass=DummyObject):\n    _backends = [\"torch\"]\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, [\"torch\"])\n"
							__lowercase		       =			create_dummy_files({"torch": ["CONSTANT", "function", "FakeClass"]}	)
							self.assertEqual(dummy_files["torch"]							,      lowerCamelCase	)








from __future__ import annotations

from typing import Any

class   _A   :


						'''simple docstring'''





						def __init__(	self	:							Union[str, Any]							,      lowerCamelCase	:							int	):






							'''simple docstring'''



							__lowercase		       =			num_of_nodes
							__lowercase		       =			[]
							__lowercase		       =			{}



						def     _snake_case	(	self	:							Dict							,      lowerCamelCase	:							int							,      lowerCamelCase	:							int							,      lowerCamelCase	:							int	):






							'''simple docstring'''



							self.m_edges.append([u_node, v_node, weight]	)



						def     _snake_case	(	self	:							List[Any]							,      lowerCamelCase	:							int	):






							'''simple docstring'''



							if self.m_component[u_node] == u_node:
								return u_node
							return self.find_component(self.m_component[u_node]	)



						def     _snake_case	(	self	:							Union[str, Any]							,      lowerCamelCase	:							int	):






							'''simple docstring'''



							if self.m_component[u_node] != u_node:
								for k in self.m_component:
									__lowercase		       =			self.find_component(lowerCamelCase	)



						def     _snake_case	(	self	:							Union[str, Any]							,      lowerCamelCase	:							list[int]							,      lowerCamelCase	:							int							,      lowerCamelCase	:							int	):






							'''simple docstring'''



							if component_size[u_node] <= component_size[v_node]:
								__lowercase		       =			v_node
								component_size[v_node] += component_size[u_node]
								self.set_component(lowerCamelCase	)

							elif component_size[u_node] >= component_size[v_node]:
								__lowercase		       =			self.find_component(lowerCamelCase	)
								component_size[u_node] += component_size[v_node]
								self.set_component(lowerCamelCase	)



						def     _snake_case	(	self	:							Any	):






							'''simple docstring'''



							__lowercase		       =			[]
							__lowercase		       =			0

							__lowercase		       =			[-1] * self.m_num_of_nodes

							# A list of components (initialized to all of the nodes)
							for node in range(self.m_num_of_nodes	):
								self.m_component.update({node: node}	)
								component_size.append(1	)

							__lowercase		       =			self.m_num_of_nodes

							while num_of_components > 1:
								for edge in self.m_edges:
									__lowercase       ,    __lowercase       ,    __lowercase		       =			edge

									__lowercase		       =			self.m_component[u]
									__lowercase		       =			self.m_component[v]

									if u_component != v_component:

										for component in (u_component, v_component):
											if (
											    minimum_weight_edge[component] == -1
											    or minimum_weight_edge[component][2] > w
											):
												__lowercase		       =			[u, v, w]

								for edge in minimum_weight_edge:
									if isinstance(lowerCamelCase							,      lowerCamelCase	):
										__lowercase       ,    __lowercase       ,    __lowercase		       =			edge

										__lowercase		       =			self.m_component[u]
										__lowercase		       =			self.m_component[v]

										if u_component != v_component:
											mst_weight += w
											self.union(lowerCamelCase							,      lowerCamelCase							,      lowerCamelCase	)
											print(f"""Added edge [{u} - {v}]\nAdded weight: {w}\n"""	)
											num_of_components -= 1

								__lowercase		       =			[-1] * self.m_num_of_nodes
							print(f"""The total weight of the minimal spanning tree is: {mst_weight}"""	)



def    snake_case_				(    ):
	pass


if __name__ == "__main__":
	import doctest

	doctest.testmod()



