import json
import os
from functools import lru_cache
from typing import List, Optional, Tuple

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


__lowerCamelCase    :				Optional[int]							     =	logging.get_logger(__name__)


__lowerCamelCase    :				List[Any]							     =	{'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt'''}

__lowerCamelCase    :				List[str]							     =	{
    '''vocab_file''': {
        '''allenai/longformer-base-4096''': '''https://huggingface.co/allenai/longformer-base-4096/resolve/main/vocab.json''',
        '''allenai/longformer-large-4096''': (
            '''https://huggingface.co/allenai/longformer-large-4096/resolve/main/vocab.json'''
        ),
        '''allenai/longformer-large-4096-finetuned-triviaqa''': (
            '''https://huggingface.co/allenai/longformer-large-4096-finetuned-triviaqa/resolve/main/vocab.json'''
        ),
        '''allenai/longformer-base-4096-extra.pos.embd.only''': (
            '''https://huggingface.co/allenai/longformer-base-4096-extra.pos.embd.only/resolve/main/vocab.json'''
        ),
        '''allenai/longformer-large-4096-extra.pos.embd.only''': (
            '''https://huggingface.co/allenai/longformer-large-4096-extra.pos.embd.only/resolve/main/vocab.json'''
        ),
    },
    '''merges_file''': {
        '''allenai/longformer-base-4096''': '''https://huggingface.co/allenai/longformer-base-4096/resolve/main/merges.txt''',
        '''allenai/longformer-large-4096''': (
            '''https://huggingface.co/allenai/longformer-large-4096/resolve/main/merges.txt'''
        ),
        '''allenai/longformer-large-4096-finetuned-triviaqa''': (
            '''https://huggingface.co/allenai/longformer-large-4096-finetuned-triviaqa/resolve/main/merges.txt'''
        ),
        '''allenai/longformer-base-4096-extra.pos.embd.only''': (
            '''https://huggingface.co/allenai/longformer-base-4096-extra.pos.embd.only/resolve/main/merges.txt'''
        ),
        '''allenai/longformer-large-4096-extra.pos.embd.only''': (
            '''https://huggingface.co/allenai/longformer-large-4096-extra.pos.embd.only/resolve/main/merges.txt'''
        ),
    },
}

__lowerCamelCase    :				Tuple							     =	{
    '''allenai/longformer-base-4096''': 4096,
    '''allenai/longformer-large-4096''': 4096,
    '''allenai/longformer-large-4096-finetuned-triviaqa''': 4096,
    '''allenai/longformer-base-4096-extra.pos.embd.only''': 4096,
    '''allenai/longformer-large-4096-extra.pos.embd.only''': 4096,
}



@lru_cache()
# Copied from transformers.models.roberta.tokenization_roberta.bytes_to_unicode
def 			__SCREAMING_SNAKE_CASE						(      )							->      str:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__    							=   (
      list(range(ord("""!"""			)				,  ord("""~"""			) + 1			)			) + list(range(ord("""¡"""			)				,  ord("""¬"""			) + 1			)			) + list(range(ord("""®"""			)				,  ord("""ÿ"""			) + 1			)			)
  )
  SCREAMING_SNAKE_CASE__    							=   bs[:]
  SCREAMING_SNAKE_CASE__    							=   0
  for b in range(2**8			):
    if b not in bs:
      bs.append(__UpperCamelCase			)
      cs.append(2**8 + n			)
      n += 1
  SCREAMING_SNAKE_CASE__    							=   [chr(__UpperCamelCase			) for n in cs]
  return dict(zip(__UpperCamelCase				,  __UpperCamelCase			)			)



def 			__SCREAMING_SNAKE_CASE						(      __UpperCamelCase					: List[str]			)							->      List[Any]:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__    							=   set()
  SCREAMING_SNAKE_CASE__    							=   word[0]
  for char in word[1:]:
    pairs.add((prev_char, char)			)
    SCREAMING_SNAKE_CASE__    							=   char
  return pairs







