"""simple docstring"""







import copy
import unittest

from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch

	from transformers import (
	    MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
	    MODEL_FOR_QUESTION_ANSWERING_MAPPING,
	    MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
	    MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
	    LayoutLMvaConfig,
	    LayoutLMvaForQuestionAnswering,
	    LayoutLMvaForSequenceClassification,
	    LayoutLMvaForTokenClassification,
	    LayoutLMvaModel,
	)
	from transformers.models.layoutlmva.modeling_layoutlmva import LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
	from PIL import Image

	from transformers import LayoutLMvaImageProcessor

class 	UpperCamelCase    :



				def __init__(self       :   List[str]			,						_A       :   Optional[int]			,						_A       :   Optional[Any]=2			,						_A       :   Union[str, Any]=3			,						_A       :   str=4			,						_A       :   Tuple=2			,						_A       :   Optional[int]=7			,						_A       :   Union[str, Any]=True			,						_A       :   Dict=True			,						_A       :   Any=True			,						_A       :   Any=True			,						_A       :   Optional[Any]=99			,						_A       :   Tuple=36			,						_A       :   Tuple=3			,						_A       :   List[str]=4			,						_A       :   List[str]=37			,						_A       :   Optional[Any]="gelu"			,						_A       :   Any=0.1			,						_A       :   int=0.1			,						_A       :   Any=5_12			,						_A       :   List[Any]=16			,						_A       :   int=2			,						_A       :   Tuple=0.02			,						_A       :   int=6			,						_A       :   Union[str, Any]=6			,						_A       :   str=3			,						_A       :   Union[str, Any]=4			,						_A       :   int=None			,						_A       :   Dict=10_00			,						)					->			Optional[Any]:
					__snake_case    :							List[str]   	=				parent
					__snake_case    :							Dict   	=				batch_size
					__snake_case    :							Dict   	=				num_channels
					__snake_case    :							Any   	=				image_size
					__snake_case    :							int   	=				patch_size
					__snake_case    :							str   	=				text_seq_length
					__snake_case    :							Tuple   	=				is_training
					__snake_case    :							Dict   	=				use_input_mask
					__snake_case    :							str   	=				use_token_type_ids
					__snake_case    :							Optional[int]   	=				use_labels
					__snake_case    :							List[Any]   	=				vocab_size
					__snake_case    :							str   	=				hidden_size
					__snake_case    :							Tuple   	=				num_hidden_layers
					__snake_case    :							List[Any]   	=				num_attention_heads
					__snake_case    :							Any   	=				intermediate_size
					__snake_case    :							Optional[int]   	=				hidden_act
					__snake_case    :							Tuple   	=				hidden_dropout_prob
					__snake_case    :							Dict   	=				attention_probs_dropout_prob
					__snake_case    :							List[str]   	=				max_position_embeddings
					__snake_case    :							List[str]   	=				type_vocab_size
					__snake_case    :							Dict   	=				type_sequence_label_size
					__snake_case    :							Tuple   	=				initializer_range
					__snake_case    :							List[str]   	=				coordinate_size
					__snake_case    :							Union[str, Any]   	=				shape_size
					__snake_case    :							List[Any]   	=				num_labels
					__snake_case    :							Optional[Any]   	=				num_choices
					__snake_case    :							Tuple   	=				scope
					__snake_case    :							Tuple   	=				range_bbox

					# LayoutLMv3's sequence length equals the number of text tokens + number of patches + 1 (we add 1 for the CLS token)
					__snake_case    :							List[Any]   	=				text_seq_length
					__snake_case    :							List[str]   	=				(image_size // patch_size) ** 2 + 1
					__snake_case    :							Optional[Any]   	=				self.text_seq_length + self.image_seq_length



				def       _lowercase  (self       :   List[Any])					->			str:
					__snake_case    :							Tuple   	=				ids_tensor([self.batch_size, self.text_seq_length]			,						self.vocab_size)

					__snake_case    :							str   	=				ids_tensor([self.batch_size, self.text_seq_length, 4]			,						self.range_bbox)
					# Ensure that bbox is legal
					for i in range(bbox.shape[0]):
						for j in range(bbox.shape[1]):
							if bbox[i, j, 3] < bbox[i, j, 1]:
								__snake_case    :							List[str]   	=				bbox[i, j, 3]
								__snake_case    :							Optional[int]   	=				bbox[i, j, 1]
								__snake_case    :							Optional[Any]   	=				t
							if bbox[i, j, 2] < bbox[i, j, 0]:
								__snake_case    :							Optional[Any]   	=				bbox[i, j, 2]
								__snake_case    :							int   	=				bbox[i, j, 0]
								__snake_case    :							Tuple   	=				t

					__snake_case    :							Tuple   	=				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

					__snake_case    :							str   	=				None
					if self.use_input_mask:
						__snake_case    :							str   	=				random_attention_mask([self.batch_size, self.text_seq_length])

					__snake_case    :							str   	=				None
					if self.use_token_type_ids:
						__snake_case    :							Union[str, Any]   	=				ids_tensor([self.batch_size, self.text_seq_length]			,						self.type_vocab_size)

					__snake_case    :							str   	=				None
					__snake_case    :							int   	=				None
					if self.use_labels:
						__snake_case    :							Tuple   	=				ids_tensor([self.batch_size]			,						self.type_sequence_label_size)
						__snake_case    :							Optional[int]   	=				ids_tensor([self.batch_size, self.text_seq_length]			,						self.num_labels)

					__snake_case    :							int   	=				LayoutLMvaConfig(
					    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			,						initializer_range=self.initializer_range			,						coordinate_size=self.coordinate_size			,						shape_size=self.shape_size			,						input_size=self.image_size			,						patch_size=self.patch_size			,						)

					return config, input_ids, bbox, pixel_values, token_type_ids, input_mask, sequence_labels, token_labels



				def       _lowercase  (self       :   int			,						_A       :   Optional[Any]			,						_A       :   int			,						_A       :   Optional[Any]			,						_A       :   str			,						_A       :   str			,						_A       :   List[Any]			,						_A       :   List[str]			,						_A       :   List[Any])					->			int:
					__snake_case    :							Any   	=				LayoutLMvaModel(config=_A)
					model.to(_A)
					model.eval()

					# text + image
					__snake_case    :							Any   	=				model(_A			,						pixel_values=_A)
					__snake_case    :							Dict   	=				model(
					    _A			,						bbox=_A			,						pixel_values=_A			,						attention_mask=_A			,						token_type_ids=_A)
					__snake_case    :							Any   	=				model(_A			,						bbox=_A			,						pixel_values=_A			,						token_type_ids=_A)
					__snake_case    :							List[Any]   	=				model(_A			,						bbox=_A			,						pixel_values=_A)

					self.parent.assertEqual(result.last_hidden_state.shape			,						(self.batch_size, self.seq_length, self.hidden_size))

					# text only
					__snake_case    :							Tuple   	=				model(_A)
					self.parent.assertEqual(
					    result.last_hidden_state.shape			,						(self.batch_size, self.text_seq_length, self.hidden_size))

					# image only
					__snake_case    :							int   	=				model(pixel_values=_A)
					self.parent.assertEqual(
					    result.last_hidden_state.shape			,						(self.batch_size, self.image_seq_length, self.hidden_size))



				def       _lowercase  (self       :   Tuple			,						_A       :   Any			,						_A       :   Union[str, Any]			,						_A       :   Union[str, Any]			,						_A       :   Any			,						_A       :   str			,						_A       :   Union[str, Any]			,						_A       :   Optional[Any]			,						_A       :   str)					->			List[str]:
					__snake_case    :							Tuple   	=				self.num_labels
					__snake_case    :							str   	=				LayoutLMvaForSequenceClassification(_A)
					model.to(_A)
					model.eval()
					__snake_case    :							Union[str, Any]   	=				model(
					    _A			,						bbox=_A			,						pixel_values=_A			,						attention_mask=_A			,						token_type_ids=_A			,						labels=_A			,						)
					self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.num_labels))



				def       _lowercase  (self       :   List[str]			,						_A       :   Optional[Any]			,						_A       :   Optional[int]			,						_A       :   List[str]			,						_A       :   List[str]			,						_A       :   str			,						_A       :   str			,						_A       :   Tuple			,						_A       :   Dict)					->			Union[str, Any]:
					__snake_case    :							List[str]   	=				self.num_labels
					__snake_case    :							int   	=				LayoutLMvaForTokenClassification(config=_A)
					model.to(_A)
					model.eval()
					__snake_case    :							Tuple   	=				model(
					    _A			,						bbox=_A			,						pixel_values=_A			,						attention_mask=_A			,						token_type_ids=_A			,						labels=_A			,						)
					self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.text_seq_length, self.num_labels))



				def       _lowercase  (self       :   List[Any]			,						_A       :   Optional[Any]			,						_A       :   List[str]			,						_A       :   int			,						_A       :   List[Any]			,						_A       :   List[Any]			,						_A       :   str			,						_A       :   str			,						_A       :   Tuple)					->			int:
					__snake_case    :							List[str]   	=				LayoutLMvaForQuestionAnswering(config=_A)
					model.to(_A)
					model.eval()
					__snake_case    :							List[Any]   	=				model(
					    _A			,						bbox=_A			,						pixel_values=_A			,						attention_mask=_A			,						token_type_ids=_A			,						start_positions=_A			,						end_positions=_A			,						)
					self.parent.assertEqual(result.start_logits.shape			,						(self.batch_size, self.seq_length))
					self.parent.assertEqual(result.end_logits.shape			,						(self.batch_size, self.seq_length))






				def       _lowercase  (self       :   int)					->			Optional[Any]:
					__snake_case    :							Any   	=				self.prepare_config_and_inputs()
					(
					    (
					    __snake_case
					)	,       (
					    __snake_case
					)	,       (
					    __snake_case
					)	,       (
					    __snake_case
					)	,       (
					    __snake_case
					)	,       (
					    __snake_case
					)	,       (
					    __snake_case
					)	,       (
					    __snake_case
					)	,       
					)    :							Optional[Any]   	=				config_and_inputs
					__snake_case    :							Tuple   	=				{
					    'input_ids': input_ids,
					    'bbox': bbox,
					    'pixel_values': pixel_values,
					    'token_type_ids': token_type_ids,
					    'attention_mask': input_mask,
					}
					return config, inputs_dict







