



import sys

from .dependency_versions_table import deps
from .utils.versions import require_version, require_version_core


# define which module versions we always want to check at run time
# (usually the ones defined in `install_requires` in setup.py)
#
# order specific notes:
# - tqdm must be checked before tokenizers

lowerCamelCase							:Union[str, Any]       = '''python tqdm regex requests packaging filelock numpy tokenizers'''.split()
if sys.version_info < (3, 7):
						pkgs_to_check_at_runtime.append('''dataclasses''')
if sys.version_info < (3, 8):
						pkgs_to_check_at_runtime.append('''importlib_metadata''')

for pkg in pkgs_to_check_at_runtime:
						if pkg in deps:
												if pkg == "tokenizers":
																		# must be loaded here, or else tqdm check may fail
																		from .utils import is_tokenizers_available

																		if not is_tokenizers_available():
																								continue  # not required, check version only if installed

												require_version_core(deps[pkg])
						else:
												raise ValueError(F"can't find {pkg} in {deps.keys()}, check dependency_versions_table.py")



def      a      (			lowerCamelCase__						,				lowerCamelCase__=None   ):
			'''simple docstring'''





			require_version(deps[pkg]						,				_SCREAMING_SNAKE_CASE   )




'''simple docstring'''




import unittest

import numpy as np
import torch

from .utils_summarization import build_mask, compute_token_type_ids, process_story, truncate_or_pad







class      _lowerCAmelCase							(      unittest.TestCase			):


	def    _a     (self							):
				A_     :						Dict     =					10


	def    _a     (self							):
				A_     :						str     =					[1, 2, 3, 4]
				A_     :						List[str]     =					[1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
				self.assertEqual(truncate_or_pad(lowercase	,				self.block_size	,				0							)	,				lowercase							)


	def    _a     (self							):
				A_     :						str     =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
				A_     :						Tuple     =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
				self.assertEqual(truncate_or_pad(lowercase	,				self.block_size	,				0							)	,				lowercase							)


	def    _a     (self							):
				A_     :						List[Any]     =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
				A_     :						str     =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
				self.assertEqual(truncate_or_pad(lowercase	,				self.block_size	,				0							)	,				lowercase							)


	def    _a     (self							):
				A_     :						Any     =					"""It was the year of Our Lord one thousand seven hundred and
        seventy-five.\n\nSpiritual revelations were conceded to England at that
        favoured period, as at this."""
				A_,   A_     :						Optional[int]     =					process_story(lowercase							)
				self.assertEqual(lowercase	,				[]							)


	def    _a     (self							):
				A_     :						Union[str, Any]     =					""""""
				A_,   A_     :						Union[str, Any]     =					process_story(lowercase							)
				self.assertEqual(lowercase	,				[]							)
				self.assertEqual(lowercase	,				[]							)


	def    _a     (self							):
				A_     :						List[Any]     =					(
				    """It was the year of Our Lord one thousand seven hundred and """
				    """seventy-five\n\nSpiritual revelations were conceded to England """
				    """at that favoured period, as at this.\n@highlight\n\nIt was the best of times"""
				)
				A_,   A_     :						int     =					process_story(lowercase							)

				A_     :						List[Any]     =					[
				    """It was the year of Our Lord one thousand seven hundred and seventy-five.""",
				    """Spiritual revelations were conceded to England at that favoured period, as at this.""",
				]
				self.assertEqual(lowercase	,				lowercase							)

				A_     :						Tuple     =					["""It was the best of times."""]
				self.assertEqual(lowercase	,				lowercase							)


	def    _a     (self							):
				A_     :						Dict     =					torch.tensor([1, 2, 3, 4]							)
				A_     :						Union[str, Any]     =					torch.tensor([1, 1, 1, 1]							)
				np.testing.assert_array_equal(build_mask(lowercase	,				0							).numpy()	,				expected.numpy()							)


	def    _a     (self							):
				A_     :						Union[str, Any]     =					torch.tensor([1, 2, 3, 4, 23, 23, 23]							)
				A_     :						List[str]     =					torch.tensor([1, 1, 1, 1, 0, 0, 0]							)
				np.testing.assert_array_equal(build_mask(lowercase	,				23							).numpy()	,				expected.numpy()							)


	def    _a     (self							):
				A_     :						Optional[Any]     =					torch.tensor([8, 2, 3, 4, 1, 1, 1]							)
				A_     :						Tuple     =					torch.tensor([1, 1, 1, 1, 0, 0, 0]							)
				np.testing.assert_array_equal(build_mask(lowercase	,				1							).numpy()	,				expected.numpy()							)


	def    _a     (self							):
				A_     :						List[str]     =					101
				A_     :						str     =					torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]]							)
				A_     :						int     =					torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]							)

				A_     :						Optional[Any]     =					compute_token_type_ids(lowercase	,				lowercase							)
				np.testing.assert_array_equal(lowercase	,				lowercase							)