class __snake_case       (		lowerCamelCase_	):
   lowerCAmelCase_														=							VOCAB_FILES_NAMES
   lowerCAmelCase_														=							PRETRAINED_VOCAB_FILES_MAP
   lowerCAmelCase_														=							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   lowerCAmelCase_														=							["input_ids", "attention_mask"]




   def __init__(					self    :       str ,			_lowercase    :       Optional[Any] ,			_lowercase    :       Optional[int] ,			_lowercase    :       Dict="replace" ,			_lowercase    :       Tuple="<s>" ,			_lowercase    :       List[str]="</s>" ,			_lowercase    :       List[str]="</s>" ,			_lowercase    :       int="<s>" ,			_lowercase    :       Optional[int]="<unk>" ,			_lowercase    :       Optional[Any]="<pad>" ,			_lowercase    :       List[Any]="<mask>" ,			_lowercase    :       Union[str, Any]=False ,			**_lowercase    :       Optional[Any] ,			):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   AddedToken(_lowercase ,			lstrip=_lowercase ,			rstrip=_lowercase   ) if isinstance(_lowercase ,			_lowercase   ) else bos_token
     SCREAMING_SNAKE_CASE__    							=   AddedToken(_lowercase ,			lstrip=_lowercase ,			rstrip=_lowercase   ) if isinstance(_lowercase ,			_lowercase   ) else eos_token
     SCREAMING_SNAKE_CASE__    							=   AddedToken(_lowercase ,			lstrip=_lowercase ,			rstrip=_lowercase   ) if isinstance(_lowercase ,			_lowercase   ) else sep_token
     SCREAMING_SNAKE_CASE__    							=   AddedToken(_lowercase ,			lstrip=_lowercase ,			rstrip=_lowercase   ) if isinstance(_lowercase ,			_lowercase   ) else cls_token
     SCREAMING_SNAKE_CASE__    							=   AddedToken(_lowercase ,			lstrip=_lowercase ,			rstrip=_lowercase   ) if isinstance(_lowercase ,			_lowercase   ) else unk_token
     SCREAMING_SNAKE_CASE__    							=   AddedToken(_lowercase ,			lstrip=_lowercase ,			rstrip=_lowercase   ) if isinstance(_lowercase ,			_lowercase   ) else pad_token

     # Mask token behave like a normal word, i.e. include the space before it
     SCREAMING_SNAKE_CASE__    							=   AddedToken(_lowercase ,			lstrip=_lowercase ,			rstrip=_lowercase   ) if isinstance(_lowercase ,			_lowercase   ) else mask_token

     super().__init__(
         errors=_lowercase ,			bos_token=_lowercase ,			eos_token=_lowercase ,			unk_token=_lowercase ,			sep_token=_lowercase ,			cls_token=_lowercase ,			pad_token=_lowercase ,			mask_token=_lowercase ,			add_prefix_space=_lowercase ,			**_lowercase ,			)

     with open(_lowercase ,			encoding="""utf-8"""   ) as vocab_handle:
       SCREAMING_SNAKE_CASE__    							=   json.load(_lowercase   )
     SCREAMING_SNAKE_CASE__    							=   {v: k for k, v in self.encoder.items()}
     SCREAMING_SNAKE_CASE__    							=   errors  # how to handle errors in decoding
     SCREAMING_SNAKE_CASE__    							=   bytes_to_unicode()
     SCREAMING_SNAKE_CASE__    							=   {v: k for k, v in self.byte_encoder.items()}
     with open(_lowercase ,			encoding="""utf-8"""   ) as merges_handle:
       SCREAMING_SNAKE_CASE__    							=   merges_handle.read().split("""\n"""   )[1:-1]
     SCREAMING_SNAKE_CASE__    							=   [tuple(merge.split()   ) for merge in bpe_merges]
     SCREAMING_SNAKE_CASE__    							=   dict(zip(_lowercase ,			range(len(_lowercase   )   )   )   )
     SCREAMING_SNAKE_CASE__    							=   {}
     SCREAMING_SNAKE_CASE__    							=   add_prefix_space

     # Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
     SCREAMING_SNAKE_CASE__    							=   re.compile(R"""'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+"""   )




   @property
   def 			__a		(					self    :       Tuple   ):



     """simple docstring"""






     return len(self.encoder   )




   def 			__a		(					self    :       Any   ):



     """simple docstring"""






     return dict(self.encoder ,			**self.added_tokens_encoder   )




   def 			__a		(					self    :       Tuple ,			_lowercase    :       List[str]   ):



     """simple docstring"""






     if token in self.cache:
       return self.cache[token]
     SCREAMING_SNAKE_CASE__    							=   tuple(_lowercase   )
     SCREAMING_SNAKE_CASE__    							=   get_pairs(_lowercase   )

     if not pairs:
       return token

     while True:
       SCREAMING_SNAKE_CASE__    							=   min(_lowercase ,			key=lambda _lowercase   : self.bpe_ranks.get(_lowercase ,			float("""inf"""   )   )   )
       if bigram not in self.bpe_ranks:
         break
       SCREAMING_SNAKE_CASE__							,  SCREAMING_SNAKE_CASE__    							=   bigram
       SCREAMING_SNAKE_CASE__    							=   []
       SCREAMING_SNAKE_CASE__    							=   0
       while i < len(_lowercase   ):
         try:
           SCREAMING_SNAKE_CASE__    							=   word.index(_lowercase ,			_lowercase   )
         except ValueError:
           new_word.extend(word[i:]   )
           break
         else:
           new_word.extend(word[i:j]   )
           SCREAMING_SNAKE_CASE__    							=   j

         if word[i] == first and i < len(_lowercase   ) - 1 and word[i + 1] == second:
           new_word.append(first + second   )
           i += 2
         else:
           new_word.append(word[i]   )
           i += 1
       SCREAMING_SNAKE_CASE__    							=   tuple(_lowercase   )
       SCREAMING_SNAKE_CASE__    							=   new_word
       if len(_lowercase   ) == 1:
         break
       else:
         SCREAMING_SNAKE_CASE__    							=   get_pairs(_lowercase   )
     SCREAMING_SNAKE_CASE__    							=   """ """.join(_lowercase   )
     SCREAMING_SNAKE_CASE__    							=   word
     return word




   def 			__a		(					self    :       Any ,			_lowercase    :       Union[str, Any]   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   []
     for token in re.findall(self.pat ,			_lowercase   ):
       SCREAMING_SNAKE_CASE__    							=   """""".join(
           self.byte_encoder[b] for b in token.encode("""utf-8"""   )   )  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
       bpe_tokens.extend(bpe_token for bpe_token in self.bpe(_lowercase   ).split(""" """   )   )
     return bpe_tokens




   def 			__a		(					self    :       List[str] ,			_lowercase    :       List[Any]   ):



     """simple docstring"""






     return self.encoder.get(_lowercase ,			self.encoder.get(self.unk_token   )   )




   def 			__a		(					self    :       Optional[int] ,			_lowercase    :       Optional[int]   ):



     """simple docstring"""






     return self.decoder.get(_lowercase   )




   def 			__a		(					self    :       List[str] ,			_lowercase    :       Union[str, Any]   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   """""".join(_lowercase   )
     SCREAMING_SNAKE_CASE__    							=   bytearray([self.byte_decoder[c] for c in text]   ).decode("""utf-8""" ,			errors=self.errors   )
     return text




   def 			__a		(					self    :       Union[str, Any] ,			_lowercase    :       str ,			_lowercase    :       Optional[str] = None   ):



     """simple docstring"""






     if not os.path.isdir(_lowercase   ):
       logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""   )
       return
     SCREAMING_SNAKE_CASE__    							=   os.path.join(
         _lowercase ,			(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]   )
     SCREAMING_SNAKE_CASE__    							=   os.path.join(
         _lowercase ,			(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""merges_file"""]   )

     with open(_lowercase ,			"""w""" ,			encoding="""utf-8"""   ) as f:
       f.write(json.dumps(self.encoder ,			indent=2 ,			sort_keys=_lowercase ,			ensure_ascii=_lowercase   ) + """\n"""   )

     SCREAMING_SNAKE_CASE__    							=   0
     with open(_lowercase ,			"""w""" ,			encoding="""utf-8"""   ) as writer:
       writer.write("""#version: 0.2\n"""   )
       for bpe_tokens, token_index in sorted(self.bpe_ranks.items() ,			key=lambda _lowercase   : kv[1]   ):
         if index != token_index:
           logger.warning(
               f"""Saving vocabulary to {merge_file}: BPE merge indices are not consecutive."""
               """ Please check that the tokenizer is not corrupted!"""   )
           SCREAMING_SNAKE_CASE__    							=   token_index
         writer.write(""" """.join(_lowercase   ) + """\n"""   )
         index += 1

     return vocab_file, merge_file




   def 			__a		(					self    :       List[Any] ,			_lowercase    :       List[int] ,			_lowercase    :       Optional[List[int]] = None   ):



     """simple docstring"""






     if token_ids_a is None:
       return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
     SCREAMING_SNAKE_CASE__    							=   [self.cls_token_id]
     SCREAMING_SNAKE_CASE__    							=   [self.sep_token_id]
     return cls + token_ids_a + sep + sep + token_ids_a + sep




   def 			__a		(					self    :       Any ,			_lowercase    :       List[int] ,			_lowercase    :       Optional[List[int]] = None ,			_lowercase    :       bool = False   ):



     """simple docstring"""






     if already_has_special_tokens:
       return super().get_special_tokens_mask(
           token_ids_a=_lowercase ,			token_ids_a=_lowercase ,			already_has_special_tokens=_lowercase   )

     if token_ids_a is None:
       return [1] + ([0] * len(_lowercase   )) + [1]
     return [1] + ([0] * len(_lowercase   )) + [1, 1] + ([0] * len(_lowercase   )) + [1]




   def 			__a		(					self    :       Tuple ,			_lowercase    :       List[int] ,			_lowercase    :       Optional[List[int]] = None   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   [self.sep_token_id]
     SCREAMING_SNAKE_CASE__    							=   [self.cls_token_id]

     if token_ids_a is None:
       return len(cls + token_ids_a + sep   ) * [0]
     return len(cls + token_ids_a + sep + sep + token_ids_a + sep   ) * [0]




   def 			__a		(					self    :       Optional[Any] ,			_lowercase    :       str ,			_lowercase    :       Tuple=False ,			**_lowercase    :       List[Any]   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   kwargs.pop("""add_prefix_space""" ,			self.add_prefix_space   )
     if (is_split_into_words or add_prefix_space) and (len(_lowercase   ) > 0 and not text[0].isspace()):
       SCREAMING_SNAKE_CASE__    							=   """ """ + text
     return (text, kwargs)

import re
import tempfile
from pathlib import Path

import pytest
import yaml

from datasets.utils.readme import ReadMe


# @pytest.fixture
# def example_yaml_structure():

__lowerCamelCase    :				str							     =	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
'''
)


__lowerCamelCase    :				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''': []},
                    ],
                },
            ],
        }
    ],
}


