





"""simple docstring"""





import unittest

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


def 					a__    (    _SCREAMING_SNAKE_CASE			):




		"""simple docstring"""


		return x + 2






class 				_lowerCamelCase					(				unittest.TestCase       ):


						def 			snake_case_      (self						)       ->      Optional[int]:
								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 			snake_case_      (self						)       ->      Any:
								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 			snake_case_      (self						)       ->      List[Any]:
								UpperCamelCase      =		"x = 3"
								UpperCamelCase      =		{}
								UpperCamelCase      =		evaluate(lowercase_      ,							{}      ,							state=lowercase_						)
								assert result == 3
								self.assertDictEqual(lowercase_      ,							{"x": 3}						)


						def 			snake_case_      (self						)       ->      int:
								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 			snake_case_      (self						)       ->      List[str]:
								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 			snake_case_      (self						)       ->      int:
								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 			snake_case_      (self						)       ->      Any:
								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 			snake_case_      (self						)       ->      Tuple:
								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 			snake_case_      (self						)       ->      int:
								UpperCamelCase      =		"y = x"
								UpperCamelCase      =		{"x": 3}
								UpperCamelCase      =		evaluate(lowercase_      ,							{}      ,							state=lowercase_						)
								assert result == 3
								self.assertDictEqual(lowercase_      ,							{"x": 3, "y": 3}						)


						def 			snake_case_      (self						)       ->      str:
								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 			snake_case_      (self						)       ->      int:
								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}						)









from typing import TYPE_CHECKING

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


lowerCamelCase           =					{'''configuration_xlnet''': ['''XLNET_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''XLNetConfig''']}

try:
       if not is_sentencepiece_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCamelCase           =					['''XLNetTokenizer''']

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

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCamelCase           =					[
           '''XLNET_PRETRAINED_MODEL_ARCHIVE_LIST''',
           '''XLNetForMultipleChoice''',
           '''XLNetForQuestionAnswering''',
           '''XLNetForQuestionAnsweringSimple''',
           '''XLNetForSequenceClassification''',
           '''XLNetForTokenClassification''',
           '''XLNetLMHeadModel''',
           '''XLNetModel''',
           '''XLNetPreTrainedModel''',
           '''load_tf_weights_in_xlnet''',
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCamelCase           =					[
           '''TF_XLNET_PRETRAINED_MODEL_ARCHIVE_LIST''',
           '''TFXLNetForMultipleChoice''',
           '''TFXLNetForQuestionAnsweringSimple''',
           '''TFXLNetForSequenceClassification''',
           '''TFXLNetForTokenClassification''',
           '''TFXLNetLMHeadModel''',
           '''TFXLNetMainLayer''',
           '''TFXLNetModel''',
           '''TFXLNetPreTrainedModel''',
       ]


if TYPE_CHECKING:
       from .configuration_xlnet import XLNET_PRETRAINED_CONFIG_ARCHIVE_MAP, XLNetConfig

       try:
              if not is_sentencepiece_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_xlnet import XLNetTokenizer

       try:
              if not is_tokenizers_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_xlnet_fast import XLNetTokenizerFast

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_xlnet import (
                  XLNET_PRETRAINED_MODEL_ARCHIVE_LIST,
                  XLNetForMultipleChoice,
                  XLNetForQuestionAnswering,
                  XLNetForQuestionAnsweringSimple,
                  XLNetForSequenceClassification,
                  XLNetForTokenClassification,
                  XLNetLMHeadModel,
                  XLNetModel,
                  XLNetPreTrainedModel,
                  load_tf_weights_in_xlnet,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_xlnet import (
                  TF_XLNET_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFXLNetForMultipleChoice,
                  TFXLNetForQuestionAnsweringSimple,
                  TFXLNetForSequenceClassification,
                  TFXLNetForTokenClassification,
                  TFXLNetLMHeadModel,
                  TFXLNetMainLayer,
                  TFXLNetModel,
                  TFXLNetPreTrainedModel,
              )

else:
       import sys

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