

'''simple docstring'''

import unittest

from transformers.testing_utils import CaptureStdout
from transformers.tools.python_interpreter import evaluate







def    lowercase__			(				__UpperCamelCase   )->			Optional[int]:
      return x + 2






class     a_						(      unittest.TestCase    ):

  def   A__						(				self				)  ->				Optional[int]:



        """simple docstring"""






        UpperCamelCase      = """x = 3"""
        UpperCamelCase      = {}
        UpperCamelCase      = evaluate(lowercase_      ,		{}      ,		state=lowercase_				)
        assert result == 3
        self.assertDictEqual(lowercase_      ,		{"""x""": 3}				)

        UpperCamelCase      = """x = y"""
        UpperCamelCase      = {"""y""": 5}
        UpperCamelCase      = evaluate(lowercase_      ,		{}      ,		state=lowercase_				)
        # evaluate returns the value of the last assignment.
        assert result == 5
        self.assertDictEqual(lowercase_      ,		{"""x""": 5, """y""": 5}				)

  def   A__						(				self				)  ->				Tuple:



        """simple docstring"""






        UpperCamelCase      = """y = add_two(x)"""
        UpperCamelCase      = {"""x""": 3}
        UpperCamelCase      = evaluate(lowercase_      ,		{"""add_two""": add_two}      ,		state=lowercase_				)
        assert result == 5
        self.assertDictEqual(lowercase_      ,		{"""x""": 3, """y""": 5}				)

        # Won't work without the tool
        with CaptureStdout() as out:
              UpperCamelCase      = evaluate(lowercase_      ,		{}      ,		state=lowercase_				)
        assert result is None
        assert "tried to execute add_two" in out.out

  def   A__						(				self				)  ->				List[Any]:



        """simple docstring"""






        UpperCamelCase      = """x = 3"""
        UpperCamelCase      = {}
        UpperCamelCase      = evaluate(lowercase_      ,		{}      ,		state=lowercase_				)
        assert result == 3
        self.assertDictEqual(lowercase_      ,		{"""x""": 3}				)

  def   A__						(				self				)  ->				Union[str, Any]:



        """simple docstring"""






        UpperCamelCase      = """test_dict = {'x': x, 'y': add_two(x)}"""
        UpperCamelCase      = {"""x""": 3}
        UpperCamelCase      = evaluate(lowercase_      ,		{"""add_two""": add_two}      ,		state=lowercase_				)
        self.assertDictEqual(lowercase_      ,		{"""x""": 3, """y""": 5}				)
        self.assertDictEqual(lowercase_      ,		{"""x""": 3, """test_dict""": {"""x""": 3, """y""": 5}}				)

  def   A__						(				self				)  ->				List[str]:



        """simple docstring"""






        UpperCamelCase      = """x = 3\ny = 5"""
        UpperCamelCase      = {}
        UpperCamelCase      = evaluate(lowercase_      ,		{}      ,		state=lowercase_				)
        # evaluate returns the value of the last assignment.
        assert result == 5
        self.assertDictEqual(lowercase_      ,		{"""x""": 3, """y""": 5}				)

  def   A__						(				self				)  ->				Any:



        """simple docstring"""






        UpperCamelCase      = """text = f'This is x: {x}.'"""
        UpperCamelCase      = {"""x""": 3}
        UpperCamelCase      = evaluate(lowercase_      ,		{}      ,		state=lowercase_				)
        # evaluate returns the value of the last assignment.
        assert result == "This is x: 3."
        self.assertDictEqual(lowercase_      ,		{"""x""": 3, """text""": """This is x: 3."""}				)

  def   A__						(				self				)  ->				Tuple:



        """simple docstring"""






        UpperCamelCase      = """if x <= 3:\n    y = 2\nelse:\n    y = 5"""
        UpperCamelCase      = {"""x""": 3}
        UpperCamelCase      = evaluate(lowercase_      ,		{}      ,		state=lowercase_				)
        # evaluate returns the value of the last assignment.
        assert result == 2
        self.assertDictEqual(lowercase_      ,		{"""x""": 3, """y""": 2}				)

        UpperCamelCase      = {"""x""": 8}
        UpperCamelCase      = evaluate(lowercase_      ,		{}      ,		state=lowercase_				)
        # evaluate returns the value of the last assignment.
        assert result == 5
        self.assertDictEqual(lowercase_      ,		{"""x""": 8, """y""": 5}				)

  def   A__						(				self				)  ->				Any:



        """simple docstring"""






        UpperCamelCase      = """test_list = [x, add_two(x)]"""
        UpperCamelCase      = {"""x""": 3}
        UpperCamelCase      = evaluate(lowercase_      ,		{"""add_two""": add_two}      ,		state=lowercase_				)
        self.assertListEqual(lowercase_      ,		[3, 5]				)
        self.assertDictEqual(lowercase_      ,		{"""x""": 3, """test_list""": [3, 5]}				)

  def   A__						(				self				)  ->				Optional[int]:



        """simple docstring"""






        UpperCamelCase      = """y = x"""
        UpperCamelCase      = {"""x""": 3}
        UpperCamelCase      = evaluate(lowercase_      ,		{}      ,		state=lowercase_				)
        assert result == 3
        self.assertDictEqual(lowercase_      ,		{"""x""": 3, """y""": 3}				)

  def   A__						(				self				)  ->				int:



        """simple docstring"""






        UpperCamelCase      = """test_list = [x, add_two(x)]\ntest_list[1]"""
        UpperCamelCase      = {"""x""": 3}
        UpperCamelCase      = evaluate(lowercase_      ,		{"""add_two""": add_two}      ,		state=lowercase_				)
        assert result == 5
        self.assertDictEqual(lowercase_      ,		{"""x""": 3, """test_list""": [3, 5]}				)

        UpperCamelCase      = """test_dict = {'x': x, 'y': add_two(x)}\ntest_dict['y']"""
        UpperCamelCase      = {"""x""": 3}
        UpperCamelCase      = evaluate(lowercase_      ,		{"""add_two""": add_two}      ,		state=lowercase_				)
        assert result == 5
        self.assertDictEqual(lowercase_      ,		{"""x""": 3, """test_dict""": {"""x""": 3, """y""": 5}}				)


  def   A__						(				self				)  ->				Optional[int]:



        """simple docstring"""






        UpperCamelCase      = """x = 0\nfor i in range(3):\n    x = i"""
        UpperCamelCase      = {}
        UpperCamelCase      = evaluate(lowercase_      ,		{"""range""": range}      ,		state=lowercase_				)
        assert result == 2
        self.assertDictEqual(lowercase_      ,		{"""x""": 2, """i""": 2}				)








