

'''simple docstring'''

import os
import tempfile
from functools import partial
from unittest import TestCase
from unittest.mock import patch

import datasets
import datasets.config

from .utils import require_beam





class 				_snake_case			(							datasets.BeamBasedBuilder    ):
   def      __UpperCamelCase    (			self      :   str				):
     return datasets.DatasetInfo(
         features=datasets.Features({"content": datasets.Value("string"				)}				)  ,supervised_keys=SCREAMING_SNAKE_CASE__  ,)
   def      __UpperCamelCase    (			self      :   Dict  ,SCREAMING_SNAKE_CASE__      :   Optional[Any]  ,SCREAMING_SNAKE_CASE__      :   Union[str, Any]				):
     return [datasets.SplitGenerator(name=datasets.Split.TRAIN  ,gen_kwargs={"examples": get_test_dummy_examples()}				)]







   def      __UpperCamelCase    (			self      :   List[str]  ,SCREAMING_SNAKE_CASE__      :   Union[str, Any]  ,SCREAMING_SNAKE_CASE__      :   Tuple				):
     import apache_beam as beam

     return pipeline | "Load Examples" >> beam.Create(SCREAMING_SNAKE_CASE__				)





class 				_snake_case			(							datasets.BeamBasedBuilder    ):
   def      __UpperCamelCase    (			self      :   List[Any]				):
     return datasets.DatasetInfo(
         features=datasets.Features({"a": datasets.Sequence({"b": datasets.Value("string"				)}				)}				)  ,supervised_keys=SCREAMING_SNAKE_CASE__  ,)
   def      __UpperCamelCase    (			self      :   Union[str, Any]  ,SCREAMING_SNAKE_CASE__      :   Optional[int]  ,SCREAMING_SNAKE_CASE__      :   Dict				):
     return [
         datasets.SplitGenerator(name=datasets.Split.TRAIN  ,gen_kwargs={"examples": get_test_nested_examples()}				)
     ]







   def      __UpperCamelCase    (			self      :   List[str]  ,SCREAMING_SNAKE_CASE__      :   List[str]  ,SCREAMING_SNAKE_CASE__      :   Optional[Any]				):
     import apache_beam as beam

     return pipeline | "Load Examples" >> beam.Create(SCREAMING_SNAKE_CASE__				)





def  A_	(			):
  return [(i, {"content": content}) for i, content in enumerate(["foo", "bar", "foobar"]			)]





def  A_	(			):
  return [(i, {"a": {"b": [content]}}) for i, content in enumerate(["foo", "bar", "foobar"]			)]





