
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    _UpperCamelCase(   SCREAMING_SNAKE_CASE				):
						__A:						List[Any]				   =      DPRContextEncoderTokenizer
						__A:						Dict				   =      DPRContextEncoderTokenizerFast
						__A:						Union[str, Any]				   =      True







@require_tokenizers
class    _UpperCamelCase(   SCREAMING_SNAKE_CASE				):
						__A:						int				   =      DPRQuestionEncoderTokenizer
						__A:						Optional[int]				   =      DPRQuestionEncoderTokenizerFast
						__A:						int				   =      True







@require_tokenizers
class    _UpperCamelCase(   SCREAMING_SNAKE_CASE				):
						__A:						Dict				   =      DPRReaderTokenizer
						__A:						Tuple				   =      DPRReaderTokenizerFast
						__A:						Union[str, Any]				   =      True

						@slow
						def 						a__ (					self		:			List[Any]			):
													_UpperCAmelCase  :			Dict	       =		self.tokenizer_class.from_pretrained("bert-base-uncased"			)

													_UpperCAmelCase  :			Optional[int]	       =		tokenizer.encode("question sequence"	,						add_special_tokens=_lowerCamelCase			)
													_UpperCAmelCase  :			Union[str, Any]	       =		tokenizer.encode("title sequence"	,						add_special_tokens=_lowerCamelCase			)
													_UpperCAmelCase  :			Union[str, Any]	       =		tokenizer.encode("text sequence " * 4	,						add_special_tokens=_lowerCamelCase			)
													_UpperCAmelCase  :			Optional[Any]	       =		[[1_01] + text_a + [1_02] + text_a + [1_02] + text_a]
													_UpperCAmelCase  :			Tuple	       =		BatchEncoding({"input_ids": input_ids}			)

													_UpperCAmelCase  :			Optional[Any]	       =		[[0] * len(input_ids[0]			)]
													_UpperCAmelCase  :			Dict	       =		[[0] * len(input_ids[0]			)]
													_UpperCAmelCase  :			Any	       =		[0]
													_UpperCAmelCase  :			List[Any]	       =		DPRReaderOutput(_lowerCamelCase	,						_lowerCamelCase	,						_lowerCamelCase			)

													_UpperCAmelCase       ,_UpperCAmelCase  :			List[str]	       =		8, 9
													_UpperCAmelCase  :			Optional[Any]	       =		10
													_UpperCAmelCase  :			Optional[int]	       =		10
													_UpperCAmelCase  :			Union[str, Any]	       =		tokenizer.decode_best_spans(_lowerCamelCase	,						_lowerCamelCase			)
													self.assertEqual(predicted_spans[0].start_index	,						_lowerCamelCase			)
													self.assertEqual(predicted_spans[0].end_index	,						_lowerCamelCase			)
													self.assertEqual(predicted_spans[0].doc_id	,						0			)






						@slow
						def 						a__ (					self		:			List[Any]			):
													_UpperCAmelCase  :			Optional[int]	       =		self.tokenizer_class.from_pretrained("bert-base-uncased"			)

													_UpperCAmelCase  :			str	       =		tokenizer.encode("question sequence"	,						add_special_tokens=_lowerCamelCase			)
													_UpperCAmelCase  :			List[Any]	       =		tokenizer.encode("title sequence"	,						add_special_tokens=_lowerCamelCase			)
													_UpperCAmelCase  :			Any	       =		tokenizer.encode("text sequence"	,						add_special_tokens=_lowerCamelCase			)
													_UpperCAmelCase  :			Tuple	       =		[1_01] + text_a + [1_02] + text_a + [1_02] + text_a
													_UpperCAmelCase  :			List[str]	       =		tokenizer(questions=["question sequence"]	,						titles=["title sequence"]	,						texts=["text sequence"]			)
													self.assertIn("input_ids"	,						_lowerCamelCase			)
													self.assertIn("attention_mask"	,						_lowerCamelCase			)
													self.assertListEqual(encoded_input["input_ids"][0]	,						_lowerCamelCase			)






import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
				from PIL import Image
class    _UpperCamelCase(   unittest.TestCase		,						SCREAMING_SNAKE_CASE				):

						def 						a__ (					self		:			Optional[int]			):
													_UpperCAmelCase  :			Any	       =		load_tool("image-captioning"			)
													self.tool.setup()
													_UpperCAmelCase  :			Optional[Any]	       =		load_tool("image-captioning"	,						remote=_lowerCamelCase			)

						def 						a__ (					self		:			int			):
													_UpperCAmelCase  :			Optional[int]	       =		Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"			)			) / "000000039769.png"			)
													_UpperCAmelCase  :			Optional[int]	       =		self.tool(_lowerCamelCase			)
													self.assertEqual(_lowerCamelCase	,						"two cats sleeping on a couch"			)

						def 						a__ (					self		:			str			):
													_UpperCAmelCase  :			List[str]	       =		Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"			)			) / "000000039769.png"			)
													_UpperCAmelCase  :			Optional[Any]	       =		self.remote_tool(_lowerCamelCase			)
													self.assertEqual(_lowerCamelCase	,						"two cats sleeping on a couch"			)

						def 						a__ (					self		:			Union[str, Any]			):
													_UpperCAmelCase  :			Any	       =		Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"			)			) / "000000039769.png"			)
													_UpperCAmelCase  :			Union[str, Any]	       =		self.tool(image=_lowerCamelCase			)
													self.assertEqual(_lowerCamelCase	,						"two cats sleeping on a couch"			)






						def 						a__ (					self		:			Optional[int]			):
													_UpperCAmelCase  :			str	       =		Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"			)			) / "000000039769.png"			)
													_UpperCAmelCase  :			str	       =		self.remote_tool(image=_lowerCamelCase			)
													self.assertEqual(_lowerCamelCase	,						"two cats sleeping on a couch"			)




