
"""simple docstring"""



import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


_snake_case          =						logging.getLogger()
@unittest.skip("Temporarily disable the doc tests."							)
@require_torch
@require_tf
@slow
class        _SCREAMING_SNAKE_CASE  (  unittest.TestCase							):






				'''simple docstring'''



				def 				__lowerCamelCase	(					self	:			List[Any]				,     UpperCAmelCase_	:			Path				,     UpperCAmelCase_	:			Union[str, None] = None				,     UpperCAmelCase_	:			Union[List[str], None] = None				,     UpperCAmelCase_	:			Union[str, List[str], None] = None				,     UpperCAmelCase_	:			bool = True				,     )		->  Any:







											"""simple docstring"""




											_lowerCAmelCase  	=			[file for file in os.listdir(UpperCAmelCase_  ) if os.path.isfile(os.path.join(UpperCAmelCase_				,     UpperCAmelCase_  )  )]

											if identifier is not None:
																		_lowerCAmelCase  	=			[file for file in files if identifier in file]

											if n_identifier is not None:
																		if isinstance(UpperCAmelCase_				,     UpperCAmelCase_  ):
																									for n_ in n_identifier:
																																_lowerCAmelCase  	=			[file for file in files if n_ not in file]
																		else:
																									_lowerCAmelCase  	=			[file for file in files if n_identifier not in file]

											_lowerCAmelCase  	=			ignore_files or []
											ignore_files.append('__init__.py'  )
											_lowerCAmelCase  	=			[file for file in files if file not in ignore_files]

											for file in files:
																		# Open all files
																		print('Testing'				,     UpperCAmelCase_  )

																		if only_modules:
																									_lowerCAmelCase  	=			file.split('.'  )[0]
																									try:
																																_lowerCAmelCase  	=			getattr(UpperCAmelCase_				,     UpperCAmelCase_  )
																																_lowerCAmelCase  	=			doctest.DocTestSuite(UpperCAmelCase_  )
																																_lowerCAmelCase  	=			unittest.TextTestRunner().run(UpperCAmelCase_  )
																																self.assertIs(len(result.failures  )				,     0  )
																									except AttributeError:
																																logger.info(F"""{module_identifier} is not a module."""  )
																		else:
																									_lowerCAmelCase  	=			doctest.testfile(str('..' / directory / file  )				,     optionflags=doctest.ELLIPSIS  )
																									self.assertIs(result.failed				,     0  )


				def 				__lowerCamelCase	(					self	:			List[str]  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			Path('src/transformers'  )
											_lowerCAmelCase  	=			'modeling'
											_lowerCAmelCase  	=			[
											    'modeling_ctrl.py',
											    'modeling_tf_ctrl.py',
											]
											self.analyze_directory(UpperCAmelCase_				,     identifier=UpperCAmelCase_				,     ignore_files=UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			str  )		->  Dict:







											"""simple docstring"""




											_lowerCAmelCase  	=			Path('src/transformers'  )
											_lowerCAmelCase  	=			'tokenization'
											self.analyze_directory(UpperCAmelCase_				,     identifier=UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			List[str]  )		->  List[Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			Path('src/transformers'  )
											_lowerCAmelCase  	=			'configuration'
											self.analyze_directory(UpperCAmelCase_				,     identifier=UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			int  )		->  List[str]:







											"""simple docstring"""




											_lowerCAmelCase  	=			Path('src/transformers'  )
											_lowerCAmelCase  	=			['configuration', 'modeling', 'tokenization']
											self.analyze_directory(UpperCAmelCase_				,     n_identifier=UpperCAmelCase_  )







				def 				__lowerCamelCase	(					self	:			str  )		->  Optional[int]:







											"""simple docstring"""




											_lowerCAmelCase  	=			Path('docs/source'  )
											_lowerCAmelCase  	=			['favicon.ico']
											self.analyze_directory(UpperCAmelCase_				,     ignore_files=UpperCAmelCase_				,     only_modules=UpperCAmelCase_  )








"""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        _SCREAMING_SNAKE_CASE  (  unittest.TestCase							):






				'''simple docstring'''



				def 				__lowerCamelCase	(					self	:			Any  )		->  Dict:







											"""simple docstring"""




											_lowerCAmelCase  	=			10


				def 				__lowerCamelCase	(					self	:			List[Any]  )		->  Optional[int]:







											"""simple docstring"""




											_lowerCAmelCase  	=			[1, 2, 3, 4]
											_lowerCAmelCase  	=			[1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
											self.assertEqual(truncate_or_pad(UpperCAmelCase_				,     self.block_size				,     0  )				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Optional[int]  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
											_lowerCAmelCase  	=			[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
											self.assertEqual(truncate_or_pad(UpperCAmelCase_				,     self.block_size				,     0  )				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			List[Any]  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
											_lowerCAmelCase  	=			[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
											self.assertEqual(truncate_or_pad(UpperCAmelCase_				,     self.block_size				,     0  )				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			str  )		->  Optional[int]:







											"""simple docstring"""




											_lowerCAmelCase  	=			'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.'
											_lowerCAmelCase	,		_lowerCAmelCase  	=			process_story(UpperCAmelCase_  )
											self.assertEqual(UpperCAmelCase_				,     []  )


				def 				__lowerCamelCase	(					self	:			Dict  )		->  Union[str, Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			''
											_lowerCAmelCase	,		_lowerCAmelCase  	=			process_story(UpperCAmelCase_  )
											self.assertEqual(UpperCAmelCase_				,     []  )
											self.assertEqual(UpperCAmelCase_				,     []  )


				def 				__lowerCamelCase	(					self	:			Optional[int]  )		->  List[str]:







											"""simple docstring"""




											_lowerCAmelCase  	=			(
											    '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'
											)
											_lowerCAmelCase	,		_lowerCAmelCase  	=			process_story(UpperCAmelCase_  )

											_lowerCAmelCase  	=			[
											    '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(UpperCAmelCase_				,     UpperCAmelCase_  )

											_lowerCAmelCase  	=			['It was the best of times.']
											self.assertEqual(UpperCAmelCase_				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			List[str]  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			torch.tensor([1, 2, 3, 4]  )
											_lowerCAmelCase  	=			torch.tensor([1, 1, 1, 1]  )
											np.testing.assert_array_equal(build_mask(UpperCAmelCase_				,     0  ).numpy()				,     expected.numpy()  )


				def 				__lowerCamelCase	(					self	:			int  )		->  str:







											"""simple docstring"""




											_lowerCAmelCase  	=			torch.tensor([1, 2, 3, 4, 23, 23, 23]  )
											_lowerCAmelCase  	=			torch.tensor([1, 1, 1, 1, 0, 0, 0]  )
											np.testing.assert_array_equal(build_mask(UpperCAmelCase_				,     23  ).numpy()				,     expected.numpy()  )


				def 				__lowerCamelCase	(					self	:			int  )		->  Union[str, Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			torch.tensor([8, 2, 3, 4, 1, 1, 1]  )
											_lowerCAmelCase  	=			torch.tensor([1, 1, 1, 1, 0, 0, 0]  )
											np.testing.assert_array_equal(build_mask(UpperCAmelCase_				,     1  ).numpy()				,     expected.numpy()  )







				def 				__lowerCamelCase	(					self	:			str  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			101
											_lowerCAmelCase  	=			torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]]  )
											_lowerCAmelCase  	=			torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]  )

											_lowerCAmelCase  	=			compute_token_type_ids(UpperCAmelCase_				,     UpperCAmelCase_  )
											np.testing.assert_array_equal(UpperCAmelCase_				,     UpperCAmelCase_  )






