


'''simple docstring'''
import subprocess
import sys

from transformers import BertConfig, BertModel, BertTokenizer, pipeline
from transformers.testing_utils import TestCasePlus, require_torch
class   lowercase      (				SCREAMING_SNAKE_CASE__   ):

		"""simple docstring"""

		@require_torch
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Any				   =					'''
from transformers import BertConfig, BertModel, BertTokenizer, pipeline
        '''

							UpperCamelCase__  :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")
        '''

							UpperCamelCase__  :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
							UpperCamelCase__  :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
							UpperCamelCase__  :str				   =					[sys.executable, '''-c''', '''\n'''.join([load, run, mock]				)]

							# should succeed
							UpperCamelCase__  :str				   =					self.get_env()
							# should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
							UpperCamelCase__  :Tuple				   =					'''1'''
							UpperCamelCase__  :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        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Tuple				   =					'''
from transformers import BertConfig, BertModel, BertTokenizer, pipeline
        '''

							UpperCamelCase__  :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")
        '''

							UpperCamelCase__  :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
							UpperCamelCase__  :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
							UpperCamelCase__  :int				   =					[sys.executable, '''-c''', '''\n'''.join([load, run, mock]				)]

							# should succeed
							UpperCamelCase__  :Union[str, Any]				   =					self.get_env()
							UpperCamelCase__  :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()				)




		@require_torch
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Any				   =					'''
from transformers import BertConfig, BertModel, BertTokenizer
        '''

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

							UpperCamelCase__  :Dict				   =					'''
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
							UpperCamelCase__  :List[str]				   =					[sys.executable, '''-c''', '''\n'''.join([load, run]				)]

							# should succeed
							UpperCamelCase__  :Optional[Any]				   =					self.get_env()
							UpperCamelCase__  :str				   =					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
							UpperCamelCase__  :List[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
							UpperCamelCase__  :Union[str, Any]				   =					'''1'''
							UpperCamelCase__  :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        lowerCAmelCase__							(						self				):

							'''simple docstring'''


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

							UpperCamelCase__  :Any				   =					'''
import socket
def offline_socket(*args, **kwargs): raise socket.error("Offline mode is enabled")
socket.socket = offline_socket
        '''
							UpperCamelCase__  :int				   =					self.get_env()
							UpperCamelCase__  :str				   =					'''1'''
							UpperCamelCase__  :Tuple				   =					[sys.executable, '''-c''', '''\n'''.join([load, mock, run]				)]
							UpperCamelCase__  :Union[str, 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        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Dict				   =					'''
from transformers import AutoModel
        '''
							UpperCamelCase__  :List[Any]				   =					'''
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
							UpperCamelCase__  :Optional[int]				   =					[sys.executable, '''-c''', '''\n'''.join([load, run]				)]

							# should succeed
							UpperCamelCase__  :Any				   =					self.get_env()
							UpperCamelCase__  :Tuple				   =					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
							UpperCamelCase__  :Any				   =					'''1'''
							UpperCamelCase__  :int				   =					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 requests

a_					=     """https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey="""







def 						__lowercase	(  snake_case_    :    str		)  ->None:



    '''simple docstring'''







    __A       :		str							=	requests.get(_NEWS_API + bbc_news_api_key		).json()
    # each article in the list is a dict
    for i, article in enumerate(bbc_news_page['''articles''']							,1		):
        print(F"""{i}.) {article['title']}"""		)


if __name__ == "__main__":
       fetch_bbc_news(bbc_news_api_key="""<Your BBC News API key goes here>""")




