


"""simple docstring"""





import tempfile
import unittest

from transformers import SPIECE_UNDERLINE, BatchEncoding, PLBartTokenizer, is_torch_available
from transformers.testing_utils import (
    get_tests_dir,
    nested_simplify,
    require_sentencepiece,
    require_tokenizers,
    require_torch,
)

from ...test_tokenization_common import TokenizerTesterMixin


snake_case__						:   List[str]			 = get_tests_dir('''fixtures/test_sentencepiece.model''')


if is_torch_available():
 from transformers.models.plbart.modeling_plbart import shift_tokens_right

snake_case__						:   Union[str, Any]			 = 50_003
snake_case__						:   Optional[int]			 = 50_002



@require_sentencepiece
@require_tokenizers
class 						snake_case_(				_a							,    unittest.TestCase	):
     __UpperCamelCase     =    PLBartTokenizer
     __UpperCamelCase     =    None
     __UpperCamelCase     =    False






     def    lowerCamelCase__   (		self     :    int ):
           super().setUp()

           # We have a SentencePiece fixture for testing
           lowerCAmelCase    :		List[str]				=      PLBartTokenizer(__UpperCAmelCase    , language_codes='''base'''    , keep_accents=__UpperCAmelCase )
           tokenizer.save_pretrained(self.tmpdirname )






     def    lowerCamelCase__   (		self     :    List[str] ):
           lowerCAmelCase    :		List[Any]				=      PLBartTokenizer(__UpperCAmelCase    , language_codes='''base'''    , keep_accents=__UpperCAmelCase )

           lowerCAmelCase    :		Tuple				=      tokenizer.tokenize('''This is a test''' )
           self.assertListEqual(__UpperCAmelCase    , ['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est'''] )

           self.assertListEqual(
               tokenizer.convert_tokens_to_ids(__UpperCAmelCase )    , [value + tokenizer.fairseq_offset for value in [2_8_5, 4_6, 1_0, 1_7_0, 3_8_2]]    , )

           lowerCAmelCase    :		Union[str, Any]				=      tokenizer.tokenize('''I was born in 92000, and this is falsé.''' )
           self.assertListEqual(
               __UpperCAmelCase    , [
                   SPIECE_UNDERLINE + '''I''',
                   SPIECE_UNDERLINE + '''was''',
                   SPIECE_UNDERLINE + '''b''',
                   '''or''',
                   '''n''',
                   SPIECE_UNDERLINE + '''in''',
                   SPIECE_UNDERLINE + '''''',
                   '''9''',
                   '''2''',
                   '''0''',
                   '''0''',
                   '''0''',
                   ''',''',
                   SPIECE_UNDERLINE + '''and''',
                   SPIECE_UNDERLINE + '''this''',
                   SPIECE_UNDERLINE + '''is''',
                   SPIECE_UNDERLINE + '''f''',
                   '''al''',
                   '''s''',
                   '''é''',
                   '''.''',
               ]    , )
           lowerCAmelCase    :		Tuple				=      tokenizer.convert_tokens_to_ids(__UpperCAmelCase )
           self.assertListEqual(
               __UpperCAmelCase    , [
                   value + tokenizer.fairseq_offset
                   for value in [8, 2_1, 8_4, 5_5, 2_4, 1_9, 7, 2, 6_0_2, 3_4_7, 3_4_7, 3_4_7, 3, 1_2, 6_6, 4_6, 7_2, 8_0, 6, 2, 4]
               ]    , )

           lowerCAmelCase    :		Union[str, Any]				=      tokenizer.convert_ids_to_tokens(__UpperCAmelCase )
           self.assertListEqual(
               __UpperCAmelCase    , [
                   SPIECE_UNDERLINE + '''I''',
                   SPIECE_UNDERLINE + '''was''',
                   SPIECE_UNDERLINE + '''b''',
                   '''or''',
                   '''n''',
                   SPIECE_UNDERLINE + '''in''',
                   SPIECE_UNDERLINE + '''''',
                   '''<unk>''',
                   '''2''',
                   '''0''',
                   '''0''',
                   '''0''',
                   ''',''',
                   SPIECE_UNDERLINE + '''and''',
                   SPIECE_UNDERLINE + '''this''',
                   SPIECE_UNDERLINE + '''is''',
                   SPIECE_UNDERLINE + '''f''',
                   '''al''',
                   '''s''',
                   '''<unk>''',
                   '''.''',
               ]    , )

           lowerCAmelCase    :		List[str]				=      tokenizer.vocab_size
           lowerCAmelCase    :		Union[str, Any]				=      [tokenizer.convert_ids_to_tokens(__UpperCAmelCase ) for x in range(end - 4    , __UpperCAmelCase )]

           self.assertListEqual(__UpperCAmelCase    , ['''__java__''', '''__python__''', '''__en_XX__''', '''<mask>'''] )

           lowerCAmelCase    :		Union[str, Any]				=      "java.lang.Exception, python.lang.Exception, javascript, php, ruby, go"
           lowerCAmelCase    :		Tuple				=      tokenizer(__UpperCAmelCase ).input_ids
           self.assertEqual(
               tokenizer.decode(__UpperCAmelCase    , skip_special_tokens=__UpperCAmelCase    , clean_up_tokenization_spaces=__UpperCAmelCase )    , __UpperCAmelCase    , )






     def    lowerCamelCase__   (		self     :    int ):
           lowerCAmelCase    :		Any				=      PLBartTokenizer(__UpperCAmelCase    , language_codes='''multi'''    , keep_accents=__UpperCAmelCase )

           lowerCAmelCase    :		Optional[int]				=      tokenizer.tokenize('''This is a test''' )
           self.assertListEqual(__UpperCAmelCase    , ['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est'''] )

           self.assertListEqual(
               tokenizer.convert_tokens_to_ids(__UpperCAmelCase )    , [value + tokenizer.fairseq_offset for value in [2_8_5, 4_6, 1_0, 1_7_0, 3_8_2]]    , )

           lowerCAmelCase    :		List[str]				=      tokenizer.tokenize('''I was born in 92000, and this is falsé.''' )
           self.assertListEqual(
               __UpperCAmelCase    , [
                   SPIECE_UNDERLINE + '''I''',
                   SPIECE_UNDERLINE + '''was''',
                   SPIECE_UNDERLINE + '''b''',
                   '''or''',
                   '''n''',
                   SPIECE_UNDERLINE + '''in''',
                   SPIECE_UNDERLINE + '''''',
                   '''9''',
                   '''2''',
                   '''0''',
                   '''0''',
                   '''0''',
                   ''',''',
                   SPIECE_UNDERLINE + '''and''',
                   SPIECE_UNDERLINE + '''this''',
                   SPIECE_UNDERLINE + '''is''',
                   SPIECE_UNDERLINE + '''f''',
                   '''al''',
                   '''s''',
                   '''é''',
                   '''.''',
               ]    , )
           lowerCAmelCase    :		Optional[int]				=      tokenizer.convert_tokens_to_ids(__UpperCAmelCase )
           self.assertListEqual(
               __UpperCAmelCase    , [
                   value + tokenizer.fairseq_offset
                   for value in [8, 2_1, 8_4, 5_5, 2_4, 1_9, 7, 2, 6_0_2, 3_4_7, 3_4_7, 3_4_7, 3, 1_2, 6_6, 4_6, 7_2, 8_0, 6, 2, 4]
               ]    , )

           lowerCAmelCase    :		Dict				=      tokenizer.convert_ids_to_tokens(__UpperCAmelCase )
           self.assertListEqual(
               __UpperCAmelCase    , [
                   SPIECE_UNDERLINE + '''I''',
                   SPIECE_UNDERLINE + '''was''',
                   SPIECE_UNDERLINE + '''b''',
                   '''or''',
                   '''n''',
                   SPIECE_UNDERLINE + '''in''',
                   SPIECE_UNDERLINE + '''''',
                   '''<unk>''',
                   '''2''',
                   '''0''',
                   '''0''',
                   '''0''',
                   ''',''',
                   SPIECE_UNDERLINE + '''and''',
                   SPIECE_UNDERLINE + '''this''',
                   SPIECE_UNDERLINE + '''is''',
                   SPIECE_UNDERLINE + '''f''',
                   '''al''',
                   '''s''',
                   '''<unk>''',
                   '''.''',
               ]    , )
           lowerCAmelCase    :		Any				=      tokenizer.vocab_size
           lowerCAmelCase    :		Tuple				=      [tokenizer.convert_ids_to_tokens(__UpperCAmelCase ) for x in range(end - 7    , __UpperCAmelCase )]

           self.assertListEqual(
               __UpperCAmelCase    , ['''__java__''', '''__python__''', '''__en_XX__''', '''__javascript__''', '''__php__''', '''__ruby__''', '''__go__'''] )
           lowerCAmelCase    :		Dict				=      "java.lang.Exception, python.lang.Exception, javascript, php, ruby, go"
           lowerCAmelCase    :		Optional[Any]				=      tokenizer(__UpperCAmelCase ).input_ids
           self.assertEqual(
               tokenizer.decode(__UpperCAmelCase    , skip_special_tokens=__UpperCAmelCase    , clean_up_tokenization_spaces=__UpperCAmelCase )    , __UpperCAmelCase    , )



