



import subprocess
import sys

from transformers import BertConfig, BertModel, BertTokenizer, pipeline
from transformers.testing_utils import TestCasePlus, require_torch


class 				_a						(       SCREAMING_SNAKE_CASE			):





							'''simple docstring'''

							@require_torch
							def 		_A	(							self				):







											"""simple docstring"""



											a__	:							str      						= '''
from transformers import BertConfig, BertModel, BertTokenizer, pipeline
        '''

											a__	:							List[Any]      						= '''
mname = "hf-internal-testing/tiny-random-bert"
BertConfig.from_pretrained(mname)
BertModel.from_pretrained(mname)
BertTokenizer.from_pretrained(mname)
pipe = pipeline(task="fill-mask", model=mname)
print("success")
        '''

											a__	:							str      						= '''
import socket
def offline_socket(*args, **kwargs): raise RuntimeError("Offline mode is enabled, we shouldn\'t access internet")
socket.socket = offline_socket
        '''

											# Force fetching the files so that we can use the cache
											a__	:							List[str]      						= '''hf-internal-testing/tiny-random-bert'''
											BertConfig.from_pretrained(lowerCamelCase_				)
											BertModel.from_pretrained(lowerCamelCase_				)
											BertTokenizer.from_pretrained(lowerCamelCase_				)
											pipeline(task="fill-mask" ,					model=lowerCamelCase_				)

											# baseline - just load from_pretrained with normal network
											a__	:							Tuple      						= [sys.executable, '''-c''', '''\n'''.join([load, run, mock]				)]

											# should succeed
											a__	:							Tuple      						= self.get_env()
											# should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
											a__	:							str      						= '''1'''
											a__	:							List[str]      						= subprocess.run(lowerCamelCase_ ,					env=lowerCamelCase_ ,					check=lowerCamelCase_ ,					capture_output=lowerCamelCase_				)
											self.assertEqual(result.returncode ,					0 ,					result.stderr				)
											self.assertIn("success" ,					result.stdout.decode()				)



							@require_torch
							def 		_A	(							self				):







											"""simple docstring"""



											a__	:							Union[str, Any]      						= '''
from transformers import BertConfig, BertModel, BertTokenizer, pipeline
        '''

											a__	:							Tuple      						= '''
mname = "hf-internal-testing/tiny-random-bert"
BertConfig.from_pretrained(mname)
BertModel.from_pretrained(mname)
BertTokenizer.from_pretrained(mname)
pipe = pipeline(task="fill-mask", model=mname)
print("success")
        '''

											a__	:							Optional[Any]      						= '''
import socket
def offline_socket(*args, **kwargs): raise socket.error("Faking flaky internet")
socket.socket = offline_socket
        '''

											# Force fetching the files so that we can use the cache
											a__	:							int      						= '''hf-internal-testing/tiny-random-bert'''
											BertConfig.from_pretrained(lowerCamelCase_				)
											BertModel.from_pretrained(lowerCamelCase_				)
											BertTokenizer.from_pretrained(lowerCamelCase_				)
											pipeline(task="fill-mask" ,					model=lowerCamelCase_				)

											# baseline - just load from_pretrained with normal network
											a__	:							Tuple      						= [sys.executable, '''-c''', '''\n'''.join([load, run, mock]				)]

											# should succeed
											a__	:							Tuple      						= self.get_env()
											a__	:							List[str]      						= subprocess.run(lowerCamelCase_ ,					env=lowerCamelCase_ ,					check=lowerCamelCase_ ,					capture_output=lowerCamelCase_				)
											self.assertEqual(result.returncode ,					0 ,					result.stderr				)
											self.assertIn("success" ,					result.stdout.decode()				)



							@require_torch
							def 		_A	(							self				):







											"""simple docstring"""



											a__	:							Optional[Any]      						= '''
from transformers import BertConfig, BertModel, BertTokenizer
        '''

											a__	:							Optional[Any]      						= '''
mname = "hf-internal-testing/tiny-random-bert-sharded"
BertConfig.from_pretrained(mname)
BertModel.from_pretrained(mname)
print("success")
        '''

											a__	:							Optional[int]      						= '''
import socket
def offline_socket(*args, **kwargs): raise ValueError("Offline mode is enabled")
socket.socket = offline_socket
        '''

											# baseline - just load from_pretrained with normal network
											a__	:							int      						= [sys.executable, '''-c''', '''\n'''.join([load, run]				)]

											# should succeed
											a__	:							List[Any]      						= self.get_env()
											a__	:							Optional[int]      						= subprocess.run(lowerCamelCase_ ,					env=lowerCamelCase_ ,					check=lowerCamelCase_ ,					capture_output=lowerCamelCase_				)
											self.assertEqual(result.returncode ,					0 ,					result.stderr				)
											self.assertIn("success" ,					result.stdout.decode()				)

											# next emulate no network
											a__	:							str      						= [sys.executable, '''-c''', '''\n'''.join([load, mock, run]				)]

											# Doesn't fail anymore since the model is in the cache due to other tests, so commenting this.
											# env["TRANSFORMERS_OFFLINE"] = "0"
											# result = subprocess.run(cmd, env=env, check=False, capture_output=True)
											# self.assertEqual(result.returncode, 1, result.stderr)

											# should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
											a__	:							Any      						= '''1'''
											a__	:							Optional[Any]      						= subprocess.run(lowerCamelCase_ ,					env=lowerCamelCase_ ,					check=lowerCamelCase_ ,					capture_output=lowerCamelCase_				)
											self.assertEqual(result.returncode ,					0 ,					result.stderr				)
											self.assertIn("success" ,					result.stdout.decode()				)



							@require_torch
							def 		_A	(							self				):







											"""simple docstring"""



											a__	:							List[str]      						= '''
from transformers import pipeline
        '''
											a__	:							Optional[Any]      						= '''
mname = "hf-internal-testing/tiny-random-bert"
pipe = pipeline(model=mname)
        '''

											a__	:							Union[str, Any]      						= '''
import socket
def offline_socket(*args, **kwargs): raise socket.error("Offline mode is enabled")
socket.socket = offline_socket
        '''
											a__	:							Optional[int]      						= self.get_env()
											a__	:							Any      						= '''1'''
											a__	:							Tuple      						= [sys.executable, '''-c''', '''\n'''.join([load, mock, run]				)]
											a__	:							Any      						= subprocess.run(lowerCamelCase_ ,					env=lowerCamelCase_ ,					check=lowerCamelCase_ ,					capture_output=lowerCamelCase_				)
											self.assertEqual(result.returncode ,					1 ,					result.stderr				)
											self.assertIn(
											    "You cannot infer task automatically within `pipeline` when using offline mode" ,					result.stderr.decode().replace("\n" ,					""				) ,					)




							@require_torch
							def 		_A	(							self				):







											"""simple docstring"""



											a__	:							Optional[int]      						= '''
from transformers import AutoModel
        '''
											a__	:							Optional[int]      						= '''
mname = "hf-internal-testing/test_dynamic_model"
AutoModel.from_pretrained(mname, trust_remote_code=True)
print("success")
        '''

											# baseline - just load from_pretrained with normal network
											a__	:							Tuple      						= [sys.executable, '''-c''', '''\n'''.join([load, run]				)]

											# should succeed
											a__	:							Optional[Any]      						= self.get_env()
											a__	:							int      						= subprocess.run(lowerCamelCase_ ,					env=lowerCamelCase_ ,					check=lowerCamelCase_ ,					capture_output=lowerCamelCase_				)
											self.assertEqual(result.returncode ,					0 ,					result.stderr				)
											self.assertIn("success" ,					result.stdout.decode()				)

											# should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
											a__	:							Tuple      						= '''1'''
											a__	:							Tuple      						= subprocess.run(lowerCamelCase_ ,					env=lowerCamelCase_ ,					check=lowerCamelCase_ ,					capture_output=lowerCamelCase_				)
											self.assertEqual(result.returncode ,					0 ,					result.stderr				)
											self.assertIn("success" ,					result.stdout.decode()				)



'''simple docstring'''

import baseaa







def __UpperCamelCase( _A       :					str     ):
   '''simple docstring'''
   return baseaa.baaencode(string.encode('''utf-8'''     )     )







def __UpperCamelCase( _A       :					bytes     ):
   '''simple docstring'''
   return baseaa.baadecode(_A     ).decode('''utf-8'''     )


if __name__ == "__main__":
  UpperCamelCase__  :						List[str]					=      'Hello World!'
  UpperCamelCase__  :						str					=      baseaa_encode(test)
  print(encoded)

  UpperCamelCase__  :						int					=      baseaa_decode(encoded)
  print(decoded)