@require_torch
class 	UpperCamelCase    (					lowercase   ,			lowercase   ,			unittest.TestCase		):
				UpperCAmelCase       :   Tuple					=	False
				UpperCAmelCase       :   Optional[Any]					=	False
				UpperCAmelCase       :   Union[str, Any]					=	False

				UpperCAmelCase       :   Tuple					=	(
				    (
				        LayoutLMvaModel,
				        LayoutLMvaForSequenceClassification,
				        LayoutLMvaForTokenClassification,
				        LayoutLMvaForQuestionAnswering,
				    )
				    if is_torch_available()
				    else ()
				)
				UpperCAmelCase       :   str					=	(
				    {"""document-question-answering""": LayoutLMvaForQuestionAnswering, """feature-extraction""": LayoutLMvaModel}
				    if is_torch_available()
				    else {}
				)



				def       _lowercase  (self       :   List[str]			,						_A       :   Union[str, Any]			,						_A       :   Optional[Any]			,						_A       :   Union[str, Any]			,						_A       :   Union[str, Any]			,						_A       :   List[str])					->			str:
					# `DocumentQuestionAnsweringPipeline` is expected to work with this model, but it combines the text and visual
					# embedding along the sequence dimension (dim 1), which causes an error during post-processing as `p_mask` has
					# the sequence dimension of the text embedding only.
					# (see the line `embedding_output = torch.cat([embedding_output, visual_embeddings], dim=1)`)
					return True



				def       _lowercase  (self       :   Any)					->			Union[str, Any]:
					__snake_case    :							Optional[int]   	=				LayoutLMvaModelTester(self)
					__snake_case    :							Union[str, Any]   	=				ConfigTester(self			,						config_class=_A			,						hidden_size=37)



				def       _lowercase  (self       :   Any			,						_A       :   Union[str, Any]			,						_A       :   int			,						_A       :   str=False)					->			Tuple:
					__snake_case    :							Optional[Any]   	=				copy.deepcopy(_A)
					if model_class in get_values(_A):
						__snake_case    :							List[Any]   	=				{
						    k: v.unsqueeze(1).expand(-1			,						self.model_tester.num_choices			,						-1).contiguous()
						    if isinstance(_A			,						torch.Tensor) and v.ndim > 1
						    else v
						    for k, v in inputs_dict.items()
						}
					if return_labels:
						if model_class in get_values(_A):
							__snake_case    :							str   	=				torch.ones(self.model_tester.batch_size			,						dtype=torch.long			,						device=_A)
						elif model_class in get_values(_A):
							__snake_case    :							List[str]   	=				torch.zeros(
							    self.model_tester.batch_size			,						dtype=torch.long			,						device=_A)
							__snake_case    :							int   	=				torch.zeros(
							    self.model_tester.batch_size			,						dtype=torch.long			,						device=_A)
						elif model_class in [
						    *get_values(_A),
						]:
							__snake_case    :							List[Any]   	=				torch.zeros(
							    self.model_tester.batch_size			,						dtype=torch.long			,						device=_A)
						elif model_class in [
						    *get_values(_A),
						]:
							__snake_case    :							Optional[Any]   	=				torch.zeros(
							    (self.model_tester.batch_size, self.model_tester.text_seq_length)			,						dtype=torch.long			,						device=_A			,						)

					return inputs_dict



				def       _lowercase  (self       :   str)					->			Any:
					self.config_tester.run_common_tests()



				def       _lowercase  (self       :   int)					->			List[Any]:
					__snake_case    :							str   	=				self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*_A)



				def       _lowercase  (self       :   Any)					->			Optional[int]:
					__snake_case    :							Any   	=				self.model_tester.prepare_config_and_inputs()
					for type in ["absolute", "relative_key", "relative_key_query"]:
						__snake_case    :							Any   	=				type
						self.model_tester.create_and_check_model(*_A)



				def       _lowercase  (self       :   Union[str, Any])					->			int:
					__snake_case    :							Optional[int]   	=				self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*_A)



				def       _lowercase  (self       :   Dict)					->			List[Any]:
					__snake_case    :							List[Any]   	=				self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*_A)



				def       _lowercase  (self       :   List[Any])					->			Optional[int]:
					__snake_case    :							int   	=				self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*_A)






				@slow
				def       _lowercase  (self       :   Dict)					->			List[str]:
					for model_name in LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						__snake_case    :							List[Any]   	=				LayoutLMvaModel.from_pretrained(_A)
						self.assertIsNotNone(_A)







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

	'''simple docstring'''





	__snake_case    :							List[Any]   	=				Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
	return image

