


import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
					import torch

					from transformers.generation import DisjunctiveConstraint







@require_torch
class 			lowercase    (	unittest.TestCase      ):




				def    a							( self	):
											# For consistency across different places the DisjunctiveConstraint is called,
											# dc.token_ids is a list of integers. It is also initialized only by integers.

											snake_case_          =   [[1, 2, 4], [1, 2, 3, 4]]
											snake_case_          =   DisjunctiveConstraint(snake_case	)
											self.assertTrue(isinstance(dc.token_ids				,       snake_case	)	)

											with self.assertRaises(snake_case	):
																		DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]	)	)

											with self.assertRaises(snake_case	):
																		DisjunctiveConstraint([torch.LongTensor([1, 2, 4]	), torch.LongTensor([1, 2, 3, 4, 5]	)]	)




				def    a							( self	):
											# We can't have constraints that are complete subsets of another. This leads to a preverse
											# interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
											# It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
											# fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
											# will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
											snake_case_          =   [[1, 2], [1, 2, 3, 4]]

											with self.assertRaises(snake_case	):
																		DisjunctiveConstraint(snake_case	)  # fails here




				def    a							( self	):
											snake_case_          =   [[1, 2, 3], [1, 2, 4]]

											snake_case_          =   DisjunctiveConstraint(snake_case	)

											snake_case_    ,   snake_case_    ,   snake_case_          =   dc.update(1	)
											snake_case_          =   stepped is True and completed is False and reset is False
											self.assertTrue(snake_case	)
											self.assertTrue(not dc.completed	)
											self.assertTrue(dc.current_seq == [1]	)

											snake_case_    ,   snake_case_    ,   snake_case_          =   dc.update(2	)
											snake_case_          =   stepped is True and completed is False and reset is False
											self.assertTrue(snake_case	)
											self.assertTrue(not dc.completed	)
											self.assertTrue(dc.current_seq == [1, 2]	)

											snake_case_    ,   snake_case_    ,   snake_case_          =   dc.update(3	)
											snake_case_          =   stepped is True and completed is True and reset is False
											self.assertTrue(snake_case	)
											self.assertTrue(dc.completed	)  # Completed!
											self.assertTrue(dc.current_seq == [1, 2, 3]	)




				def    a							( self	):
											snake_case_          =   [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

											snake_case_          =   DisjunctiveConstraint(snake_case	)

											snake_case_    ,   snake_case_    ,   snake_case_          =   dc.update(1	)
											self.assertTrue(not dc.completed	)
											self.assertTrue(dc.current_seq == [1]	)

											snake_case_    ,   snake_case_    ,   snake_case_          =   dc.update(2	)
											self.assertTrue(not dc.completed	)
											self.assertTrue(dc.current_seq == [1, 2]	)

											snake_case_    ,   snake_case_    ,   snake_case_          =   dc.update(4	)
											self.assertTrue(not dc.completed	)
											self.assertTrue(dc.current_seq == [1, 2, 4]	)

											snake_case_    ,   snake_case_    ,   snake_case_          =   dc.update(5	)
											self.assertTrue(dc.completed	)  # Completed!
											self.assertTrue(dc.current_seq == [1, 2, 4, 5]	)

											dc.reset()

											snake_case_    ,   snake_case_    ,   snake_case_          =   dc.update(1	)
											self.assertTrue(not dc.completed	)
											self.assertTrue(dc.remaining() == 3	)
											self.assertTrue(dc.current_seq == [1]	)

											snake_case_    ,   snake_case_    ,   snake_case_          =   dc.update(2	)
											self.assertTrue(not dc.completed	)
											self.assertTrue(dc.remaining() == 2	)
											self.assertTrue(dc.current_seq == [1, 2]	)

											snake_case_    ,   snake_case_    ,   snake_case_          =   dc.update(5	)
											self.assertTrue(dc.completed	)  # Completed!
											self.assertTrue(dc.remaining() == 0	)
											self.assertTrue(dc.current_seq == [1, 2, 5]	)







import os
import sys
import unittest


_UpperCAmelCase		:       str						    =	os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, """utils"""))

