"""simple docstring"""



import unittest

from transformers import AutoTokenizer, FalconConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
     import torch

     from transformers import (
         FalconForCausalLM,
         FalconForQuestionAnswering,
         FalconForSequenceClassification,
         FalconForTokenClassification,
         FalconModel,
     )

class SCREAMING_SNAKE_CASE  :







 """simple docstring"""


 def __init__( self		:   Tuple       , _snake_case		:   List[str]       , _snake_case		:   Optional[Any]=3       , _snake_case		:   Optional[Any]=7       , _snake_case		:   Any=True       , _snake_case		:   str=True       , _snake_case		:   Optional[Any]=False       , _snake_case		:   Any=True       , _snake_case		:   int=99       , _snake_case		:   Any=32       , _snake_case		:   Any=5       , _snake_case		:   Any=4       , _snake_case		:   str=37       , _snake_case		:   str="gelu"       , _snake_case		:   int=0.1       , _snake_case		:   List[str]=0.1       , _snake_case		:   str=512       , _snake_case		:   str=16       , _snake_case		:   Optional[int]=2       , _snake_case		:   Optional[Any]=0.02       , _snake_case		:   Union[str, Any]=3       , _snake_case		:   Any=4       , _snake_case		:   List[Any]=None       , )					->      Dict:




    '''simple docstring'''






    a__  					=		parent
    a__  					=		batch_size
    a__  					=		seq_length
    a__  					=		is_training
    a__  					=		use_input_mask
    a__  					=		use_token_type_ids
    a__  					=		use_labels
    a__  					=		vocab_size
    a__  					=		hidden_size
    a__  					=		num_hidden_layers
    a__  					=		num_attention_heads
    a__  					=		intermediate_size
    a__  					=		hidden_act
    a__  					=		hidden_dropout_prob
    a__  					=		attention_probs_dropout_prob
    a__  					=		max_position_embeddings
    a__  					=		type_vocab_size
    a__  					=		type_sequence_label_size
    a__  					=		initializer_range
    a__  					=		num_labels
    a__  					=		num_choices
    a__  					=		scope


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




    '''simple docstring'''






    a__  					=		ids_tensor([self.batch_size, self.seq_length]       , self.vocab_size					)

    a__  					=		None
    if self.use_input_mask:
       a__  					=		random_attention_mask([self.batch_size, self.seq_length]					)

    a__  					=		None

    a__  					=		None
    a__  					=		None
    a__  					=		None
    if self.use_labels:
       a__  					=		ids_tensor([self.batch_size]       , self.type_sequence_label_size					)
       a__  					=		ids_tensor([self.batch_size, self.seq_length]       , self.num_labels					)
       a__  					=		ids_tensor([self.batch_size]       , self.num_choices					)

    a__  					=		self.get_config()

    return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


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




    '''simple docstring'''






    return FalconConfig(
        vocab_size=self.vocab_size       , hidden_size=self.hidden_size       , num_hidden_layers=self.num_hidden_layers       , num_attention_heads=self.num_attention_heads       , intermediate_size=self.intermediate_size       , hidden_act=self.hidden_act       , hidden_dropout_prob=self.hidden_dropout_prob       , attention_probs_dropout_prob=self.attention_probs_dropout_prob       , max_position_embeddings=self.max_position_embeddings       , type_vocab_size=self.type_vocab_size       , is_decoder=__lowerCAmelCase       , initializer_range=self.initializer_range       , pad_token_id=1       , new_decoder_architecture=__lowerCAmelCase       , )


 def 							_lowerCAmelCase					( self		:   str       , _snake_case		:   int       , _snake_case		:   Dict       , _snake_case		:   Union[str, Any]       , _snake_case		:   str       , _snake_case		:   Any       , _snake_case		:   Any       , _snake_case		:   List[str]					)					->      str:




    '''simple docstring'''






    a__  					=		FalconModel(config=__lowerCAmelCase					)
    model.to(__lowerCAmelCase					)
    model.eval()
    a__  					=		model(__lowerCAmelCase       , attention_mask=__lowerCAmelCase					)
    a__  					=		model(__lowerCAmelCase					)
    self.parent.assertEqual(result.last_hidden_state.shape       , (self.batch_size, self.seq_length, self.hidden_size)					)


 def 							_lowerCAmelCase					( self		:   int       , _snake_case		:   Tuple       , _snake_case		:   List[str]       , _snake_case		:   List[Any]       , _snake_case		:   Any       , _snake_case		:   Union[str, Any]       , _snake_case		:   Optional[Any]       , _snake_case		:   int       , _snake_case		:   List[str]       , _snake_case		:   Union[str, Any]       , )					->      Tuple:




    '''simple docstring'''






    a__  					=		True
    a__  					=		FalconModel(__lowerCAmelCase					)
    model.to(__lowerCAmelCase					)
    model.eval()
    a__  					=		model(
        __lowerCAmelCase       , attention_mask=__lowerCAmelCase       , encoder_hidden_states=__lowerCAmelCase       , encoder_attention_mask=__lowerCAmelCase       , )
    a__  					=		model(
        __lowerCAmelCase       , attention_mask=__lowerCAmelCase       , encoder_hidden_states=__lowerCAmelCase       , )
    a__  					=		model(__lowerCAmelCase       , attention_mask=__lowerCAmelCase					)
    self.parent.assertEqual(result.last_hidden_state.shape       , (self.batch_size, self.seq_length, self.hidden_size)					)


 def 							_lowerCAmelCase					( self		:   Tuple       , _snake_case		:   Any       , _snake_case		:   Optional[Any]       , _snake_case		:   Dict       , _snake_case		:   Optional[Any]       , _snake_case		:   Any       , _snake_case		:   Union[str, Any]       , _snake_case		:   Dict       , _snake_case		:   Any       , _snake_case		:   List[str]       , )					->      Dict:




    '''simple docstring'''






    a__  					=		FalconForCausalLM(config=__lowerCAmelCase					)
    model.to(__lowerCAmelCase					)
    model.eval()
    a__  					=		model(__lowerCAmelCase       , attention_mask=__lowerCAmelCase       , labels=__lowerCAmelCase					)
    self.parent.assertEqual(result.logits.shape       , (self.batch_size, self.seq_length, self.vocab_size)					)


 def 							_lowerCAmelCase					( self		:   Tuple       , _snake_case		:   List[str]       , _snake_case		:   Any       , _snake_case		:   Any       , _snake_case		:   Tuple       , _snake_case		:   Any       , _snake_case		:   List[Any]       , _snake_case		:   str       , _snake_case		:   Union[str, Any]       , _snake_case		:   int       , )					->      Tuple:




    '''simple docstring'''






    a__  					=		True
    a__  					=		True
    a__  					=		FalconForCausalLM(config=__lowerCAmelCase					)
    model.to(__lowerCAmelCase					)
    model.eval()

    # first forward pass
    a__  					=		model(
        __lowerCAmelCase       , attention_mask=__lowerCAmelCase       , encoder_hidden_states=__lowerCAmelCase       , encoder_attention_mask=__lowerCAmelCase       , use_cache=__lowerCAmelCase       , )
    a__  					=		outputs.past_key_values

    # create hypothetical multiple next token and extent to next_input_ids
    a__  					=		ids_tensor((self.batch_size, 3)       , config.vocab_size					)
    a__  					=		ids_tensor((self.batch_size, 3)       , vocab_size=2					)

    # append to next input_ids and
    a__  					=		torch.cat([input_ids, next_tokens]       , dim=-1					)
    a__  					=		torch.cat([input_mask, next_mask]       , dim=-1					)

    a__  					=		model(
        __lowerCAmelCase       , attention_mask=__lowerCAmelCase       , encoder_hidden_states=__lowerCAmelCase       , encoder_attention_mask=__lowerCAmelCase       , output_hidden_states=__lowerCAmelCase       , )['hidden_states'][0]
    a__  					=		model(
        __lowerCAmelCase       , attention_mask=__lowerCAmelCase       , encoder_hidden_states=__lowerCAmelCase       , encoder_attention_mask=__lowerCAmelCase       , past_key_values=__lowerCAmelCase       , output_hidden_states=__lowerCAmelCase       , )['hidden_states'][0]

    # select random slice
    a__  					=		ids_tensor((1,)       , output_from_past.shape[-1]					).item()
    a__  					=		output_from_no_past[:, -3:, random_slice_idx].detach()
    a__  					=		output_from_past[:, :, random_slice_idx].detach()

    self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]					)

    # test that outputs are equal for slice
    self.parent.assertTrue(torch.allclose(__lowerCAmelCase       , __lowerCAmelCase       , atol=1E-3					)					)



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




    '''simple docstring'''






    a__  					=		self.prepare_config_and_inputs()
    (
        (
        a__     
    )					,							(
        a__     
    )					,							(
        a__     
    )					,							(
        a__     
    )					,							(
        a__     
    )					,							(
        a__     
    )					,							(
        a__     
    )					,							     
    )  					=		config_and_inputs
    a__  					=		{'input_ids': input_ids, 'attention_mask': input_mask}
    return config, inputs_dict