@require_torch
class 	UpperCamelCase    (					unittest.TestCase		):



				@cached_property
				def       _lowercase  (self       :   Any)					->			Optional[Any]:
					return LayoutLMvaImageProcessor(apply_ocr=_A) if is_vision_available() else None






				@slow
				def       _lowercase  (self       :   int)					->			Optional[Any]:
					__snake_case    :							List[str]   	=				LayoutLMvaModel.from_pretrained('microsoft/layoutlmv3-base').to(_A)

					__snake_case    :							List[Any]   	=				self.default_image_processor
					__snake_case    :							Optional[Any]   	=				prepare_img()
					__snake_case    :							Any   	=				image_processor(images=_A			,						return_tensors='pt').pixel_values.to(_A)

					__snake_case    :							List[str]   	=				torch.tensor([[1, 2]])
					__snake_case    :							List[str]   	=				torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]]).unsqueeze(0)

					# forward pass
					__snake_case    :							List[Any]   	=				model(
					    input_ids=input_ids.to(_A)			,						bbox=bbox.to(_A)			,						pixel_values=pixel_values.to(_A)			,						)

					# verify the logits
					__snake_case    :							List[str]   	=				torch.Size((1, 1_99, 7_68))
					self.assertEqual(outputs.last_hidden_state.shape			,						_A)

					__snake_case    :							Optional[Any]   	=				torch.tensor(
					    [[-0.0_529, 0.3_618, 0.1_632], [-0.1_587, -0.1_667, -0.0_400], [-0.1_557, -0.1_671, -0.0_505]]).to(_A)

					self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3]			,						_A			,						atol=1E-4))