import get_test_info  # noqa: E402
from get_test_info import (  # noqa: E402
    get_model_to_test_mapping,
    get_model_to_tester_mapping,
    get_test_to_tester_mapping,
)


_UpperCAmelCase		:       List[Any]						    =	os.path.join("""tests""", """models""", """bert""", """test_modeling_bert.py""")
_UpperCAmelCase		:       Dict						    =	os.path.join("""tests""", """models""", """blip""", """test_modeling_blip.py""")







class 			lowercase    (	unittest.TestCase      ):




				def    a							( self	):
											snake_case_          =   get_test_to_tester_mapping(snake_case	)
											snake_case_          =   get_test_to_tester_mapping(snake_case	)

											snake_case_          =   {'BertModelTest': 'BertModelTester'}

											snake_case_          =   {
											    'BlipModelTest': 'BlipModelTester',
											    'BlipTextImageModelTest': 'BlipTextImageModelsModelTester',
											    'BlipTextModelTest': 'BlipTextModelTester',
											    'BlipTextRetrievalModelTest': 'BlipTextRetrievalModelTester',
											    'BlipVQAModelTest': 'BlipVQAModelTester',
											    'BlipVisionModelTest': 'BlipVisionModelTester',
											}

											self.assertEqual(get_test_info.to_json(snake_case	)				,       snake_case	)
											self.assertEqual(get_test_info.to_json(snake_case	)				,       snake_case	)




				def    a							( self	):
											snake_case_          =   get_model_to_test_mapping(snake_case	)
											snake_case_          =   get_model_to_test_mapping(snake_case	)

											snake_case_          =   {
											    'BertForMaskedLM': ['BertModelTest'],
											    'BertForMultipleChoice': ['BertModelTest'],
											    'BertForNextSentencePrediction': ['BertModelTest'],
											    'BertForPreTraining': ['BertModelTest'],
											    'BertForQuestionAnswering': ['BertModelTest'],
											    'BertForSequenceClassification': ['BertModelTest'],
											    'BertForTokenClassification': ['BertModelTest'],
											    'BertLMHeadModel': ['BertModelTest'],
											    'BertModel': ['BertModelTest'],
											}

											snake_case_          =   {
											    'BlipForConditionalGeneration': ['BlipTextImageModelTest'],
											    'BlipForImageTextRetrieval': ['BlipTextRetrievalModelTest'],
											    'BlipForQuestionAnswering': ['BlipVQAModelTest'],
											    'BlipModel': ['BlipModelTest'],
											    'BlipTextModel': ['BlipTextModelTest'],
											    'BlipVisionModel': ['BlipVisionModelTest'],
											}

											self.assertEqual(get_test_info.to_json(snake_case	)				,       snake_case	)
											self.assertEqual(get_test_info.to_json(snake_case	)				,       snake_case	)




				def    a							( self	):
											snake_case_          =   get_model_to_tester_mapping(snake_case	)
											snake_case_          =   get_model_to_tester_mapping(snake_case	)

											snake_case_          =   {
											    'BertForMaskedLM': ['BertModelTester'],
											    'BertForMultipleChoice': ['BertModelTester'],
											    'BertForNextSentencePrediction': ['BertModelTester'],
											    'BertForPreTraining': ['BertModelTester'],
											    'BertForQuestionAnswering': ['BertModelTester'],
											    'BertForSequenceClassification': ['BertModelTester'],
											    'BertForTokenClassification': ['BertModelTester'],
											    'BertLMHeadModel': ['BertModelTester'],
											    'BertModel': ['BertModelTester'],
											}

											snake_case_          =   {
											    'BlipForConditionalGeneration': ['BlipTextImageModelsModelTester'],
											    'BlipForImageTextRetrieval': ['BlipTextRetrievalModelTester'],
											    'BlipForQuestionAnswering': ['BlipVQAModelTester'],
											    'BlipModel': ['BlipModelTester'],
											    'BlipTextModel': ['BlipTextModelTester'],
											    'BlipVisionModel': ['BlipVisionModelTester'],
											}

											self.assertEqual(get_test_info.to_json(snake_case	)				,       snake_case	)
											self.assertEqual(get_test_info.to_json(snake_case	)				,       snake_case	)




