

"""simple docstring"""





from transformers import (
    DPRContextEncoderTokenizer,
    DPRContextEncoderTokenizerFast,
    DPRQuestionEncoderTokenizer,
    DPRQuestionEncoderTokenizerFast,
    DPRReaderOutput,
    DPRReaderTokenizer,
    DPRReaderTokenizerFast,
)
from transformers.testing_utils import require_tokenizers, slow
from transformers.tokenization_utils_base import BatchEncoding

from ..bert.test_tokenization_bert import BertTokenizationTest

@require_tokenizers
class     __a   (      snake_case__    ):

			"""simple docstring"""

			SCREAMING_SNAKE_CASE_						     =						DPRContextEncoderTokenizer
			SCREAMING_SNAKE_CASE_						     =						DPRContextEncoderTokenizerFast
			SCREAMING_SNAKE_CASE_						     =						True



@require_tokenizers
class     __a   (      snake_case__    ):

			"""simple docstring"""

			SCREAMING_SNAKE_CASE_						     =						DPRQuestionEncoderTokenizer
			SCREAMING_SNAKE_CASE_						     =						DPRQuestionEncoderTokenizerFast
			SCREAMING_SNAKE_CASE_						     =						True



@require_tokenizers
class     __a   (      snake_case__    ):

			"""simple docstring"""

			SCREAMING_SNAKE_CASE_						     =						DPRReaderTokenizer
			SCREAMING_SNAKE_CASE_						     =						DPRReaderTokenizerFast
			SCREAMING_SNAKE_CASE_						     =						True






			@slow
			def    _lowerCAmelCase			(							self     :					Optional[Any]						):
								UpperCamelCase__		:    Dict         =self.tokenizer_class.from_pretrained('''bert-base-uncased'''						)

								UpperCamelCase__		:    Dict         =tokenizer.encode('''question sequence'''						,  add_special_tokens=lowercase_						)
								UpperCamelCase__		:    List[str]         =tokenizer.encode('''title sequence'''						,  add_special_tokens=lowercase_						)
								UpperCamelCase__		:    Any         =tokenizer.encode('''text sequence ''' * 4						,  add_special_tokens=lowercase_						)
								UpperCamelCase__		:    str         =[[101] + text_a + [102] + text_a + [102] + text_a]
								UpperCamelCase__		:    Dict         =BatchEncoding({'''input_ids''': input_ids}						)

								UpperCamelCase__		:    List[Any]         =[[0] * len(input_ids[0]						)]
								UpperCamelCase__		:    Optional[int]         =[[0] * len(input_ids[0]						)]
								UpperCamelCase__		:    Optional[Any]         =[0]
								UpperCamelCase__		:    List[Any]         =DPRReaderOutput(lowercase_						,  lowercase_						,  lowercase_						)

								UpperCamelCase__  ,			UpperCamelCase__		:    Tuple         =8, 9
								UpperCamelCase__		:    List[str]         =10
								UpperCamelCase__		:    Tuple         =10
								UpperCamelCase__		:    Tuple         =tokenizer.decode_best_spans(lowercase_						,  lowercase_						)
								self.assertEqual(predicted_spans[0].start_index						,  lowercase_						)
								self.assertEqual(predicted_spans[0].end_index						,  lowercase_						)
								self.assertEqual(predicted_spans[0].doc_id						,  0						)






			@slow
			def    _lowerCAmelCase			(							self     :					List[Any]						):
								UpperCamelCase__		:    Optional[int]         =self.tokenizer_class.from_pretrained('''bert-base-uncased'''						)

								UpperCamelCase__		:    List[str]         =tokenizer.encode('''question sequence'''						,  add_special_tokens=lowercase_						)
								UpperCamelCase__		:    int         =tokenizer.encode('''title sequence'''						,  add_special_tokens=lowercase_						)
								UpperCamelCase__		:    List[str]         =tokenizer.encode('''text sequence'''						,  add_special_tokens=lowercase_						)
								UpperCamelCase__		:    Optional[Any]         =[101] + text_a + [102] + text_a + [102] + text_a
								UpperCamelCase__		:    Tuple         =tokenizer(questions=['''question sequence''']						,  titles=['''title sequence''']						,  texts=['''text sequence''']						)
								self.assertIn('''input_ids'''						,  lowercase_						)
								self.assertIn('''attention_mask'''						,  lowercase_						)
								self.assertListEqual(encoded_input['''input_ids'''][0]						,  lowercase_						)





"""simple docstring"""





import unittest

from transformers.image_processing_utils import get_size_dict

class     __a   (      unittest.TestCase    ):

			"""simple docstring"""

			def    _lowerCAmelCase			(							self     :					Dict						):
								# Test a dict with the wrong keys raises an error
								UpperCamelCase__		:    str         ={'''wrong_key''': 224}
								with self.assertRaises(lowercase_						):
													get_size_dict(lowercase_						)

								UpperCamelCase__		:    Any         ={'''height''': 224}
								with self.assertRaises(lowercase_						):
													get_size_dict(lowercase_						)

								UpperCamelCase__		:    List[str]         ={'''width''': 224, '''shortest_edge''': 224}
								with self.assertRaises(lowercase_						):
													get_size_dict(lowercase_						)

								# Test a dict with the correct keys is returned as is
								UpperCamelCase__		:    int         ={'''height''': 224, '''width''': 224}
								UpperCamelCase__		:    str         =get_size_dict(lowercase_						)
								self.assertEqual(lowercase_						,  lowercase_						)

								UpperCamelCase__		:    List[Any]         ={'''shortest_edge''': 224}
								UpperCamelCase__		:    List[str]         =get_size_dict(lowercase_						)
								self.assertEqual(lowercase_						,  {'''shortest_edge''': 224}						)

								UpperCamelCase__		:    List[Any]         ={'''longest_edge''': 224, '''shortest_edge''': 224}
								UpperCamelCase__		:    Tuple         =get_size_dict(lowercase_						)
								self.assertEqual(lowercase_						,  {'''longest_edge''': 224, '''shortest_edge''': 224}						)

								# Test a single int value which  represents (size, size)
								UpperCamelCase__		:    Optional[int]         =get_size_dict(224						)
								self.assertEqual(lowercase_						,  {'''height''': 224, '''width''': 224}						)

								# Test a single int value which represents the shortest edge
								UpperCamelCase__		:    str         =get_size_dict(224						,  default_to_square=lowercase_						)
								self.assertEqual(lowercase_						,  {'''shortest_edge''': 224}						)

								# Test a tuple of ints which represents (height, width)
								UpperCamelCase__		:    List[str]         =get_size_dict((150, 200)						)
								self.assertEqual(lowercase_						,  {'''height''': 150, '''width''': 200}						)

								# Test a tuple of ints which represents (width, height)
								UpperCamelCase__		:    Optional[int]         =get_size_dict((150, 200)						,  height_width_order=lowercase_						)
								self.assertEqual(lowercase_						,  {'''height''': 200, '''width''': 150}						)

								# Test an int representing the shortest edge and max_size which represents the longest edge
								UpperCamelCase__		:    int         =get_size_dict(224						,  max_size=256						,  default_to_square=lowercase_						)
								self.assertEqual(lowercase_						,  {'''shortest_edge''': 224, '''longest_edge''': 256}						)

								# Test int with default_to_square=True and max_size fails
								with self.assertRaises(lowercase_						):
													get_size_dict(224						,  max_size=256						,  default_to_square=lowercase_						)