"""simple docstring"""







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  :  List[str]=				yaml.safe_load(
    "\\nname: \"\"\nallow_empty: false\nallow_empty_text: true\nsubsections:\n  - name: \"Dataset Card for X\" # First-level markdown heading\n    allow_empty: false\n    allow_empty_text: true\n    subsections:\n      - name: \"Table of Contents\"\n        allow_empty: false\n        allow_empty_text: false\n        subsections: null\n      - name: \"Dataset Description\"\n        allow_empty: false\n        allow_empty_text: false\n        subsections:\n          - name: \"Dataset Summary\"\n            allow_empty: false\n            allow_empty_text: false\n            subsections: null\n          - name: \"Supported Tasks and Leaderboards\"\n            allow_empty: true\n            allow_empty_text: true\n            subsections: null\n          - name: Languages\n            allow_empty: false\n            allow_empty_text: true\n            subsections: null\n"
)


_a  :  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": "Supported Tasks and Leaderboards",
                            "text": "",
                            "is_empty_text": True,
                            "subsections": [],
                        },
                        {"name": "Languages", "text": "Language Text", "is_empty_text": False, "subsections": []},
                    ],
                },
            ],
        }
    ],
}


_a  :  str=				"\\n---\nlanguage:\n- zh\n- en\n---\n\n# Dataset Card for My Dataset\n## Table of Contents\nSome text here.\n## Dataset Description\nSome text here.\n### Dataset Summary\nSome text here.\n### Supported Tasks and Leaderboards\n### Languages\nLanguage Text\n"


