


"""simple docstring"""







import os
import unittest

from transformers.models.bartpho.tokenization_bartpho import VOCAB_FILES_NAMES, BartphoTokenizer
from transformers.testing_utils import get_tests_dir

from ...test_tokenization_common import TokenizerTesterMixin


lowerCAmelCase__				    =       get_tests_dir('''fixtures/test_sentencepiece_bpe.model''')


class 				SCREAMING_SNAKE_CASE__    (		lowercase       ,   unittest.TestCase    ):
       """simple docstring"""


       a  :    List[str]       =BartphoTokenizer
       a  :    Union[str, Any]       =False
       a  :    Tuple       =True

       def 	lowercase__							(						self						):






         """simple docstring"""





         super().setUp()

         lowerCAmelCase					:					Union[str, Any]								=							["▁This", "▁is", "▁a", "▁t", "est"]
         lowerCAmelCase					:					int								=							dict(zip(snake_case__		,					range(len(snake_case__						)						)						)						)
         lowerCAmelCase					:					Union[str, Any]								=							{"unk_token": "<unk>"}

         lowerCAmelCase					:					Tuple								=							os.path.join(self.tmpdirname		,					VOCAB_FILES_NAMES["monolingual_vocab_file"]						)
         with open(self.monolingual_vocab_file		,					"w"		,					encoding="utf-8"						) as fp:
           for token in vocab_tokens:
             fp.write(f"""{token} {vocab_tokens[token]}\n"""						)

         lowerCAmelCase					:					Dict								=							BartphoTokenizer(snake_case__		,					self.monolingual_vocab_file		,					**self.special_tokens_map						)
         tokenizer.save_pretrained(self.tmpdirname						)

       def 	lowercase__							(						self		,					**snake_case__						):






         """simple docstring"""





         kwargs.update(self.special_tokens_map						)
         return BartphoTokenizer.from_pretrained(self.tmpdirname		,					**snake_case__						)

       def 	lowercase__							(						self		,					snake_case__						):






         """simple docstring"""





         lowerCAmelCase					:					List[Any]								=							"This is a là test"
         lowerCAmelCase					:					str								=							"This is a<unk><unk> test"
         return input_text, output_text







       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					str								=							BartphoTokenizer(snake_case__		,					self.monolingual_vocab_file		,					**self.special_tokens_map						)
         lowerCAmelCase					:					List[str]								=							"This is a là test"
         lowerCAmelCase					:					List[str]								=							"▁This ▁is ▁a ▁l à ▁t est".split()
         lowerCAmelCase					:					Any								=							tokenizer.tokenize(snake_case__						)
         self.assertListEqual(snake_case__		,					snake_case__						)

         lowerCAmelCase					:					Any								=							tokens + [tokenizer.unk_token]
         lowerCAmelCase					:					Union[str, Any]								=							[4, 5, 6, 3, 3, 7, 8, 3]
         self.assertListEqual(tokenizer.convert_tokens_to_ids(snake_case__						)		,					snake_case__						)









"""simple docstring"""







import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible


class 				SCREAMING_SNAKE_CASE__    (		unittest.TestCase    ):
       """simple docstring"""


       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					int								=							[
             "safety_checker/pytorch_model.bin",
             "safety_checker/model.safetensors",
             "vae/diffusion_pytorch_model.bin",
             "vae/diffusion_pytorch_model.safetensors",
             "text_encoder/pytorch_model.bin",
             "text_encoder/model.safetensors",
             "unet/diffusion_pytorch_model.bin",
             "unet/diffusion_pytorch_model.safetensors",
         ]
         self.assertTrue(is_safetensors_compatible(snake_case__						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Dict								=							[
             "unet/diffusion_pytorch_model.bin",
             "unet/diffusion_pytorch_model.safetensors",
         ]
         self.assertTrue(is_safetensors_compatible(snake_case__						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Optional[Any]								=							[
             "safety_checker/pytorch_model.bin",
             "safety_checker/model.safetensors",
             "vae/diffusion_pytorch_model.bin",
             "vae/diffusion_pytorch_model.safetensors",
             "text_encoder/pytorch_model.bin",
             "text_encoder/model.safetensors",
             "unet/diffusion_pytorch_model.bin",
             # Removed: 'unet/diffusion_pytorch_model.safetensors',
         ]
         self.assertFalse(is_safetensors_compatible(snake_case__						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					List[str]								=							[
             "text_encoder/pytorch_model.bin",
             "text_encoder/model.safetensors",
         ]
         self.assertTrue(is_safetensors_compatible(snake_case__						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Tuple								=							[
             "safety_checker/pytorch_model.bin",
             "safety_checker/model.safetensors",
             "vae/diffusion_pytorch_model.bin",
             "vae/diffusion_pytorch_model.safetensors",
             "text_encoder/pytorch_model.bin",
             # Removed: 'text_encoder/model.safetensors',
             "unet/diffusion_pytorch_model.bin",
             "unet/diffusion_pytorch_model.safetensors",
         ]
         self.assertFalse(is_safetensors_compatible(snake_case__						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					List[Any]								=							[
             "safety_checker/pytorch_model.fp16.bin",
             "safety_checker/model.fp16.safetensors",
             "vae/diffusion_pytorch_model.fp16.bin",
             "vae/diffusion_pytorch_model.fp16.safetensors",
             "text_encoder/pytorch_model.fp16.bin",
             "text_encoder/model.fp16.safetensors",
             "unet/diffusion_pytorch_model.fp16.bin",
             "unet/diffusion_pytorch_model.fp16.safetensors",
         ]
         lowerCAmelCase					:					Union[str, Any]								=							"fp16"
         self.assertTrue(is_safetensors_compatible(snake_case__		,					variant=snake_case__						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Optional[int]								=							[
             "unet/diffusion_pytorch_model.fp16.bin",
             "unet/diffusion_pytorch_model.fp16.safetensors",
         ]
         lowerCAmelCase					:					Tuple								=							"fp16"
         self.assertTrue(is_safetensors_compatible(snake_case__		,					variant=snake_case__						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					List[Any]								=							[
             "unet/diffusion_pytorch_model.bin",
             "unet/diffusion_pytorch_model.safetensors",
         ]
         lowerCAmelCase					:					Union[str, Any]								=							"fp16"
         self.assertTrue(is_safetensors_compatible(snake_case__		,					variant=snake_case__						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					List[Any]								=							[
             "safety_checker/pytorch_model.fp16.bin",
             "safety_checker/model.fp16.safetensors",
             "vae/diffusion_pytorch_model.fp16.bin",
             "vae/diffusion_pytorch_model.fp16.safetensors",
             "text_encoder/pytorch_model.fp16.bin",
             "text_encoder/model.fp16.safetensors",
             "unet/diffusion_pytorch_model.fp16.bin",
             # Removed: 'unet/diffusion_pytorch_model.fp16.safetensors',
         ]
         lowerCAmelCase					:					Dict								=							"fp16"
         self.assertFalse(is_safetensors_compatible(snake_case__		,					variant=snake_case__						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					str								=							[
             "text_encoder/pytorch_model.fp16.bin",
             "text_encoder/model.fp16.safetensors",
         ]
         lowerCAmelCase					:					int								=							"fp16"
         self.assertTrue(is_safetensors_compatible(snake_case__		,					variant=snake_case__						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					str								=							[
             "text_encoder/pytorch_model.bin",
             "text_encoder/model.safetensors",
         ]
         lowerCAmelCase					:					Tuple								=							"fp16"
         self.assertTrue(is_safetensors_compatible(snake_case__		,					variant=snake_case__						)						)







       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					int								=							[
             "safety_checker/pytorch_model.fp16.bin",
             "safety_checker/model.fp16.safetensors",
             "vae/diffusion_pytorch_model.fp16.bin",
             "vae/diffusion_pytorch_model.fp16.safetensors",
             "text_encoder/pytorch_model.fp16.bin",
             # 'text_encoder/model.fp16.safetensors',
             "unet/diffusion_pytorch_model.fp16.bin",
             "unet/diffusion_pytorch_model.fp16.safetensors",
         ]
         lowerCAmelCase					:					List[Any]								=							"fp16"
         self.assertFalse(is_safetensors_compatible(snake_case__		,					variant=snake_case__						)						)





