'''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 					__SCREAMING_SNAKE_CASE						(	datasets.BeamBasedBuilder	):







  '''simple docstring'''






  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       return datasets.DatasetInfo(
           features=datasets.Features({'content': datasets.Value('string'						)}						)				,		supervised_keys=snake_case_				,		)


  def _UpperCamelCase					(			self				,		snake_case_				,		snake_case_						):




       '''simple docstring'''

       return [datasets.SplitGenerator(name=datasets.Split.TRAIN				,		gen_kwargs={'examples': get_test_dummy_examples()}						)]






  def _UpperCamelCase					(			self				,		snake_case_				,		snake_case_						):




       '''simple docstring'''

       import apache_beam as beam

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







class 					__SCREAMING_SNAKE_CASE						(	datasets.BeamBasedBuilder	):







  '''simple docstring'''






  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       return datasets.DatasetInfo(
           features=datasets.Features({'a': datasets.Sequence({'b': datasets.Value('string'						)}						)}						)				,		supervised_keys=snake_case_				,		)


  def _UpperCamelCase					(			self				,		snake_case_				,		snake_case_						):




       '''simple docstring'''

       return [
           datasets.SplitGenerator(name=datasets.Split.TRAIN				,		gen_kwargs={'examples': get_test_nested_examples()}						)
       ]






  def _UpperCamelCase					(			self				,		snake_case_				,		snake_case_						):




       '''simple docstring'''

       import apache_beam as beam

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







def  _lowerCamelCase   (				):



     """simple docstring"""





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


def  _lowerCamelCase   (				):



     """simple docstring"""





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






class 					__SCREAMING_SNAKE_CASE						(	lowerCamelCase_	):







  '''simple docstring'''






  @require_beam
  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       UpperCAmelCase_							:       List[str]       =				len(get_test_dummy_examples()						)
       with tempfile.TemporaryDirectory() as tmp_cache_dir:
            UpperCAmelCase_							:       int       =				DummyBeamDataset(cache_dir=snake_case_				,		beam_runner='DirectRunner'						)
            builder.download_and_prepare()
            self.assertTrue(
                os.path.exists(
                    os.path.join(snake_case_				,		builder.name				,		'default'				,		'0.0.0'				,		F'''{builder.name}-train.arrow'''						)						)						)
            self.assertDictEqual(builder.info.features				,		datasets.Features({'content': datasets.Value('string'						)}						)						)
            UpperCAmelCase_							:       Any       =				builder.as_dataset()
            self.assertEqual(dset['train'].num_rows				,		snake_case_						)
            self.assertEqual(dset['train'].info.splits['train'].num_examples				,		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(snake_case_				,		builder.name				,		'default'				,		'0.0.0'				,		'dataset_info.json'						)						)						)
            del dset


  @require_beam
  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       import apache_beam as beam

       UpperCAmelCase_							:       str       =				beam.io.parquetio.WriteToParquet

       UpperCAmelCase_							:       str       =				len(get_test_dummy_examples()						)
       with tempfile.TemporaryDirectory() as tmp_cache_dir:
            UpperCAmelCase_							:       Union[str, Any]       =				DummyBeamDataset(cache_dir=snake_case_				,		beam_runner='DirectRunner'						)
            with patch('apache_beam.io.parquetio.WriteToParquet'						) as write_parquet_mock:
                 UpperCAmelCase_							:       Optional[Any]       =				partial(snake_case_				,		num_shards=2						)
                 builder.download_and_prepare()
            self.assertTrue(
                os.path.exists(
                    os.path.join(
                        snake_case_				,		builder.name				,		'default'				,		'0.0.0'				,		F'''{builder.name}-train-00000-of-00002.arrow'''						)						)						)
            self.assertTrue(
                os.path.exists(
                    os.path.join(
                        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'						)}						)						)
            UpperCAmelCase_							:       List[str]       =				builder.as_dataset()
            self.assertEqual(dset['train'].num_rows				,		snake_case_						)
            self.assertEqual(dset['train'].info.splits['train'].num_examples				,		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(snake_case_				,		builder.name				,		'default'				,		'0.0.0'				,		'dataset_info.json'						)						)						)
            del dset


  @require_beam
  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       with tempfile.TemporaryDirectory() as tmp_cache_dir:
            UpperCAmelCase_							:       Any       =				DummyBeamDataset(cache_dir=snake_case_						)
            self.assertRaises(datasets.builder.MissingBeamOptions				,		builder.download_and_prepare						)






  @require_beam
  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       UpperCAmelCase_							:       Union[str, Any]       =				len(get_test_nested_examples()						)
       with tempfile.TemporaryDirectory() as tmp_cache_dir:
            UpperCAmelCase_							:       List[str]       =				NestedBeamDataset(cache_dir=snake_case_				,		beam_runner='DirectRunner'						)
            builder.download_and_prepare()
            self.assertTrue(
                os.path.exists(
                    os.path.join(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'						)}						)}						)						)
            UpperCAmelCase_							:       Dict       =				builder.as_dataset()
            self.assertEqual(dset['train'].num_rows				,		snake_case_						)
            self.assertEqual(dset['train'].info.splits['train'].num_examples				,		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(snake_case_				,		builder.name				,		'default'				,		'0.0.0'				,		'dataset_info.json'						)						)						)
            del dset







'''simple docstring'''


snake_case__					:      str				      =  '''Tobias Carryer'''

from time import time






class 					__SCREAMING_SNAKE_CASE						:







  '''simple docstring'''






  def __init__(			self				,		snake_case_				,		snake_case_				,		snake_case_				,		snake_case_=int(time()						)						):  # noqa: B008




       '''simple docstring'''

       UpperCAmelCase_							:       str       =				multiplier
       UpperCAmelCase_							:       Dict       =				increment
       UpperCAmelCase_							:       Tuple       =				modulo
       UpperCAmelCase_							:       Dict       =				seed






  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       UpperCAmelCase_							:       Union[str, Any]       =				(self.multiplier * self.seed + self.increment) % self.modulo
       return self.seed


if __name__ == "__main__":
 # Show the LCG in action.
 snake_case__					:      Any				      =  LinearCongruentialGenerator(166_4525, 10_1390_4223, 2 << 31)
 while True:
  print(lcg.next_number())