_a  :  Tuple=				"\\n---\nlanguage:\n- zh\n- en\n---\n\n# Dataset Card for My Dataset\n## Table of Contents\nSome text here.\n## Dataset Description\nSome text here.\n### Dataset Summary\nSome text here.\n#### Extra Ignored Subsection\n### Supported Tasks and Leaderboards\n### Languages\nLanguage Text\n"

_a  :  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": []},
                    ],
                },
            ],
        }
    ],
}

_a  :  str=				"\\n---\n---\n# Dataset Card for My Dataset\n## Table of Contents\nSome text here.\n## Dataset Description\nSome text here.\n### Dataset Summary\nSome text here.\n### Supported Tasks and Leaderboards\n### Languages\nLanguage Text\n"

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

_a  :  Optional[int]=				"\\n# Dataset Card for My Dataset\n## Table of Contents\nSome text here.\n## Dataset Description\nSome text here.\n### Dataset Summary\nSome text here.\n### Supported Tasks and Leaderboards\n### Languages\nLanguage Text\n"

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

_a  :  str=				"\\n---\n# Dataset Card for My Dataset\n## Table of Contents\nSome text here.\n## Dataset Description\nSome text here.\n### Dataset Summary\nSome text here.\n### Supported Tasks and Leaderboards\n### Languages\nLanguage Text\n"

_a  :  Optional[int]=				"The following issues were found for the README at `{path}`:\n-\tOnly the start of YAML tags present in the README."

_a  :  int=				"\\n---\nlanguage:\n- zh\n- en\n---\n\n# Dataset Card for My Dataset\n## Table of Contents\nSome text here.\n## Dataset Description\nSome text here.\n### Dataset Summary\n### Supported Tasks and Leaderboards\n### Languages\nLanguage Text\n"
_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  :  int=				"\\n---\nlanguage:\n- zh\n- en\n---\n\n# Dataset Card for My Dataset\n"
_a  :  Optional[Any]=				"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  :  Dict=				"\\n---\nlanguage:\n- zh\n- en\n---\n\n# Dataset Card for My Dataset\n## Table of Contents\nSome text here.\n## Dataset Description\nSome text here.\n### Dataset Summary\nSome text here.\n### Languages\nLanguage Text\n"

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


_a  :  int=				"\\n---\nlanguage:\n- zh\n- en\n---\n\n# Dataset Card for My Dataset\n## Table of Contents\nSome text here.\n## Dataset Description\nSome text here.\n### Dataset Summary\nSome text here.\n### Supported Tasks and Leaderboards\n### Languages\n"

_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  :  Optional[int]=				"\\n---\nlanguage:\n- zh\n- en\n---\n\n## Table of Contents\nSome text here.\n## Dataset Description\nSome text here.\n### Dataset Summary\nSome text here.\n### Supported Tasks and Leaderboards\n### Languages\nLanguage Text\n"
_a  :  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  :  Tuple=				"\\n---\nlanguage:\n- zh\n- en\n---\n\n# Dataset Card for My Dataset\n## Table of Contents\nSome text here.\n## Dataset Description\nSome text here.\n### Dataset Summary\nSome text here.\n### Supported Tasks and Leaderboards\n### Languages\nLanguage Text\n# Dataset Card My Dataset\n"