__lowerCamelCase    :				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
'''


__lowerCamelCase    :				List[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.
#### Extra Ignored Subsection
### Supported Tasks and Leaderboards
### Languages
Language Text
'''

__lowerCamelCase    :				Dict							     =	{
    '''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''': []},
                    ],
                },
            ],
        }
    ],
}

__lowerCamelCase    :				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
'''

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

__lowerCamelCase    :				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
'''

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

__lowerCamelCase    :				List[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
'''

__lowerCamelCase    :				List[Any]							     =	'''The following issues were found for the README at `{path}`:\n-\tOnly the start of YAML tags present in the README.'''

__lowerCamelCase    :				str							     =	'''\
---
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
'''
__lowerCamelCase    :				Any							     =	'''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).'''


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

# Dataset Card for My Dataset
'''
__lowerCamelCase    :				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\'.'''

__lowerCamelCase    :				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
'''

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


__lowerCamelCase    :				Optional[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
'''

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

__lowerCamelCase    :				List[str]							     =	'''\
---
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
'''
__lowerCamelCase    :				List[str]							     =	'''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.'''

__lowerCamelCase    :				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
'''

__lowerCamelCase    :				int							     =	'''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.'''

__lowerCamelCase    :				List[Any]							     =	'''\
---
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
'''

__lowerCamelCase    :				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.'''