@require_torch
class SCREAMING_SNAKE_CASE  (     a ,   a ,   a ,   unittest.TestCase						):







 """simple docstring"""


 a_							:						Dict	      =(
     (
         FalconModel,
         FalconForCausalLM,
         FalconForSequenceClassification,
         FalconForTokenClassification,
         FalconForQuestionAnswering,
     )
     if is_torch_available()
     else ()
 )
 a_							:						Optional[Any]	      =(FalconForCausalLM,) if is_torch_available() else ()
 a_							:						int	      =(
     {
         '''feature-extraction''': FalconModel,
         '''text-classification''': FalconForSequenceClassification,
         '''text-generation''': FalconForCausalLM,
         '''question-answering''': FalconForQuestionAnswering,
         '''token-classification''': FalconForTokenClassification,
         '''zero-shot''': FalconForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 a_							:						Dict	      =False
 a_							:						Any	      =False


 def 							_lowerCAmelCase					( self		:   Any					)					->      str:




    '''simple docstring'''






    a__  					=		FalconModelTester(self					)
    a__  					=		ConfigTester(self       , config_class=__lowerCAmelCase       , hidden_size=37					)


 def 							_lowerCAmelCase					( self		:   int					)					->      int:




    '''simple docstring'''






    self.config_tester.run_common_tests()


 def 							_lowerCAmelCase					( self		:   Union[str, Any]					)					->      List[str]:




    '''simple docstring'''






    a__  					=		self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*__lowerCAmelCase					)


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




    '''simple docstring'''






    a__					,							*a__  					=		self.model_tester.prepare_config_and_inputs()
    for alibi in [True, False]:
       a__  					=		alibi
       self.model_tester.create_and_check_model(__lowerCAmelCase       , *__lowerCAmelCase					)


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




    '''simple docstring'''






    a__					,							a__  					=		self.model_tester.prepare_config_and_inputs_for_common()
    a__  					=		3
    a__  					=		input_dict['input_ids']
    a__  					=		input_ids.ne(1					).to(__lowerCAmelCase					)
    a__  					=		ids_tensor([self.model_tester.batch_size]       , self.model_tester.type_sequence_label_size					)
    a__  					=		FalconForSequenceClassification(__lowerCAmelCase					)
    model.to(__lowerCAmelCase					)
    model.eval()
    a__  					=		model(__lowerCAmelCase       , attention_mask=__lowerCAmelCase       , labels=__lowerCAmelCase					)
    self.assertEqual(result.logits.shape       , (self.model_tester.batch_size, self.model_tester.num_labels)					)


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




    '''simple docstring'''






    a__					,							a__  					=		self.model_tester.prepare_config_and_inputs_for_common()
    a__  					=		3
    a__  					=		'single_label_classification'
    a__  					=		input_dict['input_ids']
    a__  					=		input_ids.ne(1					).to(__lowerCAmelCase					)
    a__  					=		ids_tensor([self.model_tester.batch_size]       , self.model_tester.type_sequence_label_size					)
    a__  					=		FalconForSequenceClassification(__lowerCAmelCase					)
    model.to(__lowerCAmelCase					)
    model.eval()
    a__  					=		model(__lowerCAmelCase       , attention_mask=__lowerCAmelCase       , labels=__lowerCAmelCase					)
    self.assertEqual(result.logits.shape       , (self.model_tester.batch_size, self.model_tester.num_labels)					)


 def 							_lowerCAmelCase					( self		:   Any					)					->      Any:




    '''simple docstring'''






    a__					,							a__  					=		self.model_tester.prepare_config_and_inputs_for_common()
    a__  					=		input_dict['input_ids']
    a__  					=		FalconForCausalLM(__lowerCAmelCase					)
    model.to(__lowerCAmelCase					)
    model.eval()
    a__  					=		model(__lowerCAmelCase       , use_cache=__lowerCAmelCase					)
    a__  					=		input_ids.shape[0]
    a__  					=		model._convert_to_rw_cache(result.past_key_values					)
    a__  					=		model._convert_cache_to_standard_format(__lowerCAmelCase       , __lowerCAmelCase					)
    for layer in range(len(__lowerCAmelCase					)					):
       for tensor_idx in range(2					):
          self.assertTrue(rw_cache[layer][tensor_idx].ndim == 3					)
          self.assertTrue(result.past_key_values[layer][tensor_idx].ndim == 4					)
          self.assertTrue(
              torch.all(result.past_key_values[layer][tensor_idx] == standard_cache[layer][tensor_idx]					)					)


 def 							_lowerCAmelCase					( self		:   Any					)					->      Tuple:




    '''simple docstring'''






    a__					,							a__  					=		self.model_tester.prepare_config_and_inputs_for_common()
    a__  					=		3
    a__  					=		'multi_label_classification'
    a__  					=		input_dict['input_ids']
    a__  					=		input_ids.ne(1					).to(__lowerCAmelCase					)
    a__  					=		ids_tensor(
        [self.model_tester.batch_size, config.num_labels]       , self.model_tester.type_sequence_label_size					).to(torch.float					)
    a__  					=		FalconForSequenceClassification(__lowerCAmelCase					)
    model.to(__lowerCAmelCase					)
    model.eval()
    a__  					=		model(__lowerCAmelCase       , attention_mask=__lowerCAmelCase       , labels=__lowerCAmelCase					)
    self.assertEqual(result.logits.shape       , (self.model_tester.batch_size, self.model_tester.num_labels)					)



 def 							_lowerCAmelCase					( self		:   Any					)					->      Optional[Any]:




    '''simple docstring'''






    for model_class in self.all_generative_model_classes:
       a__					,							a__  					=		self.model_tester.prepare_config_and_inputs_for_common()

       # If it doesn't support cache, pass the test
       if not hasattr(__lowerCAmelCase       , 'use_cache'					):
          return

       a__  					=		model_class(__lowerCAmelCase					).to(__lowerCAmelCase					)
       if "use_cache" not in inputs:
          a__  					=		True
       a__  					=		model(**__lowerCAmelCase					)

       # If "past_key_values" is not returned, pass the test (e.g. RWKV uses a different cache name and format)
       if "past_key_values" not in outputs:
          return

       a__  					=		(
           getattr(__lowerCAmelCase       , 'decoder_layers'       , __lowerCAmelCase					)
           or getattr(__lowerCAmelCase       , 'num_decoder_layers'       , __lowerCAmelCase					)
           or config.num_hidden_layers
       )
       a__  					=		getattr(__lowerCAmelCase       , 'num_kv_heads'       , config.num_attention_heads					)
       a__  					=		getattr(__lowerCAmelCase       , 'd_model'       , config.hidden_size					)
       a__  					=		embed_dim // num_attention_heads

       a__  					=		outputs['past_key_values']
       self.assertEqual(len(__lowerCAmelCase					)       , __lowerCAmelCase					)

       a__					,							a__  					=		inputs['input_ids'].shape
       for i in range(__lowerCAmelCase					):
          if config.new_decoder_architecture:
             a__  					=		config.num_attention_heads
          elif config.multi_query:
             a__  					=		1
          self.assertEqual(len(past_kv[0]					)       , 2					)  # K V for the decoder = 2
          self.assertEqual(
              past_kv[i][0].shape       , (batch_size, num_attention_heads, seq_length, per_head_embed_dim)					)
          self.assertEqual(
              past_kv[i][1].shape       , (batch_size, num_attention_heads, seq_length, per_head_embed_dim)					)

@require_torch
class SCREAMING_SNAKE_CASE  (     unittest.TestCase						):







 """simple docstring"""


 @slow
 def 							_lowerCAmelCase					( self		:   int					)					->      List[str]:




    '''simple docstring'''






    a__  					=		AutoTokenizer.from_pretrained('Rocketknight1/falcon-rw-1b'					)
    a__  					=		FalconForCausalLM.from_pretrained('Rocketknight1/falcon-rw-1b'					)
    model.eval()
    model.to(__lowerCAmelCase					)
    a__  					=		tokenizer('My favorite food is'       , return_tensors='pt'					).to(__lowerCAmelCase					)

    a__  					=		(
        'My favorite food is pizza. I love it so much that I have a pizza party every year for my birthday.'
    )

    a__  					=		model.generate(**__lowerCAmelCase       , do_sample=__lowerCAmelCase       , max_new_tokens=19					)
    a__  					=		tokenizer.batch_decode(__lowerCAmelCase					)[0]

    self.assertEqual(__lowerCAmelCase       , __lowerCAmelCase					)


 @slow
 def 							_lowerCAmelCase					( self		:   Optional[int]					)					->      List[str]:




    '''simple docstring'''






    for repo in ["Rocketknight1/tiny-random-falcon-7b", "Rocketknight1/tiny-random-falcon-40b"]:
       a__  					=		AutoTokenizer.from_pretrained(__lowerCAmelCase					)
       a__  					=		FalconForCausalLM.from_pretrained(__lowerCAmelCase					)
       model.eval()
       model.to(__lowerCAmelCase					)
       a__  					=		tokenizer('My favorite food is'       , return_tensors='pt'					).to(__lowerCAmelCase					)

       # We just test that these run without errors - the models are randomly initialized
       # and so the actual text outputs will be garbage
       model.generate(**__lowerCAmelCase       , do_sample=__lowerCAmelCase       , max_new_tokens=4					)
       model.generate(**__lowerCAmelCase       , do_sample=__lowerCAmelCase       , max_new_tokens=4					)
       model.generate(**__lowerCAmelCase       , num_beams=2       , max_new_tokens=4					)



 @slow
 def 							_lowerCAmelCase					( self		:   Union[str, Any]					)					->      int:




    '''simple docstring'''






    with torch.no_grad():
       for repo in [
           "Rocketknight1/falcon-rw-1b",
           "Rocketknight1/tiny-random-falcon-7b",
           "Rocketknight1/tiny-random-falcon-40b",
       ]:
          a__  					=		AutoTokenizer.from_pretrained(__lowerCAmelCase					)
          a__  					=		FalconForCausalLM.from_pretrained(__lowerCAmelCase					)
          model.eval()
          model.to(device=__lowerCAmelCase					)
          a__  					=		tokenizer('My favorite food is'       , return_tensors='pt'					).to(__lowerCAmelCase					)

          # Test results are the same with and without cache
          a__  					=		model.generate(**__lowerCAmelCase       , do_sample=__lowerCAmelCase       , max_new_tokens=20       , use_cache=__lowerCAmelCase					)
          a__  					=		model.generate(**__lowerCAmelCase       , do_sample=__lowerCAmelCase       , max_new_tokens=20       , use_cache=__lowerCAmelCase					)
          self.assertTrue((outputs_cache - outputs_no_cache).sum().item() == 0					)









import re
import tempfile
from pathlib import Path

import pytest
import yaml

from datasets.utils.readme import ReadMe


# @pytest.fixture
# def example_yaml_structure():

A       :   Dict					= yaml.safe_load(
    '''\
name: ""
allow_empty: false
allow_empty_text: true
subsections:
  - name: "Dataset Card for X" # First-level markdown heading
    allow_empty: false
    allow_empty_text: true
    subsections:
      - name: "Table of Contents"
        allow_empty: false
        allow_empty_text: false
        subsections: null
      - name: "Dataset Description"
        allow_empty: false
        allow_empty_text: false
        subsections:
          - name: "Dataset Summary"
            allow_empty: false
            allow_empty_text: false
            subsections: null
          - name: "Supported Tasks and Leaderboards"
            allow_empty: true
            allow_empty_text: true
            subsections: null
          - name: Languages
            allow_empty: false
            allow_empty_text: true
            subsections: null
'''
)


A       :   str					= {
    '''name''': '''root''',
    '''text''': '''''',
    '''is_empty_text''': True,
    '''subsections''': [
        {
            '''name''': '''Dataset Card for My Dataset''',
            '''text''': '''''',
            '''is_empty_text''': True,
            '''subsections''': [
                {'''name''': '''Table of Contents''', '''text''': '''Some text here.''', '''is_empty_text''': False, '''subsections''': []},
                {
                    '''name''': '''Dataset Description''',
                    '''text''': '''Some text here.''',
                    '''is_empty_text''': False,
                    '''subsections''': [
                        {
                            '''name''': '''Dataset Summary''',
                            '''text''': '''Some text here.''',
                            '''is_empty_text''': False,
                            '''subsections''': [],
                        },
                        {
                            '''name''': '''Supported Tasks and Leaderboards''',
                            '''text''': '''''',
                            '''is_empty_text''': True,
                            '''subsections''': [],
                        },
                        {'''name''': '''Languages''', '''text''': '''Language Text''', '''is_empty_text''': False, '''subsections''': []},
                    ],
                },
            ],
        }
    ],
}


A       :   Union[str, Any]					= '''\
---
language:
- zh
- en
---

# Dataset Card for My Dataset
## Table of Contents
Some text here.
## Dataset Description
Some text here.
### Dataset Summary
Some text here.
### Supported Tasks and Leaderboards
### Languages
Language Text
'''


A       :   int					= '''\
---
language:
- zh
- en
---

# Dataset Card for My Dataset
## Table of Contents
Some text here.
## Dataset Description
Some text here.
### Dataset Summary
Some text here.
#### Extra Ignored Subsection
### Supported Tasks and Leaderboards
### Languages
Language Text
'''

A       :   Optional[int]					= {
    '''name''': '''root''',
    '''text''': '''''',
    '''is_empty_text''': True,
    '''subsections''': [
        {
            '''name''': '''Dataset Card for My Dataset''',
            '''text''': '''''',
            '''is_empty_text''': True,
            '''subsections''': [
                {'''name''': '''Table of Contents''', '''text''': '''Some text here.''', '''is_empty_text''': False, '''subsections''': []},
                {
                    '''name''': '''Dataset Description''',
                    '''text''': '''Some text here.''',
                    '''is_empty_text''': False,
                    '''subsections''': [
                        {
                            '''name''': '''Dataset Summary''',
                            '''text''': '''Some text here.''',
                            '''is_empty_text''': False,
                            '''subsections''': [
                                {
                                    '''name''': '''Extra Ignored Subsection''',
                                    '''text''': '''''',
                                    '''is_empty_text''': True,
                                    '''subsections''': [],
                                }
                            ],
                        },
                        {
                            '''name''': '''Supported Tasks and Leaderboards''',
                            '''text''': '''''',
                            '''is_empty_text''': True,
                            '''subsections''': [],
                        },
                        {'''name''': '''Languages''', '''text''': '''Language Text''', '''is_empty_text''': False, '''subsections''': []},
                    ],
                },
            ],
        }
    ],
}

A       :   str					= '''\
---
---
# Dataset Card for My Dataset
## Table of Contents
Some text here.
## Dataset Description
Some text here.
### Dataset Summary
Some text here.
### Supported Tasks and Leaderboards
### Languages
Language Text
'''

A       :   Optional[Any]					= (
    '''The following issues were found for the README at `{path}`:\n-\tEmpty YAML markers are present in the README.'''
)

A       :   List[Any]					= '''\
# Dataset Card for My Dataset
## Table of Contents
Some text here.
## Dataset Description
Some text here.
### Dataset Summary
Some text here.
### Supported Tasks and Leaderboards
### Languages
Language Text
'''

A       :   Union[str, Any]					= (
    '''The following issues were found for the README at `{path}`:\n-\tNo YAML markers are present in the README.'''
)

A       :   int					= '''\
---
# Dataset Card for My Dataset
## Table of Contents
Some text here.
## Dataset Description
Some text here.
### Dataset Summary
Some text here.
### Supported Tasks and Leaderboards
### Languages
Language Text
'''

A       :   Dict					= '''The following issues were found for the README at `{path}`:\n-\tOnly the start of YAML tags present in the README.'''

A       :   List[Any]					= '''\
---
language:
- zh
- en
---

# Dataset Card for My Dataset
## Table of Contents
Some text here.
## Dataset Description
Some text here.
### Dataset Summary
### Supported Tasks and Leaderboards
### Languages
Language Text
'''
A       :   str					= '''The following issues were found for the README at `{path}`:\n-\tExpected some content in section `Dataset Summary` but it is empty.\n-\tExpected some text in section `Dataset Summary` but it is empty (text in subsections are ignored).'''


A       :   Optional[int]					= '''\
---
language:
- zh
- en
---

# Dataset Card for My Dataset
'''
A       :   Optional[int]					= '''The following issues were found for the README at `{path}`:\n-\tExpected some content in section `Dataset Card for My Dataset` but it is empty.\n-\tSection `Dataset Card for My Dataset` expected the following subsections: `Table of Contents`, `Dataset Description`. Found \'None\'.'''

A       :   Optional[int]					= '''\
---
language:
- zh
- en
---

# Dataset Card for My Dataset
## Table of Contents
Some text here.
## Dataset Description
Some text here.
### Dataset Summary
Some text here.
### Languages
Language Text
'''

A       :   List[str]					= '''The following issues were found for the README at `{path}`:\n-\tSection `Dataset Description` is missing subsection: `Supported Tasks and Leaderboards`.'''


A       :   Optional[int]					= '''\
---
language:
- zh
- en
---

# Dataset Card for My Dataset
## Table of Contents
Some text here.
## Dataset Description
Some text here.
### Dataset Summary
Some text here.
### Supported Tasks and Leaderboards
### Languages
'''

A       :   Optional[Any]					= '''The following issues were found for the README at `{path}`:\n-\tExpected some content in section `Languages` but it is empty.'''

A       :   List[Any]					= '''\
---
language:
- zh
- en
---

## Table of Contents
Some text here.
## Dataset Description
Some text here.
### Dataset Summary
Some text here.
### Supported Tasks and Leaderboards
### Languages
Language Text
'''
A       :   Optional[Any]					= '''The following issues were found for the README at `{path}`:\n-\tThe README has no first-level headings. One heading is expected. Skipping further validation for this README.'''

A       :   int					= '''\
---
language:
- zh
- en
---

# Dataset Card for My Dataset
## Table of Contents
Some text here.
## Dataset Description
Some text here.
### Dataset Summary
Some text here.
### Supported Tasks and Leaderboards
### Languages
Language Text
# Dataset Card My Dataset
'''

A       :   Dict					= '''The following issues were found for the README at `{path}`:\n-\tThe README has several first-level headings: `Dataset Card for My Dataset`, `Dataset Card My Dataset`. Only one heading is expected. Skipping further validation for this README.'''

A       :   str					= '''\
---
language:
- zh
- en
---

# Dataset Card My Dataset
## Table of Contents
Some text here.
## Dataset Description
Some text here.
### Dataset Summary
Some text here.
### Supported Tasks and Leaderboards
### Languages
Language Text
'''

A       :   int					= '''The following issues were found for the README at `{path}`:\n-\tNo first-level heading starting with `Dataset Card for` found in README. Skipping further validation for this README.'''

A       :   str					= ''''''

A       :   Optional[Any]					= '''The following issues were found for the README at `{path}`:\n-\tThe README has no first-level headings. One heading is expected. Skipping further validation for this README.\n-\tNo YAML markers are present in the README.'''

A       :   int					= '''\
---
language:
- zh
- en
---

# Dataset Card for My Dataset
# Dataset Card for My Dataset
## Table of Contents
Some text here.
## Dataset Description
Some text here.
### Dataset Summary
Some text here.
### Supported Tasks and Leaderboards
### Languages
Language Text
'''

A       :   List[Any]					= '''The following issues were found while parsing the README at `{path}`:\n-\tMultiple sections with the same heading `Dataset Card for My Dataset` have been found. Please keep only one of these sections.'''







@pytest.mark.parametrize(
    """readme_md, expected_dict"""       ,	[
        (README_CORRECT, CORRECT_DICT),
        (README_CORRECT_FOUR_LEVEL, CORRECT_DICT_FOUR_LEVEL),
    ]       ,	)
def   __lowerCamelCase   (				__a  :Union[str, Any]       ,	__a  :List[Any]       )						->							List[Any]:






		"""simple docstring"""

		assert ReadMe.from_string(__a       ,	__a       ).to_dict() == expected_dict







@pytest.mark.parametrize(
    """readme_md, expected_error"""       ,	[
        (README_NO_YAML, EXPECTED_ERROR_README_NO_YAML),
        (README_EMPTY_YAML, EXPECTED_ERROR_README_EMPTY_YAML),
        (README_INCORRECT_YAML, EXPECTED_ERROR_README_INCORRECT_YAML),
        (README_EMPTY, EXPECTED_ERROR_README_EMPTY),
        (README_NONE_SUBSECTION, EXPECTED_ERROR_README_NONE_SUBSECTION),
        (README_MISSING_FIRST_LEVEL, EXPECTED_ERROR_README_MISSING_FIRST_LEVEL),
        (README_MISSING_SUBSECTION, EXPECTED_ERROR_README_MISSING_SUBSECTION),
        (README_MISSING_TEXT, EXPECTED_ERROR_README_MISSING_TEXT),
        (README_WRONG_FIRST_LEVEL, EXPECTED_ERROR_README_WRONG_FIRST_LEVEL),
        (README_MULTIPLE_WRONG_FIRST_LEVEL, EXPECTED_ERROR_README_MULTIPLE_WRONG_FIRST_LEVEL),
        (README_MISSING_CONTENT, EXPECTED_ERROR_README_MISSING_CONTENT),
    ]       ,	)
def   __lowerCamelCase   (				__a  :Any       ,	__a  :Union[str, Any]       )						->							Dict:






		"""simple docstring"""

		with pytest.raises(__a       ,	match=re.escape(expected_error.format(path="""root"""       )       )       ):
				A__     =  ReadMe.from_string(__a       ,	__a       )
				readme.validate()







@pytest.mark.parametrize(
    """readme_md, expected_error"""       ,	[
        (README_MULTIPLE_SAME_HEADING_1, EXPECTED_ERROR_README_MULTIPLE_SAME_HEADING_1),
    ]       ,	)
def   __lowerCamelCase   (				__a  :List[str]       ,	__a  :Tuple       )						->							Dict:






		"""simple docstring"""

		with pytest.raises(__a       ,	match=re.escape(expected_error.format(path="""root"""       )       )       ):
				ReadMe.from_string(__a       ,	__a       )







@pytest.mark.parametrize(
    """readme_md,"""       ,	[
        (README_MULTIPLE_SAME_HEADING_1),
    ]       ,	)
def   __lowerCamelCase   (				__a  :Any       )						->							List[str]:






		"""simple docstring"""

		ReadMe.from_string(__a       ,	__a       ,	suppress_parsing_errors=__a       )







@pytest.mark.parametrize(
    """readme_md, expected_dict"""       ,	[
        (README_CORRECT, CORRECT_DICT),
        (README_CORRECT_FOUR_LEVEL, CORRECT_DICT_FOUR_LEVEL),
    ]       ,	)
def   __lowerCamelCase   (				__a  :List[Any]       ,	__a  :Optional[int]       )						->							Optional[int]:






		"""simple docstring"""

		with tempfile.TemporaryDirectory() as tmp_dir:
				A__     =  Path(__a       ) / """README.md"""
				with open(__a       ,	"""w+"""       ) as readme_file:
						readme_file.write(__a       )
				A__     =  ReadMe.from_readme(__a       ,	__a       ).to_dict()
				assert out["name"] == path
				assert out["text"] == ""
				assert out["is_empty_text"]
				assert out["subsections"] == expected_dict["subsections"]







@pytest.mark.parametrize(
    """readme_md, expected_error"""       ,	[
        (README_NO_YAML, EXPECTED_ERROR_README_NO_YAML),
        (README_EMPTY_YAML, EXPECTED_ERROR_README_EMPTY_YAML),
        (README_INCORRECT_YAML, EXPECTED_ERROR_README_INCORRECT_YAML),
        (README_EMPTY, EXPECTED_ERROR_README_EMPTY),
        (README_NONE_SUBSECTION, EXPECTED_ERROR_README_NONE_SUBSECTION),
        (README_MISSING_FIRST_LEVEL, EXPECTED_ERROR_README_MISSING_FIRST_LEVEL),
        (README_MISSING_SUBSECTION, EXPECTED_ERROR_README_MISSING_SUBSECTION),
        (README_MISSING_TEXT, EXPECTED_ERROR_README_MISSING_TEXT),
        (README_WRONG_FIRST_LEVEL, EXPECTED_ERROR_README_WRONG_FIRST_LEVEL),
        (README_MULTIPLE_WRONG_FIRST_LEVEL, EXPECTED_ERROR_README_MULTIPLE_WRONG_FIRST_LEVEL),
        (README_MISSING_CONTENT, EXPECTED_ERROR_README_MISSING_CONTENT),
    ]       ,	)
def   __lowerCamelCase   (				__a  :List[str]       ,	__a  :Union[str, Any]       )						->							List[str]:






		"""simple docstring"""

		with tempfile.TemporaryDirectory() as tmp_dir:
				A__     =  Path(__a       ) / """README.md"""
				with open(__a       ,	"""w+"""       ) as readme_file:
						readme_file.write(__a       )
				A__     =  expected_error.format(path=__a       )
				with pytest.raises(__a       ,	match=re.escape(__a       )       ):
						A__     =  ReadMe.from_readme(__a       ,	__a       )
						readme.validate()







@pytest.mark.parametrize(
    """readme_md, expected_error"""       ,	[
        (README_MULTIPLE_SAME_HEADING_1, EXPECTED_ERROR_README_MULTIPLE_SAME_HEADING_1),
    ]       ,	)
def   __lowerCamelCase   (				__a  :List[Any]       ,	__a  :Any       )						->							int:






		"""simple docstring"""

		with tempfile.TemporaryDirectory() as tmp_dir:
				A__     =  Path(__a       ) / """README.md"""
				with open(__a       ,	"""w+"""       ) as readme_file:
						readme_file.write(__a       )
				A__     =  expected_error.format(path=__a       )
				with pytest.raises(__a       ,	match=re.escape(__a       )       ):
						ReadMe.from_readme(__a       ,	__a       )







@pytest.mark.parametrize(
    """readme_md,"""       ,	[
        (README_MULTIPLE_SAME_HEADING_1),
    ]       ,	)
def   __lowerCamelCase   (				__a  :Union[str, Any]       )						->							Optional[Any]:






		"""simple docstring"""

		with tempfile.TemporaryDirectory() as tmp_dir:
				A__     =  Path(__a       ) / """README.md"""
				with open(__a       ,	"""w+"""       ) as readme_file:
						readme_file.write(__a       )
				ReadMe.from_readme(__a       ,	__a       ,	suppress_parsing_errors=__a       )