class 				_snake_case			(							_snake_case    ):
   @require_beam
   def      __UpperCamelCase    (			self      :   Dict				):
     SCREAMING_SNAKE_CASE:List[str]       =       len(get_test_dummy_examples()				)
     with tempfile.TemporaryDirectory() as tmp_cache_dir:
       SCREAMING_SNAKE_CASE:Dict       =       DummyBeamDataset(cache_dir=SCREAMING_SNAKE_CASE__  ,beam_runner="DirectRunner"				)
       builder.download_and_prepare()
       self.assertTrue(
           os.path.exists(
               os.path.join(SCREAMING_SNAKE_CASE__  ,builder.name  ,"default"  ,"0.0.0"  ,F'''{builder.name}-train.arrow'''				)				)				)
       self.assertDictEqual(builder.info.features  ,datasets.Features({"content": datasets.Value("string"				)}				)				)
       SCREAMING_SNAKE_CASE:int       =       builder.as_dataset()
       self.assertEqual(dset["train"].num_rows  ,SCREAMING_SNAKE_CASE__				)
       self.assertEqual(dset["train"].info.splits["train"].num_examples  ,SCREAMING_SNAKE_CASE__				)
       self.assertDictEqual(dset["train"][0]  ,get_test_dummy_examples()[0][1]				)
       self.assertDictEqual(
           dset["train"][expected_num_examples - 1]  ,get_test_dummy_examples()[expected_num_examples - 1][1]				)
       self.assertTrue(
           os.path.exists(os.path.join(SCREAMING_SNAKE_CASE__  ,builder.name  ,"default"  ,"0.0.0"  ,"dataset_info.json"				)				)				)
       del dset
   @require_beam
   def      __UpperCamelCase    (			self      :   int				):
     import apache_beam as beam

     SCREAMING_SNAKE_CASE:int       =       beam.io.parquetio.WriteToParquet

     SCREAMING_SNAKE_CASE:int       =       len(get_test_dummy_examples()				)
     with tempfile.TemporaryDirectory() as tmp_cache_dir:
       SCREAMING_SNAKE_CASE:Tuple       =       DummyBeamDataset(cache_dir=SCREAMING_SNAKE_CASE__  ,beam_runner="DirectRunner"				)
       with patch("apache_beam.io.parquetio.WriteToParquet"				) as write_parquet_mock:
         SCREAMING_SNAKE_CASE:Any       =       partial(SCREAMING_SNAKE_CASE__  ,num_shards=2				)
         builder.download_and_prepare()
       self.assertTrue(
           os.path.exists(
               os.path.join(
                   SCREAMING_SNAKE_CASE__  ,builder.name  ,"default"  ,"0.0.0"  ,F'''{builder.name}-train-00000-of-00002.arrow'''				)				)				)
       self.assertTrue(
           os.path.exists(
               os.path.join(
                   SCREAMING_SNAKE_CASE__  ,builder.name  ,"default"  ,"0.0.0"  ,F'''{builder.name}-train-00000-of-00002.arrow'''				)				)				)
       self.assertDictEqual(builder.info.features  ,datasets.Features({"content": datasets.Value("string"				)}				)				)
       SCREAMING_SNAKE_CASE:Union[str, Any]       =       builder.as_dataset()
       self.assertEqual(dset["train"].num_rows  ,SCREAMING_SNAKE_CASE__				)
       self.assertEqual(dset["train"].info.splits["train"].num_examples  ,SCREAMING_SNAKE_CASE__				)
       # Order is not preserved when sharding, so we just check that all the elements are there
       self.assertListEqual(sorted(dset["train"]["content"]				)  ,sorted(["foo", "bar", "foobar"]				)				)
       self.assertTrue(
           os.path.exists(os.path.join(SCREAMING_SNAKE_CASE__  ,builder.name  ,"default"  ,"0.0.0"  ,"dataset_info.json"				)				)				)
       del dset
   @require_beam
   def      __UpperCamelCase    (			self      :   Any				):

     with tempfile.TemporaryDirectory() as tmp_cache_dir:
       SCREAMING_SNAKE_CASE:Tuple       =       DummyBeamDataset(cache_dir=SCREAMING_SNAKE_CASE__				)
       self.assertRaises(datasets.builder.MissingBeamOptions  ,builder.download_and_prepare				)







   @require_beam
   def      __UpperCamelCase    (			self      :   Optional[int]				):
     SCREAMING_SNAKE_CASE:List[Any]       =       len(get_test_nested_examples()				)
     with tempfile.TemporaryDirectory() as tmp_cache_dir:
       SCREAMING_SNAKE_CASE:Any       =       NestedBeamDataset(cache_dir=SCREAMING_SNAKE_CASE__  ,beam_runner="DirectRunner"				)
       builder.download_and_prepare()
       self.assertTrue(
           os.path.exists(
               os.path.join(SCREAMING_SNAKE_CASE__  ,builder.name  ,"default"  ,"0.0.0"  ,F'''{builder.name}-train.arrow'''				)				)				)
       self.assertDictEqual(
           builder.info.features  ,datasets.Features({"a": datasets.Sequence({"b": datasets.Value("string"				)}				)}				)				)
       SCREAMING_SNAKE_CASE:Union[str, Any]       =       builder.as_dataset()
       self.assertEqual(dset["train"].num_rows  ,SCREAMING_SNAKE_CASE__				)
       self.assertEqual(dset["train"].info.splits["train"].num_examples  ,SCREAMING_SNAKE_CASE__				)
       self.assertDictEqual(dset["train"][0]  ,get_test_nested_examples()[0][1]				)
       self.assertDictEqual(
           dset["train"][expected_num_examples - 1]  ,get_test_nested_examples()[expected_num_examples - 1][1]				)
       self.assertTrue(
           os.path.exists(os.path.join(SCREAMING_SNAKE_CASE__  ,builder.name  ,"default"  ,"0.0.0"  ,"dataset_info.json"				)				)				)
       del dset













'''simple docstring'''

from PIL import Image

def     __magic_name__							(				__UpperCAmelCase				,						__UpperCAmelCase   )    ->       Image:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE   				=							(259 * (level + 255)) / (255 * (259 - level))

   def contrast(__UpperCAmelCase   ) -> int:
      return int(128 + factor * (c - 128)   )

   return img.point(__UpperCAmelCase   )


if __name__ == "__main__":
    # Load image
    with Image.open("image_data/lena.jpg") as img:
        # Change contrast to 170
        a   	=    change_contrast(img, 170)
        cont_img.save("image_data/lena_high_contrast.png", format="png")





