




"""simple docstring"""







import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import VideoMAEConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, 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
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch
	from torch import nn

	from transformers import (
	    MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING,
	    VideoMAEForPreTraining,
	    VideoMAEForVideoClassification,
	    VideoMAEModel,
	)
	from transformers.models.videomae.modeling_videomae import VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
	from transformers import VideoMAEImageProcessor

class 	UpperCamelCase    :



				def __init__(self       :   Any			,						_A       :   str			,						_A       :   Any=13			,						_A       :   Tuple=10			,						_A       :   Any=3			,						_A       :   Optional[int]=2			,						_A       :   Union[str, Any]=2			,						_A       :   List[Any]=2			,						_A       :   Tuple=True			,						_A       :   List[str]=True			,						_A       :   Any=32			,						_A       :   Optional[int]=5			,						_A       :   List[str]=4			,						_A       :   List[str]=37			,						_A       :   List[Any]="gelu"			,						_A       :   Optional[Any]=0.1			,						_A       :   int=0.1			,						_A       :   List[Any]=10			,						_A       :   Union[str, Any]=0.02			,						_A       :   Optional[int]=0.9			,						_A       :   Optional[Any]=None			,						)					->			Any:
					__snake_case    :							List[Any]   	=				parent
					__snake_case    :							List[str]   	=				batch_size
					__snake_case    :							Optional[int]   	=				image_size
					__snake_case    :							int   	=				num_channels
					__snake_case    :							Union[str, Any]   	=				patch_size
					__snake_case    :							int   	=				tubelet_size
					__snake_case    :							List[Any]   	=				num_frames
					__snake_case    :							str   	=				is_training
					__snake_case    :							int   	=				use_labels
					__snake_case    :							str   	=				hidden_size
					__snake_case    :							List[str]   	=				num_hidden_layers
					__snake_case    :							Optional[int]   	=				num_attention_heads
					__snake_case    :							Union[str, Any]   	=				intermediate_size
					__snake_case    :							Optional[Any]   	=				hidden_act
					__snake_case    :							Dict   	=				hidden_dropout_prob
					__snake_case    :							Any   	=				attention_probs_dropout_prob
					__snake_case    :							Optional[Any]   	=				type_sequence_label_size
					__snake_case    :							Union[str, Any]   	=				initializer_range
					__snake_case    :							Tuple   	=				mask_ratio
					__snake_case    :							Any   	=				scope

					# in VideoMAE, the number of tokens equals num_frames/tubelet_size * num_patches per frame
					__snake_case    :							int   	=				(image_size // patch_size) ** 2
					__snake_case    :							Optional[Any]   	=				(num_frames // tubelet_size) * self.num_patches_per_frame

					# use this variable to define bool_masked_pos
					__snake_case    :							Any   	=				int(mask_ratio * self.seq_length)



				def       _lowercase  (self       :   int)					->			List[str]:
					__snake_case    :							Tuple   	=				floats_tensor(
					    [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size])

					__snake_case    :							List[str]   	=				None
					if self.use_labels:
						__snake_case    :							Union[str, Any]   	=				ids_tensor([self.batch_size]			,						self.type_sequence_label_size)

					__snake_case    :							Tuple   	=				self.get_config()

					return config, pixel_values, labels



				def       _lowercase  (self       :   Any)					->			str:
					return VideoMAEConfig(
					    image_size=self.image_size			,						patch_size=self.patch_size			,						num_channels=self.num_channels			,						num_frames=self.num_frames			,						tubelet_size=self.tubelet_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			,						is_decoder=__lowerCamelCase			,						initializer_range=self.initializer_range			,						)



				def       _lowercase  (self       :   List[str]			,						_A       :   Dict			,						_A       :   Optional[int]			,						_A       :   Optional[Any])					->			List[str]:
					__snake_case    :							Tuple   	=				VideoMAEModel(config=__lowerCamelCase)
					model.to(__lowerCamelCase)
					model.eval()
					__snake_case    :							Any   	=				model(__lowerCamelCase)
					self.parent.assertEqual(result.last_hidden_state.shape			,						(self.batch_size, self.seq_length, self.hidden_size))



				def       _lowercase  (self       :   Optional[Any]			,						_A       :   str			,						_A       :   Any			,						_A       :   Tuple)					->			List[str]:
					__snake_case    :							int   	=				VideoMAEForPreTraining(__lowerCamelCase)
					model.to(__lowerCamelCase)
					model.eval()
					# important: each video needs to have the same number of masked patches
					# hence we define a single mask, which we then repeat for each example in the batch
					__snake_case    :							Optional[Any]   	=				torch.ones((self.num_masks,))
					__snake_case    :							Optional[int]   	=				torch.cat([mask, torch.zeros(self.seq_length - mask.size(0))])
					__snake_case    :							int   	=				mask.expand(self.batch_size			,						-1).bool()

					__snake_case    :							Any   	=				model(__lowerCamelCase			,						__lowerCamelCase)
					# model only returns predictions for masked patches
					__snake_case    :							str   	=				mask.sum().item()
					__snake_case    :							Tuple   	=				3 * self.tubelet_size * self.patch_size**2
					self.parent.assertEqual(result.logits.shape			,						(self.batch_size, num_masked_patches, decoder_num_labels))






				def       _lowercase  (self       :   Optional[int])					->			List[Any]:
					__snake_case    :							List[Any]   	=				self.prepare_config_and_inputs()
					__snake_case    :							Any   	=				config_and_inputs
					__snake_case    :							Dict   	=				{'''pixel_values''': pixel_values}
					return config, inputs_dict







@require_torch
class 	UpperCamelCase    (					lowerCamelCase__   ,			lowerCamelCase__   ,			unittest.TestCase		):
				UpperCAmelCase       :   Dict					=	(
				    (VideoMAEModel, VideoMAEForPreTraining, VideoMAEForVideoClassification) if is_torch_available() else ()
				)
				UpperCAmelCase       :   List[Any]					=	(
				    {"""feature-extraction""": VideoMAEModel, """video-classification""": VideoMAEForVideoClassification}
				    if is_torch_available()
				    else {}
				)

				UpperCAmelCase       :   int					=	False
				UpperCAmelCase       :   Union[str, Any]					=	False
				UpperCAmelCase       :   Any					=	False
				UpperCAmelCase       :   Union[str, Any]					=	False



				def       _lowercase  (self       :   Dict)					->			List[str]:
					__snake_case    :							str   	=				VideoMAEModelTester(self)
					__snake_case    :							List[str]   	=				ConfigTester(self			,						config_class=__lowerCamelCase			,						has_text_modality=__lowerCamelCase			,						hidden_size=37)



				def       _lowercase  (self       :   str			,						_A       :   Tuple			,						_A       :   Union[str, Any]			,						_A       :   int=False)					->			Optional[Any]:
					__snake_case    :							List[str]   	=				copy.deepcopy(__lowerCamelCase)

					if model_class == VideoMAEForPreTraining:
						# important: each video needs to have the same number of masked patches
						# hence we define a single mask, which we then repeat for each example in the batch
						__snake_case    :							List[str]   	=				torch.ones((self.model_tester.num_masks,))
						__snake_case    :							Tuple   	=				torch.cat([mask, torch.zeros(self.model_tester.seq_length - mask.size(0))])
						__snake_case    :							Optional[Any]   	=				mask.expand(self.model_tester.batch_size			,						-1).bool()
						__snake_case    :							Dict   	=				bool_masked_pos.to(__lowerCamelCase)

					if return_labels:
						if model_class in [
						    *get_values(__lowerCamelCase),
						]:
							__snake_case    :							str   	=				torch.zeros(
							    self.model_tester.batch_size			,						dtype=torch.long			,						device=__lowerCamelCase)

					return inputs_dict



				def       _lowercase  (self       :   int)					->			List[str]:
					self.config_tester.run_common_tests()



				@unittest.skip(reason='VideoMAE does not use inputs_embeds')
				def       _lowercase  (self       :   Any)					->			Union[str, Any]:
					pass



				def       _lowercase  (self       :   Union[str, Any])					->			Optional[int]:
					__snake_case    :							Tuple   	=				self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
						__snake_case    :							Optional[Any]   	=				model_class(__lowerCamelCase)
						self.assertIsInstance(model.get_input_embeddings()			,						(nn.Module))
						__snake_case    :							str   	=				model.get_output_embeddings()
						self.assertTrue(x is None or isinstance(__lowerCamelCase			,						nn.Linear))



				def       _lowercase  (self       :   Union[str, Any])					->			List[str]:
					__snake_case    :							Optional[int]   	=				self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
						__snake_case    :							List[str]   	=				model_class(__lowerCamelCase)
						__snake_case    :							List[Any]   	=				inspect.signature(model.forward)
						# signature.parameters is an OrderedDict => so arg_names order is deterministic
						__snake_case    :							Optional[Any]   	=				[*signature.parameters.keys()]

						__snake_case    :							List[str]   	=				['''pixel_values''']
						self.assertListEqual(arg_names[:1]			,						__lowerCamelCase)



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



				def       _lowercase  (self       :   Union[str, Any])					->			Dict:
					__snake_case    :							List[str]   	=				self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_pretraining(*__lowerCamelCase)



				@slow
				def       _lowercase  (self       :   int)					->			str:






					for model_name in VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						__snake_case    :							Union[str, Any]   	=				VideoMAEModel.from_pretrained(__lowerCamelCase)
						self.assertIsNotNone(__lowerCamelCase)



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






					if not self.has_attentions:
						pass

					else:
						__snake_case    :							Dict   	=				self.model_tester.prepare_config_and_inputs_for_common()
						__snake_case    :							List[Any]   	=				True

						for model_class in self.all_model_classes:
							__snake_case    :							List[str]   	=				self.model_tester.seq_length - self.model_tester.num_masks
							__snake_case    :							Optional[int]   	=				(
							    num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length
							)

							__snake_case    :							Optional[int]   	=				True
							__snake_case    :							Dict   	=				False
							__snake_case    :							List[str]   	=				True
							__snake_case    :							str   	=				model_class(__lowerCamelCase)
							model.to(__lowerCamelCase)
							model.eval()
							with torch.no_grad():
								__snake_case    :							Dict   	=				model(**self._prepare_for_class(__lowerCamelCase			,						__lowerCamelCase))
							__snake_case    :							Tuple   	=				outputs.attentions
							self.assertEqual(len(__lowerCamelCase)			,						self.model_tester.num_hidden_layers)

							# check that output_attentions also work using config
							del inputs_dict["output_attentions"]
							__snake_case    :							Optional[Any]   	=				True
							__snake_case    :							Optional[Any]   	=				model_class(__lowerCamelCase)
							model.to(__lowerCamelCase)
							model.eval()
							with torch.no_grad():
								__snake_case    :							Optional[int]   	=				model(**self._prepare_for_class(__lowerCamelCase			,						__lowerCamelCase))
							__snake_case    :							List[str]   	=				outputs.attentions
							self.assertEqual(len(__lowerCamelCase)			,						self.model_tester.num_hidden_layers)

							self.assertListEqual(
							    list(attentions[0].shape[-3:])			,						[self.model_tester.num_attention_heads, seq_len, seq_len]			,						)
							__snake_case    :							str   	=				len(__lowerCamelCase)

							# Check attention is always last and order is fine
							__snake_case    :							Union[str, Any]   	=				True
							__snake_case    :							List[Any]   	=				True
							__snake_case    :							List[str]   	=				model_class(__lowerCamelCase)
							model.to(__lowerCamelCase)
							model.eval()
							with torch.no_grad():
								__snake_case    :							List[Any]   	=				model(**self._prepare_for_class(__lowerCamelCase			,						__lowerCamelCase))

							self.assertEqual(out_len + 1			,						len(__lowerCamelCase))

							__snake_case    :							Optional[int]   	=				outputs.attentions

							self.assertEqual(len(__lowerCamelCase)			,						self.model_tester.num_hidden_layers)
							self.assertListEqual(
							    list(self_attentions[0].shape[-3:])			,						[self.model_tester.num_attention_heads, seq_len, seq_len]			,						)



				def       _lowercase  (self       :   Any)					->			List[Any]:






					def check_hidden_states_output(_A       :   Union[str, Any]			,						_A       :   Dict			,						_A       :   Union[str, Any]):
						__snake_case    :							Any   	=				model_class(__lowerCamelCase)
						model.to(__lowerCamelCase)
						model.eval()

						with torch.no_grad():
							__snake_case    :							Optional[Any]   	=				model(**self._prepare_for_class(__lowerCamelCase			,						__lowerCamelCase))

						__snake_case    :							Any   	=				outputs.hidden_states
						__snake_case    :							Union[str, Any]   	=				self.model_tester.num_hidden_layers + 1
						self.assertEqual(len(__lowerCamelCase)			,						__lowerCamelCase)

						__snake_case    :							str   	=				self.model_tester.seq_length - self.model_tester.num_masks
						__snake_case    :							int   	=				num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length

						self.assertListEqual(
						    list(hidden_states[0].shape[-2:])			,						[seq_length, self.model_tester.hidden_size]			,						)

					__snake_case    :							Any   	=				self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
						__snake_case    :							List[str]   	=				True
						check_hidden_states_output(__lowerCamelCase			,						__lowerCamelCase			,						__lowerCamelCase)

						# check that output_hidden_states also work using config
						del inputs_dict["output_hidden_states"]
						__snake_case    :							List[str]   	=				True

						check_hidden_states_output(__lowerCamelCase			,						__lowerCamelCase			,						__lowerCamelCase)






				@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.')
				def       _lowercase  (self       :   Optional[Any])					->			int:
					pass







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

	'''simple docstring'''





	__snake_case    :							str   	=				hf_hub_download(
	    repo_id='hf-internal-testing/spaghetti-video'    ,							filename='eating_spaghetti.npy'    ,							repo_type='dataset'						)
	__snake_case    :							Tuple   	=				np.load(lowerCamelCase_						)
	return list(lowerCamelCase_						)

@require_torch
@require_vision
class 	UpperCamelCase    (					unittest.TestCase		):



				@cached_property
				def       _lowercase  (self       :   int)					->			Optional[Any]:
					return (
					    VideoMAEImageProcessor(image_mean=[0.5, 0.5, 0.5]			,						image_std=[0.5, 0.5, 0.5])
					    if is_vision_available()
					    else None
					)



				@slow
				def       _lowercase  (self       :   Optional[int])					->			List[str]:
					__snake_case    :							int   	=				VideoMAEForVideoClassification.from_pretrained('MCG-NJU/videomae-base-finetuned-kinetics').to(
					    __lowerCamelCase)

					__snake_case    :							Dict   	=				self.default_image_processor
					__snake_case    :							Dict   	=				prepare_video()
					__snake_case    :							str   	=				image_processor(__lowerCamelCase			,						return_tensors='pt').to(__lowerCamelCase)

					# forward pass
					with torch.no_grad():
						__snake_case    :							List[Any]   	=				model(**__lowerCamelCase)

					# verify the logits
					__snake_case    :							Any   	=				torch.Size((1, 4_00))
					self.assertEqual(outputs.logits.shape			,						__lowerCamelCase)

					__snake_case    :							List[str]   	=				torch.tensor([0.3_669, -0.0_688, -0.2_421]).to(__lowerCamelCase)

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






				@slow
				def       _lowercase  (self       :   Optional[Any])					->			Any:
					__snake_case    :							Union[str, Any]   	=				VideoMAEForPreTraining.from_pretrained('MCG-NJU/videomae-base-short').to(__lowerCamelCase)

					__snake_case    :							Any   	=				self.default_image_processor
					__snake_case    :							str   	=				prepare_video()
					__snake_case    :							Tuple   	=				image_processor(__lowerCamelCase			,						return_tensors='pt').to(__lowerCamelCase)

					# add boolean mask, indicating which patches to mask
					__snake_case    :							int   	=				hf_hub_download(repo_id='hf-internal-testing/bool-masked-pos'			,						filename='bool_masked_pos.pt')
					__snake_case    :							Any   	=				torch.load(__lowerCamelCase)

					# forward pass
					with torch.no_grad():
						__snake_case    :							str   	=				model(**__lowerCamelCase)

					# verify the logits
					__snake_case    :							Tuple   	=				torch.Size([1, 14_08, 15_36])
					__snake_case    :							Union[str, Any]   	=				torch.tensor(
					    [[0.7_994, 0.9_612, 0.8_508], [0.7_401, 0.8_958, 0.8_302], [0.5_862, 0.7_468, 0.7_325]]			,						device=__lowerCamelCase)
					self.assertEqual(outputs.logits.shape			,						__lowerCamelCase)
					self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]			,						__lowerCamelCase			,						atol=1E-4))

					# verify the loss (`config.norm_pix_loss` = `True`)
					__snake_case    :							Tuple   	=				torch.tensor([0.5_142]			,						device=__lowerCamelCase)
					self.assertTrue(torch.allclose(outputs.loss			,						__lowerCamelCase			,						atol=1E-4))

					# verify the loss (`config.norm_pix_loss` = `False`)
					__snake_case    :							int   	=				VideoMAEForPreTraining.from_pretrained('MCG-NJU/videomae-base-short'			,						norm_pix_loss=__lowerCamelCase).to(
					    __lowerCamelCase)

					with torch.no_grad():
						__snake_case    :							List[Any]   	=				model(**__lowerCamelCase)

					__snake_case    :							Any   	=				torch.tensor(torch.tensor([0.6_469])			,						device=__lowerCamelCase)
					self.assertTrue(torch.allclose(outputs.loss			,						__lowerCamelCase			,						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_						)