'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


SCREAMING_SNAKE_CASE__     =       {
    'configuration_mobilebert': [
        'MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'MobileBertConfig',
        'MobileBertOnnxConfig',
    ],
    'tokenization_mobilebert': ['MobileBertTokenizer'],
}

try:
     if not is_tokenizers_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     SCREAMING_SNAKE_CASE__     =       ['MobileBertTokenizerFast']

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     SCREAMING_SNAKE_CASE__     =       [
         'MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
         'MobileBertForMaskedLM',
         'MobileBertForMultipleChoice',
         'MobileBertForNextSentencePrediction',
         'MobileBertForPreTraining',
         'MobileBertForQuestionAnswering',
         'MobileBertForSequenceClassification',
         'MobileBertForTokenClassification',
         'MobileBertLayer',
         'MobileBertModel',
         'MobileBertPreTrainedModel',
         'load_tf_weights_in_mobilebert',
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     SCREAMING_SNAKE_CASE__     =       [
         'TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
         'TFMobileBertForMaskedLM',
         'TFMobileBertForMultipleChoice',
         'TFMobileBertForNextSentencePrediction',
         'TFMobileBertForPreTraining',
         'TFMobileBertForQuestionAnswering',
         'TFMobileBertForSequenceClassification',
         'TFMobileBertForTokenClassification',
         'TFMobileBertMainLayer',
         'TFMobileBertModel',
         'TFMobileBertPreTrainedModel',
     ]


if TYPE_CHECKING:
     from .configuration_mobilebert import (
         MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
         MobileBertConfig,
         MobileBertOnnxConfig,
     )
     from .tokenization_mobilebert import MobileBertTokenizer

     try:
          if not is_tokenizers_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .tokenization_mobilebert_fast import MobileBertTokenizerFast

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_mobilebert import (
              MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
              MobileBertForMaskedLM,
              MobileBertForMultipleChoice,
              MobileBertForNextSentencePrediction,
              MobileBertForPreTraining,
              MobileBertForQuestionAnswering,
              MobileBertForSequenceClassification,
              MobileBertForTokenClassification,
              MobileBertLayer,
              MobileBertModel,
              MobileBertPreTrainedModel,
              load_tf_weights_in_mobilebert,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_mobilebert import (
              TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
              TFMobileBertForMaskedLM,
              TFMobileBertForMultipleChoice,
              TFMobileBertForNextSentencePrediction,
              TFMobileBertForPreTraining,
              TFMobileBertForQuestionAnswering,
              TFMobileBertForSequenceClassification,
              TFMobileBertForTokenClassification,
              TFMobileBertMainLayer,
              TFMobileBertModel,
              TFMobileBertPreTrainedModel,
          )

else:
     import sys

     SCREAMING_SNAKE_CASE__     =       _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