_a  :  List[str]=				"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  :  List[Any]=				"\\n---\nlanguage:\n- zh\n- en\n---\n\n# Dataset Card My Dataset\n## Table of Contents\nSome text here.\n## Dataset Description\nSome text here.\n### Dataset Summary\nSome text here.\n### Supported Tasks and Leaderboards\n### Languages\nLanguage Text\n"

_a  :  Tuple=				"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  :  Optional[Any]=				""

_a  :  Tuple=				"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  :  Union[str, Any]=				"\\n---\nlanguage:\n- zh\n- en\n---\n\n# Dataset Card for My Dataset\n# Dataset Card for My Dataset\n## Table of Contents\nSome text here.\n## Dataset Description\nSome text here.\n### Dataset Summary\nSome text here.\n### Supported Tasks and Leaderboards\n### Languages\nLanguage Text\n"

_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 						__UpperCAmelCase       (					UpperCAmelCase_					:       Tuple    ,							UpperCAmelCase_					:       Tuple						)							->    Tuple:

	'''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 						__UpperCAmelCase       (					UpperCAmelCase_					:       List[str]    ,							UpperCAmelCase_					:       Tuple						)							->    Union[str, Any]:

	'''simple docstring'''





	with pytest.raises(UpperCAmelCase_    ,							match=re.escape(expected_error.format(path='root'						)						)						):
		__snake_case    :							Tuple   	=				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 						__UpperCAmelCase       (					UpperCAmelCase_					:       List[str]    ,							UpperCAmelCase_					:       int						)							->    Optional[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 						__UpperCAmelCase       (					UpperCAmelCase_					:       Optional[int]						)							->    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 						__UpperCAmelCase       (					UpperCAmelCase_					:       Optional[int]    ,							UpperCAmelCase_					:       Union[str, Any]						)							->    str:

	'''simple docstring'''





	with tempfile.TemporaryDirectory() as tmp_dir:
		__snake_case    :							Union[str, Any]   	=				Path(UpperCAmelCase_						) / 'README.md'
		with open(UpperCAmelCase_    ,							'w+'						) as readme_file:
			readme_file.write(UpperCAmelCase_						)
		__snake_case    :							Optional[Any]   	=				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 						__UpperCAmelCase       (					UpperCAmelCase_					:       Optional[Any]    ,							UpperCAmelCase_					:       Dict						)							->    int:

	'''simple docstring'''





	with tempfile.TemporaryDirectory() as tmp_dir:
		__snake_case    :							Optional[int]   	=				Path(UpperCAmelCase_						) / 'README.md'
		with open(UpperCAmelCase_    ,							'w+'						) as readme_file:
			readme_file.write(UpperCAmelCase_						)
		__snake_case    :							List[Any]   	=				expected_error.format(path=UpperCAmelCase_						)
		with pytest.raises(UpperCAmelCase_    ,							match=re.escape(UpperCAmelCase_						)						):
			__snake_case    :							Any   	=				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 						__UpperCAmelCase       (					UpperCAmelCase_					:       Any    ,							UpperCAmelCase_					:       Union[str, Any]						)							->    Any:

	'''simple docstring'''





	with tempfile.TemporaryDirectory() as tmp_dir:
		__snake_case    :							Tuple   	=				Path(UpperCAmelCase_						) / 'README.md'
		with open(UpperCAmelCase_    ,							'w+'						) as readme_file:
			readme_file.write(UpperCAmelCase_						)
		__snake_case    :							List[str]   	=				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 						__UpperCAmelCase       (					UpperCAmelCase_					:       Dict						)							->    Optional[Any]:

	'''simple docstring'''





	with tempfile.TemporaryDirectory() as tmp_dir:
		__snake_case    :							Optional[int]   	=				Path(UpperCAmelCase_						) / 'README.md'
		with open(UpperCAmelCase_    ,							'w+'						) as readme_file:
			readme_file.write(UpperCAmelCase_						)
		ReadMe.from_readme(UpperCAmelCase_    ,							UpperCAmelCase_    ,							suppress_parsing_errors=UpperCAmelCase_						)