__lowerCamelCase    :				Optional[Any]							     =	''''''

__lowerCamelCase    :				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.'''

__lowerCamelCase    :				str							     =	'''\
---
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
'''

__lowerCamelCase    :				Dict							     =	'''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 			__SCREAMING_SNAKE_CASE						(      __UpperCamelCase					: Union[str, Any]				,  __UpperCamelCase					: Union[str, Any]			)							->      Dict:







  """simple docstring"""





  assert ReadMe.from_string(__UpperCamelCase				,  __UpperCamelCase			).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 			__SCREAMING_SNAKE_CASE						(      __UpperCamelCase					: Optional[Any]				,  __UpperCamelCase					: Dict			)							->      Union[str, Any]:







  """simple docstring"""





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



@pytest.mark.parametrize(
    """readme_md, expected_error"""				,  [
        (README_MULTIPLE_SAME_HEADING_1, EXPECTED_ERROR_README_MULTIPLE_SAME_HEADING_1),
    ]				,  )
def 			__SCREAMING_SNAKE_CASE						(      __UpperCamelCase					: Optional[int]				,  __UpperCamelCase					: Optional[Any]			)							->      Any:







  """simple docstring"""





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



@pytest.mark.parametrize(
    """readme_md,"""				,  [
        (README_MULTIPLE_SAME_HEADING_1),
    ]				,  )
def 			__SCREAMING_SNAKE_CASE						(      __UpperCamelCase					: Optional[int]			)							->      List[Any]:







  """simple docstring"""





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



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







  """simple docstring"""





  with tempfile.TemporaryDirectory() as tmp_dir:
    SCREAMING_SNAKE_CASE__    							=   Path(__UpperCamelCase			) / """README.md"""
    with open(__UpperCamelCase				,  """w+"""			) as readme_file:
      readme_file.write(__UpperCamelCase			)
    SCREAMING_SNAKE_CASE__    							=   ReadMe.from_readme(__UpperCamelCase				,  __UpperCamelCase			).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 			__SCREAMING_SNAKE_CASE						(      __UpperCamelCase					: List[str]				,  __UpperCamelCase					: Any			)							->      Optional[Any]:







  """simple docstring"""





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



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







  """simple docstring"""





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






@pytest.mark.parametrize(
    """readme_md,"""				,  [
        (README_MULTIPLE_SAME_HEADING_1),
    ]				,  )
def 			__SCREAMING_SNAKE_CASE						(      __UpperCamelCase					: Optional[Any]			)							->      List[Any]:







  """simple docstring"""





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