


import os
from tempfile import TemporaryDirectory
from unittest import TestCase

import pytest
from absl.testing import parameterized

from datasets import config
from datasets.arrow_reader import HF_GCP_BASE_URL
from datasets.builder import DatasetBuilder
from datasets.dataset_dict import IterableDatasetDict
from datasets.iterable_dataset import IterableDataset
from datasets.load import dataset_module_factory, import_main_class
from datasets.utils.file_utils import cached_path


__snake_case            =   [
    {"dataset": "wikipedia", "config_name": "20220301.de"},
    {"dataset": "wikipedia", "config_name": "20220301.en"},
    {"dataset": "wikipedia", "config_name": "20220301.fr"},
    {"dataset": "wikipedia", "config_name": "20220301.frr"},
    {"dataset": "wikipedia", "config_name": "20220301.it"},
    {"dataset": "wikipedia", "config_name": "20220301.simple"},
    {"dataset": "snli", "config_name": "plain_text"},
    {"dataset": "eli5", "config_name": "LFQA_reddit"},
    {"dataset": "wiki40b", "config_name": "en"},
    {"dataset": "wiki_dpr", "config_name": "psgs_w100.nq.compressed"},
    {"dataset": "wiki_dpr", "config_name": "psgs_w100.nq.no_index"},
    {"dataset": "wiki_dpr", "config_name": "psgs_w100.multiset.no_index"},
    {"dataset": "natural_questions", "config_name": "default"},
]






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		Dict=True	):





			"""simple docstring"""




			if with_config:
						return [
						    {
						        "testcase_name": d["dataset"] + "/" + d["config_name"],
						        "dataset": d["dataset"],
						        "config_name": d["config_name"],
						    }
						    for d in DATASETS_ON_HF_GCP
						]
			else:
						return [
						    {"testcase_name": dataset, "dataset": dataset} for dataset in {d["dataset"] for d in DATASETS_ON_HF_GCP}
						]




@parameterized.named_parameters(list_datasets_on_hf_gcp_parameters(with_config=__snake_case    )    )
class    UpperCAmelCase					(       __snake_case    ):
			lowercase						= None
			lowercase						= None




			def   lowerCamelCase_					(						self							:		str       ,       __magic_name__							:		str       ,       __magic_name__							:		List[str]						):







						"""simple docstring"""







						with TemporaryDirectory() as tmp_dir:
									UpperCamelCase         =					dataset_module_factory(__magic_name__       ,       cache_dir=__magic_name__						)

									UpperCamelCase         =					import_main_class(dataset_module.module_path       ,       dataset=__magic_name__						)

									UpperCamelCase         =					builder_cls(
									    cache_dir=__magic_name__       ,       config_name=__magic_name__       ,       hash=dataset_module.hash       ,       )

									UpperCamelCase         =					"""/""".join(
									    [
									        HF_GCP_BASE_URL,
									        builder_instance._relative_data_dir(with_hash=__magic_name__						).replace(os.sep       ,       """/"""						),
									        config.DATASET_INFO_FILENAME,
									    ]						)
									UpperCamelCase         =					cached_path(__magic_name__       ,       cache_dir=__magic_name__						)
									self.assertTrue(os.path.exists(__magic_name__						)						)






@pytest.mark.integration
def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		Dict	):





			"""simple docstring"""




			UpperCamelCase         =					tmp_path_factory.mktemp("""test_hf_gcp"""	) / """test_wikipedia_simple"""
			UpperCamelCase         =					dataset_module_factory("""wikipedia"""       ,  cache_dir=SCREAMING_SNAKE_CASE_	)
			UpperCamelCase         =					import_main_class(dataset_module.module_path	)
			UpperCamelCase         =					builder_cls(
			    cache_dir=SCREAMING_SNAKE_CASE_       ,  config_name="""20220301.frr"""       ,  hash=dataset_module.hash       ,  )
			# use the HF cloud storage, not the original download_and_prepare that uses apache-beam
			UpperCamelCase         =					None
			builder_instance.download_and_prepare()
			UpperCamelCase         =					builder_instance.as_dataset()
			assert ds






@pytest.mark.integration
def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		Optional[Any]	):





			"""simple docstring"""




			UpperCamelCase         =					dataset_module_factory("""wikipedia"""       ,  cache_dir=SCREAMING_SNAKE_CASE_	)
			UpperCamelCase         =					import_main_class(dataset_module.module_path       ,  dataset=SCREAMING_SNAKE_CASE_	)
			UpperCamelCase         =					builder_cls(
			    cache_dir=SCREAMING_SNAKE_CASE_       ,  config_name="""20220301.frr"""       ,  hash=dataset_module.hash       ,  )
			UpperCamelCase         =					builder_instance.as_streaming_dataset()
			assert ds
			assert isinstance(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	)
			assert "train" in ds
			assert isinstance(ds["""train"""]       ,  SCREAMING_SNAKE_CASE_	)
			assert next(iter(ds["""train"""]	)	)



import math
import unittest






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		int	):





			"""simple docstring"""




			assert isinstance(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	) and (
			    number >= 0
			), "'number' must been an int and positive"

			if 1 < number < 4:
						# 2 and 3 are primes
						return True
			elif number < 2 or number % 2 == 0 or number % 3 == 0:
						# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
						return False

			# All primes number are in format of 6k +/- 1
			for i in range(5       ,  int(math.sqrt(SCREAMING_SNAKE_CASE_	) + 1	)       ,  6	):
						if number % i == 0 or number % (i + 2) == 0:
									return False
			return True




class    UpperCAmelCase					(       unittest.TestCase    ):




			def   lowerCamelCase_					(						self							:		Any						):







						"""simple docstring"""







						self.assertTrue(is_prime(2						)						)
						self.assertTrue(is_prime(3						)						)
						self.assertTrue(is_prime(5						)						)
						self.assertTrue(is_prime(7						)						)
						self.assertTrue(is_prime(1_1						)						)
						self.assertTrue(is_prime(1_3						)						)
						self.assertTrue(is_prime(1_7						)						)
						self.assertTrue(is_prime(1_9						)						)
						self.assertTrue(is_prime(2_3						)						)
						self.assertTrue(is_prime(2_9						)						)





			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						with self.assertRaises(__magic_name__						):
									is_prime(-1_9						)
						self.assertFalse(
						    is_prime(0						)       ,       """Zero doesn't have any positive factors, primes must have exactly two."""       ,       )
						self.assertFalse(
						    is_prime(1						)       ,       """One only has 1 positive factor, primes must have exactly two."""       ,       )
						self.assertFalse(is_prime(2 * 2						)						)
						self.assertFalse(is_prime(2 * 3						)						)
						self.assertFalse(is_prime(3 * 3						)						)
						self.assertFalse(is_prime(3 * 5						)						)
						self.assertFalse(is_prime(3 * 5 * 7						)						)


if __name__ == "__main__":
			unittest.main()