@require_torch
@require_sentencepiece
@require_tokenizers
class 						snake_case_(				unittest.TestCase	):
     __UpperCamelCase     =    """uclanlp/plbart-python-en_XX"""
     __UpperCamelCase     =    [
         """def maximum(a,b,c):NEW_LINE_INDENTreturn max([a,b,c])""",
         """def sum(a,b,c):NEW_LINE_INDENTreturn sum([a,b,c])""",
     ]
     __UpperCamelCase     =    [
         """Returns the maximum value of a b c.""",
         """Sums the values of a b c.""",
     ]
     __UpperCamelCase     =    [
         134,
         5_452,
         33_460,
         33_441,
         33_463,
         33_465,
         33_463,
         33_449,
         988,
         20,
         33_456,
         19,
         33_456,
         771,
         39,
         4_258,
         889,
         3_318,
         33_441,
         33_463,
         33_465,
         33_463,
         33_449,
         2_471,
         2,
         PYTHON_CODE,
     ]






     @classmethod
     def    lowerCamelCase__   (		cls     :    Optional[Any] ):
           lowerCAmelCase    :		PLBartTokenizer				=      PLBartTokenizer.from_pretrained(
               cls.checkpoint_name    , language_codes='''base'''    , src_lang='''python'''    , tgt_lang='''en_XX''' )
           lowerCAmelCase    :		Union[str, Any]				=      1
           return cls






     def    lowerCamelCase__   (		self     :    Any ):
           self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''__java__''']    , 5_0_0_0_1 )
           self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''__python__''']    , 5_0_0_0_2 )
           self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''__en_XX__''']    , 5_0_0_0_3 )






     def    lowerCamelCase__   (		self     :    List[Any] ):
           lowerCAmelCase    :		Any				=      self.tokenizer.batch_encode_plus(self.src_text ).input_ids[0]
           self.assertListEqual(self.expected_src_tokens    , __UpperCAmelCase )






     def    lowerCamelCase__   (		self     :    Tuple ):
           self.assertIn(__UpperCAmelCase    , self.tokenizer.all_special_ids )
           lowerCAmelCase    :		Tuple				=      [EN_CODE, 9_0_3_7, 3_3_4_4_2, 5_7, 7_5_2, 1_5_3, 1_4, 5_6, 1_8, 9, 2]
           lowerCAmelCase    :		str				=      self.tokenizer.decode(__UpperCAmelCase    , skip_special_tokens=__UpperCAmelCase )
           lowerCAmelCase    :		List[Any]				=      self.tokenizer.decode(generated_ids[1:]    , skip_special_tokens=__UpperCAmelCase )
           self.assertEqual(__UpperCAmelCase    , __UpperCAmelCase )
           self.assertNotIn(self.tokenizer.eos_token    , __UpperCAmelCase )






     def    lowerCamelCase__   (		self     :    Any ):
           lowerCAmelCase    :		Dict				=      ["def sum(a,b,c):NEW_LINE_INDENTreturn sum([a,b,c])" * 2_0]
           self.assertIsInstance(src_text[0]    , __UpperCAmelCase )
           lowerCAmelCase    :		List[str]				=      1_0
           lowerCAmelCase    :		Union[str, Any]				=      self.tokenizer(__UpperCAmelCase    , max_length=__UpperCAmelCase    , truncation=__UpperCAmelCase ).input_ids[0]
           self.assertEqual(ids[-2]    , 2 )
           self.assertEqual(ids[-1]    , __UpperCAmelCase )
           self.assertEqual(len(__UpperCAmelCase )    , __UpperCAmelCase )






     def    lowerCamelCase__   (		self     :    int ):
           self.assertListEqual(self.tokenizer.convert_tokens_to_ids(['''<mask>''', '''__java__'''] )    , [5_0_0_0_4, 5_0_0_0_1] )






     def    lowerCamelCase__   (		self     :    Optional[int] ):
           lowerCAmelCase    :		Union[str, Any]				=      tempfile.mkdtemp()
           lowerCAmelCase    :		Dict				=      self.tokenizer.fairseq_tokens_to_ids
           self.tokenizer.save_pretrained(__UpperCAmelCase )
           lowerCAmelCase    :		Optional[int]				=      PLBartTokenizer.from_pretrained(__UpperCAmelCase )
           self.assertDictEqual(new_tok.fairseq_tokens_to_ids    , __UpperCAmelCase )






     @require_torch
     def    lowerCamelCase__   (		self     :    Tuple ):
           lowerCAmelCase    :		Optional[int]				=      self.tokenizer(self.src_text    , text_target=self.tgt_text    , padding=__UpperCAmelCase    , return_tensors='''pt''' )
           lowerCAmelCase    :		Optional[int]				=      shift_tokens_right(batch['''labels''']    , self.tokenizer.pad_token_id )

           # fairseq batch: https://gist.github.com/sshleifer/cba08bc2109361a74ac3760a7e30e4f4
           self.assertEqual(batch.input_ids[1][-2:].tolist()    , [2, PYTHON_CODE] )
           self.assertEqual(batch.decoder_input_ids[1][0]    , __UpperCAmelCase )
           self.assertEqual(batch.decoder_input_ids[1][-1]    , 2 )
           self.assertEqual(batch.labels[1][-2:].tolist()    , [2, EN_CODE] )






     @require_torch
     def    lowerCamelCase__   (		self     :    Optional[Any] ):
           lowerCAmelCase    :		Union[str, Any]				=      self.tokenizer(
               self.src_text    , text_target=self.tgt_text    , padding=__UpperCAmelCase    , truncation=__UpperCAmelCase    , max_length=len(self.expected_src_tokens )    , return_tensors='''pt'''    , )
           lowerCAmelCase    :		Tuple				=      shift_tokens_right(batch['''labels''']    , self.tokenizer.pad_token_id )

           self.assertIsInstance(__UpperCAmelCase    , __UpperCAmelCase )

           self.assertEqual((2, 2_6)    , batch.input_ids.shape )
           self.assertEqual((2, 2_6)    , batch.attention_mask.shape )
           lowerCAmelCase    :		List[str]				=      batch.input_ids.tolist()[0]
           self.assertListEqual(self.expected_src_tokens    , __UpperCAmelCase )
           self.assertEqual(2    , batch.decoder_input_ids[0, -1] )  # EOS
           # Test that special tokens are reset
           self.assertEqual(self.tokenizer.prefix_tokens    , [] )
           self.assertEqual(self.tokenizer.suffix_tokens    , [self.tokenizer.eos_token_id, PYTHON_CODE] )






     def    lowerCamelCase__   (		self     :    str ):
           lowerCAmelCase    :		Tuple				=      self.tokenizer(self.src_text    , padding=__UpperCAmelCase    , truncation=__UpperCAmelCase    , max_length=3    , return_tensors='''pt''' )
           lowerCAmelCase    :		Optional[Any]				=      self.tokenizer(
               text_target=self.tgt_text    , padding=__UpperCAmelCase    , truncation=__UpperCAmelCase    , max_length=1_0    , return_tensors='''pt''' )
           lowerCAmelCase    :		Dict				=      targets["input_ids"]
           lowerCAmelCase    :		str				=      shift_tokens_right(__UpperCAmelCase    , self.tokenizer.pad_token_id )

           self.assertEqual(batch.input_ids.shape[1]    , 3 )
           self.assertEqual(batch.decoder_input_ids.shape[1]    , 1_0 )






     @require_torch
     def    lowerCamelCase__   (		self     :    Dict ):
           lowerCAmelCase    :		Optional[int]				=      self.tokenizer._build_translation_inputs(
               '''A test'''    , return_tensors='''pt'''    , src_lang='''en_XX'''    , tgt_lang='''java''' )

           self.assertEqual(
               nested_simplify(__UpperCAmelCase )    , {
                   # A, test, EOS, en_XX
                   '''input_ids''': [[1_5_0, 2_4_2, 2, 5_0_0_0_3]],
                   '''attention_mask''': [[1, 1, 1, 1]],
                   # java
                   '''forced_bos_token_id''': 5_0_0_0_1,
               }    , )






"""simple docstring"""







from itertools import permutations


def      lowercase			(				A_       )->      bool:
  '''simple docstring'''







  if num[3] % 2 != 0:
    return False

  if (num[2] + num[3] + num[4]) % 3 != 0:
    return False

  if num[5] % 5 != 0:
    return False

  a						:		Optional[int]      							=			[7, 11, 13, 17]
  for i, test in enumerate(A_       ):
    if (num[i + 4] * 100 + num[i + 5] * 10 + num[i + 6]) % test != 0:
      return False
  return True


def      lowercase			(				A_ = 10       )->      int:
  '''simple docstring'''







  return sum(
      int("".join(map(A_  ,   A_       )       )       )
      for num in permutations(range(A_       )       )
      if is_substring_divisible(A_       )       )


if __name__ == "__main__":
 print(f'''{solution() = }''')






