
'''simple docstring'''






import subprocess
import sys

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

class  UpperCAmelCase__						(       A ):



    @require_torch
    def   lowerCamelCase_  (	self      :       int     ):
          # this test is a bit tricky since TRANSFORMERS_OFFLINE can only be changed before
          # `transformers` is loaded, and it's too late for inside pytest - so we are changing it
          # while running an external program

          # python one-liner segments

          # this must be loaded before socket.socket is monkey-patched
          _lowerCamelCase				:   Optional[int]								=   "\nfrom transformers import BertConfig, BertModel, BertTokenizer, pipeline\n        "

          _lowerCamelCase				:   Optional[int]								=   "\nmname = \"hf-internal-testing/tiny-random-bert\"\nBertConfig.from_pretrained(mname)\nBertModel.from_pretrained(mname)\nBertTokenizer.from_pretrained(mname)\npipe = pipeline(task=\"fill-mask\", model=mname)\nprint(\"success\")\n        "

          _lowerCamelCase				:   List[Any]								=   "\nimport socket\ndef offline_socket(*args, **kwargs): raise RuntimeError(\"Offline mode is enabled, we shouldn't access internet\")\nsocket.socket = offline_socket\n        "

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

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

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



    @require_torch
    def   lowerCamelCase_  (	self      :       List[str]     ):
          # python one-liner segments
          # this must be loaded before socket.socket is monkey-patched
          _lowerCamelCase				:   Any								=   "\nfrom transformers import BertConfig, BertModel, BertTokenizer, pipeline\n        "

          _lowerCamelCase				:   Union[str, Any]								=   "\nmname = \"hf-internal-testing/tiny-random-bert\"\nBertConfig.from_pretrained(mname)\nBertModel.from_pretrained(mname)\nBertTokenizer.from_pretrained(mname)\npipe = pipeline(task=\"fill-mask\", model=mname)\nprint(\"success\")\n        "

          _lowerCamelCase				:   Any								=   "\nimport socket\ndef offline_socket(*args, **kwargs): raise socket.error(\"Faking flaky internet\")\nsocket.socket = offline_socket\n        "

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

          # baseline - just load from_pretrained with normal network
          _lowerCamelCase				:   Union[str, Any]								=   [sys.executable, "-c", "\n".join([load, run, mock]     )]

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



    @require_torch
    def   lowerCamelCase_  (	self      :       Tuple     ):
          # this test is a bit tricky since TRANSFORMERS_OFFLINE can only be changed before
          # `transformers` is loaded, and it's too late for inside pytest - so we are changing it
          # while running an external program

          # python one-liner segments

          # this must be loaded before socket.socket is monkey-patched
          _lowerCamelCase				:   List[str]								=   "\nfrom transformers import BertConfig, BertModel, BertTokenizer\n        "

          _lowerCamelCase				:   List[Any]								=   "\nmname = \"hf-internal-testing/tiny-random-bert-sharded\"\nBertConfig.from_pretrained(mname)\nBertModel.from_pretrained(mname)\nprint(\"success\")\n        "

          _lowerCamelCase				:   int								=   "\nimport socket\ndef offline_socket(*args, **kwargs): raise ValueError(\"Offline mode is enabled\")\nsocket.socket = offline_socket\n        "

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

          # should succeed
          _lowerCamelCase				:   Dict								=   self.get_env()
          _lowerCamelCase				:   Any								=   subprocess.run(__A,env=__A,check=__A,capture_output=__A     )
          self.assertEqual(result.returncode,0,result.stderr     )
          self.assertIn("success",result.stdout.decode()     )

          # next emulate no network
          _lowerCamelCase				:   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
          _lowerCamelCase				:   List[Any]								=   "1"
          _lowerCamelCase				:   int								=   subprocess.run(__A,env=__A,check=__A,capture_output=__A     )
          self.assertEqual(result.returncode,0,result.stderr     )
          self.assertIn("success",result.stdout.decode()     )



    @require_torch
    def   lowerCamelCase_  (	self      :       Tuple     ):
          _lowerCamelCase				:   Any								=   "\nfrom transformers import pipeline\n        "
          _lowerCamelCase				:   List[Any]								=   "\nmname = \"hf-internal-testing/tiny-random-bert\"\npipe = pipeline(model=mname)\n        "

          _lowerCamelCase				:   str								=   "\nimport socket\ndef offline_socket(*args, **kwargs): raise socket.error(\"Offline mode is enabled\")\nsocket.socket = offline_socket\n        "
          _lowerCamelCase				:   Union[str, Any]								=   self.get_env()
          _lowerCamelCase				:   Any								=   "1"
          _lowerCamelCase				:   List[str]								=   [sys.executable, "-c", "\n".join([load, mock, run]     )]
          _lowerCamelCase				:   Tuple								=   subprocess.run(__A,env=__A,check=__A,capture_output=__A     )
          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      :       Optional[Any]     ):
          _lowerCamelCase				:   Dict								=   "\nfrom transformers import AutoModel\n        "
          _lowerCamelCase				:   List[Any]								=   "\nmname = \"hf-internal-testing/test_dynamic_model\"\nAutoModel.from_pretrained(mname, trust_remote_code=True)\nprint(\"success\")\n        "

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

          # should succeed
          _lowerCamelCase				:   Optional[Any]								=   self.get_env()
          _lowerCamelCase				:   Tuple								=   subprocess.run(__A,env=__A,check=__A,capture_output=__A     )
          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
          _lowerCamelCase				:   str								=   "1"
          _lowerCamelCase				:   int								=   subprocess.run(__A,env=__A,check=__A,capture_output=__A     )
          self.assertEqual(result.returncode,0,result.stderr     )
          self.assertIn("success",result.stdout.decode()     )



'''simple docstring'''






def 		A_       (	_lowerCAmelCase   :    float							):



      """simple docstring"""




      return 10 - x * x







def 		A_       (	_lowerCAmelCase   :    float				,	_lowerCAmelCase   :    float							):



      """simple docstring"""




      if equation(_lowerCAmelCase							) * equation(_lowerCAmelCase							) >= 0:
            raise ValueError("Wrong space!"							)

      _lowerCamelCase				:   List[str]								=   a
      while (b - a) >= 0.0_1:
            # Find middle point
            _lowerCamelCase				:   Union[str, Any]								=   (a + b) / 2
            # Check if middle point is root
            if equation(_lowerCAmelCase							) == 0.0:
                  break
            # Decide the side to repeat the steps
            if equation(_lowerCAmelCase							) * equation(_lowerCAmelCase							) < 0:
                  _lowerCamelCase				:   Union[str, Any]								=   c
            else:
                  _lowerCamelCase				:   Any								=   c
      return c


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 print(bisection(-2, 5))
 print(bisection(0, 6))