





'''simple docstring'''


import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible






class     lowerCAmelCase__ (				unittest.TestCase    ):

       '''simple docstring'''

       def 			__snake_case      ( self					:				Dict						):
              UpperCAmelCase  =						[
                  '''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(a__						)						)

       def 			__snake_case      ( self					:				Union[str, Any]						):
              UpperCAmelCase  =						[
                  '''unet/diffusion_pytorch_model.bin''',
                  '''unet/diffusion_pytorch_model.safetensors''',
              ]
              self.assertTrue(is_safetensors_compatible(a__						)						)

       def 			__snake_case      ( self					:				Union[str, Any]						):
              UpperCAmelCase  =						[
                  '''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(a__						)						)

       def 			__snake_case      ( self					:				Union[str, Any]						):
              UpperCAmelCase  =						[
                  '''text_encoder/pytorch_model.bin''',
                  '''text_encoder/model.safetensors''',
              ]
              self.assertTrue(is_safetensors_compatible(a__						)						)

       def 			__snake_case      ( self					:				Dict						):
              UpperCAmelCase  =						[
                  '''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(a__						)						)

       def 			__snake_case      ( self					:				Tuple						):
              UpperCAmelCase  =						[
                  '''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''',
              ]
              UpperCAmelCase  =						'''fp16'''
              self.assertTrue(is_safetensors_compatible(a__       ,     variant=a__						)						)

       def 			__snake_case      ( self					:				Tuple						):
              UpperCAmelCase  =						[
                  '''unet/diffusion_pytorch_model.fp16.bin''',
                  '''unet/diffusion_pytorch_model.fp16.safetensors''',
              ]
              UpperCAmelCase  =						'''fp16'''
              self.assertTrue(is_safetensors_compatible(a__       ,     variant=a__						)						)

       def 			__snake_case      ( self					:				Any						):
              # pass variant but use the non-variant filenames
              UpperCAmelCase  =						[
                  '''unet/diffusion_pytorch_model.bin''',
                  '''unet/diffusion_pytorch_model.safetensors''',
              ]
              UpperCAmelCase  =						'''fp16'''
              self.assertTrue(is_safetensors_compatible(a__       ,     variant=a__						)						)

       def 			__snake_case      ( self					:				Optional[int]						):
              UpperCAmelCase  =						[
                  '''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',
              ]
              UpperCAmelCase  =						'''fp16'''
              self.assertFalse(is_safetensors_compatible(a__       ,     variant=a__						)						)

       def 			__snake_case      ( self					:				List[str]						):
              UpperCAmelCase  =						[
                  '''text_encoder/pytorch_model.fp16.bin''',
                  '''text_encoder/model.fp16.safetensors''',
              ]
              UpperCAmelCase  =						'''fp16'''
              self.assertTrue(is_safetensors_compatible(a__       ,     variant=a__						)						)

       def 			__snake_case      ( self					:				str						):
              # pass variant but use the non-variant filenames
              UpperCAmelCase  =						[
                  '''text_encoder/pytorch_model.bin''',
                  '''text_encoder/model.safetensors''',
              ]
              UpperCAmelCase  =						'''fp16'''
              self.assertTrue(is_safetensors_compatible(a__       ,     variant=a__						)						)



       def 			__snake_case      ( self					:				Optional[int]						):
              UpperCAmelCase  =						[
                  '''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''',
              ]
              UpperCAmelCase  =						'''fp16'''
              self.assertFalse(is_safetensors_compatible(a__       ,     variant=a__						)						)










'''simple docstring'''







import os
import time

import pytest

from datasets.utils.filelock import FileLock, Timeout





def 		_UpperCAmelCase (				__A				: int   ):
				a_		:	Optional[Any]									=   FileLock(str(tmpdir / '''foo.lock'''   )   )
				a_		:	Union[str, Any]									=   FileLock(str(tmpdir / '''foo.lock'''   )   )
				a_		:	List[Any]									=   0.01
				with locka.acquire():
								with pytest.raises(__A   ):
												a_		:	List[Any]									=   time.time()
												locka.acquire(__A   )
												assert time.time() - _start > timeout





def 		_UpperCAmelCase (				__A				: Tuple   ):
				a_		:	Tuple									=   '''a''' * 10_00 + '''.lock'''
				a_		:	List[Any]									=   FileLock(str(tmpdir / filename   )   )
				assert locka._lock_file.endswith('''.lock'''   )
				assert not locka._lock_file.endswith(__A   )
				assert len(os.path.basename(locka._lock_file   )   ) <= 2_55
				a_		:	Optional[int]									=   FileLock(tmpdir / filename   )
				with locka.acquire():
								with pytest.raises(__A   ):
												locka.acquire(0   )




