'''simple docstring'''

import unittest

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


def __a (	__lowerCamelCase			:						Optional[Any]				)	->							int:
      '''simple docstring'''


      return x + 2






class 							lowercase						(						unittest.TestCase ):


   def __UpperCAmelCase       (   self				:	Union[str, Any])      ->					str:
         lowercase_     =      "x = 3"
         lowercase_     =      {}
         lowercase_     =      evaluate(__lowerCAmelCase   ,		{}   ,		state=__lowerCAmelCase)
         assert result == 3
         self.assertDictEqual(__lowerCAmelCase   ,		{"x": 3})

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


   def __UpperCAmelCase       (   self				:	int)      ->					Optional[Any]:
         lowercase_     =      "y = add_two(x)"
         lowercase_     =      {"x": 3}
         lowercase_     =      evaluate(__lowerCAmelCase   ,		{"add_two": add_two}   ,		state=__lowerCAmelCase)
         assert result == 5
         self.assertDictEqual(__lowerCAmelCase   ,		{"x": 3, "y": 5})

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


   def __UpperCAmelCase       (   self				:	List[Any])      ->					int:
         lowercase_     =      "x = 3"
         lowercase_     =      {}
         lowercase_     =      evaluate(__lowerCAmelCase   ,		{}   ,		state=__lowerCAmelCase)
         assert result == 3
         self.assertDictEqual(__lowerCAmelCase   ,		{"x": 3})


   def __UpperCAmelCase       (   self				:	Union[str, Any])      ->					Tuple:
         lowercase_     =      "test_dict = {'x': x, 'y': add_two(x)}"
         lowercase_     =      {"x": 3}
         lowercase_     =      evaluate(__lowerCAmelCase   ,		{"add_two": add_two}   ,		state=__lowerCAmelCase)
         self.assertDictEqual(__lowerCAmelCase   ,		{"x": 3, "y": 5})
         self.assertDictEqual(__lowerCAmelCase   ,		{"x": 3, "test_dict": {"x": 3, "y": 5}})


   def __UpperCAmelCase       (   self				:	Tuple)      ->					Union[str, Any]:
         lowercase_     =      "x = 3\ny = 5"
         lowercase_     =      {}
         lowercase_     =      evaluate(__lowerCAmelCase   ,		{}   ,		state=__lowerCAmelCase)
         # evaluate returns the value of the last assignment.
         assert result == 5
         self.assertDictEqual(__lowerCAmelCase   ,		{"x": 3, "y": 5})


   def __UpperCAmelCase       (   self				:	Union[str, Any])      ->					Dict:
         lowercase_     =      "text = f'This is x: {x}.'"
         lowercase_     =      {"x": 3}
         lowercase_     =      evaluate(__lowerCAmelCase   ,		{}   ,		state=__lowerCAmelCase)
         # evaluate returns the value of the last assignment.
         assert result == "This is x: 3."
         self.assertDictEqual(__lowerCAmelCase   ,		{"x": 3, "text": "This is x: 3."})


   def __UpperCAmelCase       (   self				:	int)      ->					Optional[int]:
         lowercase_     =      "if x <= 3:\n    y = 2\nelse:\n    y = 5"
         lowercase_     =      {"x": 3}
         lowercase_     =      evaluate(__lowerCAmelCase   ,		{}   ,		state=__lowerCAmelCase)
         # evaluate returns the value of the last assignment.
         assert result == 2
         self.assertDictEqual(__lowerCAmelCase   ,		{"x": 3, "y": 2})

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


   def __UpperCAmelCase       (   self				:	Dict)      ->					int:
         lowercase_     =      "test_list = [x, add_two(x)]"
         lowercase_     =      {"x": 3}
         lowercase_     =      evaluate(__lowerCAmelCase   ,		{"add_two": add_two}   ,		state=__lowerCAmelCase)
         self.assertListEqual(__lowerCAmelCase   ,		[3, 5])
         self.assertDictEqual(__lowerCAmelCase   ,		{"x": 3, "test_list": [3, 5]})


   def __UpperCAmelCase       (   self				:	Union[str, Any])      ->					Union[str, Any]:
         lowercase_     =      "y = x"
         lowercase_     =      {"x": 3}
         lowercase_     =      evaluate(__lowerCAmelCase   ,		{}   ,		state=__lowerCAmelCase)
         assert result == 3
         self.assertDictEqual(__lowerCAmelCase   ,		{"x": 3, "y": 3})


   def __UpperCAmelCase       (   self				:	Any)      ->					List[str]:
         lowercase_     =      "test_list = [x, add_two(x)]\ntest_list[1]"
         lowercase_     =      {"x": 3}
         lowercase_     =      evaluate(__lowerCAmelCase   ,		{"add_two": add_two}   ,		state=__lowerCAmelCase)
         assert result == 5
         self.assertDictEqual(__lowerCAmelCase   ,		{"x": 3, "test_list": [3, 5]})

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


   def __UpperCAmelCase       (   self				:	Union[str, Any])      ->					Dict:
         lowercase_     =      "x = 0\nfor i in range(3):\n    x = i"
         lowercase_     =      {}
         lowercase_     =      evaluate(__lowerCAmelCase   ,		{"range": range}   ,		state=__lowerCAmelCase)
         assert result == 2
         self.assertDictEqual(__lowerCAmelCase   ,		{"x": 2, "i": 2})







'''simple docstring'''

from typing import Callable, Optional

from .. import Features
from ..packaged_modules.generator.generator import Generator
from .abc import AbstractDatasetInputStream





class 							lowercase						(						__lowerCamelCase ):


   def __init__(   self				:	str   ,		__lowerCAmelCase				:	Callable   ,		__lowerCAmelCase				:	Optional[Features] = None   ,		__lowerCAmelCase				:	str = None   ,		__lowerCAmelCase				:	bool = False   ,		__lowerCAmelCase				:	bool = False   ,		__lowerCAmelCase				:	Optional[dict] = None   ,		__lowerCAmelCase				:	Optional[int] = None   ,		**__lowerCAmelCase				:	Union[str, Any]   ,		)      ->					List[Any]:
         super().__init__(
             features=__lowerCAmelCase   ,		cache_dir=__lowerCAmelCase   ,		keep_in_memory=__lowerCAmelCase   ,		streaming=__lowerCAmelCase   ,		num_proc=__lowerCAmelCase   ,		**__lowerCAmelCase   ,		)
         lowercase_     =      Generator(
             cache_dir=__lowerCAmelCase   ,		features=__lowerCAmelCase   ,		generator=__lowerCAmelCase   ,		gen_kwargs=__lowerCAmelCase   ,		**__lowerCAmelCase   ,		)


   def __UpperCAmelCase       (   self				:	Optional[int])      ->					List[str]:
         # Build iterable dataset
         if self.streaming:
               lowercase_     =      self.builder.as_streaming_dataset(split="train")
         # Build regular (map-style) dataset
         else:
               lowercase_     =      None
               lowercase_     =      None
               lowercase_     =      None
               lowercase_     =      None

               self.builder.download_and_prepare(
                   download_config=__lowerCAmelCase   ,		download_mode=__lowerCAmelCase   ,		verification_mode=__lowerCAmelCase   ,		base_path=__lowerCAmelCase   ,		num_proc=self.num_proc   ,		)
               lowercase_     =      self.builder.as_dataset(
                   split="train"   ,		verification_mode=__lowerCAmelCase   ,		in_memory=self.keep_in_memory)
         return dataset






