



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  _lowercase			(       self      :     str):
											A__	:							Optional[int]						    = 10







					def  _lowercase			(       self      :     Any):
											A__	:							Any						    = [1, 2, 3, 4]
											A__	:							Union[str, Any]						    = [1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
											self.assertEqual(truncate_or_pad(_A			,		self.block_size			,		0)			,		_A)







					def  _lowercase			(       self      :     Optional[Any]):
											A__	:							Tuple						    = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
											A__	:							Any						    = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
											self.assertEqual(truncate_or_pad(_A			,		self.block_size			,		0)			,		_A)







					def  _lowercase			(       self      :     Tuple):
											A__	:							Union[str, Any]						    = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
											A__	:							int						    = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
											self.assertEqual(truncate_or_pad(_A			,		self.block_size			,		0)			,		_A)







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







					def  _lowercase			(       self      :     Dict):
											A__	:							int						    = ""
											A__    ,       A__	:							int						    = process_story(_A)
											self.assertEqual(_A			,		[])
											self.assertEqual(_A			,		[])







					def  _lowercase			(       self      :     int):
											A__	:							Union[str, 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__	:							Optional[int]						    = process_story(_A)

											A__	:							Optional[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(_A			,		_A)

											A__	:							List[Any]						    = ["It was the best of times."]
											self.assertEqual(_A			,		_A)







					def  _lowercase			(       self      :     str):
											A__	:							Dict						    = torch.tensor([1, 2, 3, 4])
											A__	:							List[str]						    = torch.tensor([1, 1, 1, 1])
											np.testing.assert_array_equal(build_mask(_A			,		0).numpy()			,		expected.numpy())







					def  _lowercase			(       self      :     Optional[Any]):
											A__	:							Optional[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(_A			,		23).numpy()			,		expected.numpy())







					def  _lowercase			(       self      :     Union[str, Any]):
											A__	:							str						    = torch.tensor([8, 2, 3, 4, 1, 1, 1])
											A__	:							Optional[int]						    = torch.tensor([1, 1, 1, 1, 0, 0, 0])
											np.testing.assert_array_equal(build_mask(_A			,		1).numpy()			,		expected.numpy())







					def  _lowercase			(       self      :     Optional[int]):
											A__	:							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__	:							Optional[int]						    = torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]])

											A__	:							List[str]						    = compute_token_type_ids(_A			,		_A)
											np.testing.assert_array_equal(_A			,		_A)




import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
		import ctypes
		import msvcrt  # noqa




		class 							lowerCAmelCase__  (	ctypes.Structure						):
							# _fields is a specific attr expected by ctypes
							__A     :    Optional[Any]           =						[('size', ctypes.c_int), ('visible', ctypes.c_byte)]
def 	snake_case__       (					)		->		List[Any]:







						"""simple docstring"""

						if os.name == "nt":
												A__	:							Optional[Any]						    = CursorInfo()
												A__	:							Tuple						    = ctypes.windll.kernelaa.GetStdHandle(-1_1       )
												ctypes.windll.kernelaa.GetConsoleCursorInfo(__lowercase							,     ctypes.byref(__lowercase       )       )
												A__	:							Any						    = False
												ctypes.windll.kernelaa.SetConsoleCursorInfo(__lowercase							,     ctypes.byref(__lowercase       )       )
						elif os.name == "posix":
												sys.stdout.write("\033[?25l"       )
												sys.stdout.flush()
def 	snake_case__       (					)		->		Dict:







						"""simple docstring"""

						if os.name == "nt":
												A__	:							List[str]						    = CursorInfo()
												A__	:							Optional[int]						    = ctypes.windll.kernelaa.GetStdHandle(-1_1       )
												ctypes.windll.kernelaa.GetConsoleCursorInfo(__lowercase							,     ctypes.byref(__lowercase       )       )
												A__	:							int						    = True
												ctypes.windll.kernelaa.SetConsoleCursorInfo(__lowercase							,     ctypes.byref(__lowercase       )       )
						elif os.name == "posix":
												sys.stdout.write("\033[?25h"       )
												sys.stdout.flush()




@contextmanager
def 	snake_case__       (					)		->		Optional[int]:







						"""simple docstring"""

						try:
												hide_cursor()
												yield
						finally:
												show_cursor()