"""simple docstring"""
import unittest

from transformers.testing_utils import require_bsa
from transformers.utils import is_bsa_available

from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin


if is_bsa_available():
					from transformers import MarkupLMFeatureExtractor



class   lowerCAmelCase_    (			unittest.TestCase					):



				"""simple docstring"""

				def __init__(				self		,    lowerCAmelCase    ):






										"""simple docstring"""

										snake_case								=			parent

				def 		snake_case (				self    ):






										"""simple docstring"""

										return {}





def    lowerCAmelCase__    (			)					->				Tuple:





						"""simple docstring"""






						snake_case								=			'<HTML>\n\n    <HEAD>\n    <TITLE>sample document</TITLE>\n    </HEAD>\n\n    <BODY BGCOLOR="FFFFFF">\n    <HR>\n    <a href="http://google.com">Goog</a>\n    <H1>This is one header</H1>\n    <H2>This is a another Header</H2>\n    <P>Travel from\n        <P>\n        <B>SFO to JFK</B>\n        <BR>\n        <B><I>on May 2, 2015 at 2:00 pm. For details go to confirm.com </I></B>\n        <HR>\n        <div style="color:#0000FF">\n            <h3>Traveler <b> name </b> is\n            <p> John Doe </p>\n        </div>'

						snake_case								=			'\n    <!DOCTYPE html>\n    <html>\n    <body>\n\n    <h1>My First Heading</h1>\n    <p>My first paragraph.</p>\n\n    </body>\n    </html>\n    '

						return [html_string_a, html_string_a]



@require_bsa
class   lowerCAmelCase_    (			lowerCAmelCase     ,    unittest.TestCase					):



				"""simple docstring"""
				_lowerCAmelCase     :    Any			  =						MarkupLMFeatureExtractor if is_bsa_available() else None

				def 		snake_case (				self    ):






										"""simple docstring"""

										snake_case								=			MarkupLMFeatureExtractionTester(self    )

				@property
				def 		snake_case (				self    ):






										"""simple docstring"""

										return self.feature_extract_tester.prepare_feat_extract_dict()

				def 		snake_case (				self    ):






										"""simple docstring"""

										snake_case								=			self.feature_extraction_class()

										# Test not batched input
										snake_case								=			get_html_strings()[0]
										snake_case								=			feature_extractor(lowerCAmelCase    )

										# fmt: off
										snake_case								=			[['sample document', 'Goog', 'This is one header', 'This is a another Header', 'Travel from', 'SFO to JFK', 'on May 2, 2015 at 2:00 pm. For details go to confirm.com', 'Traveler', 'name', 'is', 'John Doe']]
										snake_case								=			[['/html/head/title', '/html/body/a', '/html/body/h1', '/html/body/h2', '/html/body/p', '/html/body/p/p/b[1]', '/html/body/p/p/b[2]/i', '/html/body/p/p/div/h3', '/html/body/p/p/div/h3/b', '/html/body/p/p/div/h3', '/html/body/p/p/div/h3/p']]
										# fmt: on

										self.assertEqual(encoding.nodes		,    lowerCAmelCase    )
										self.assertEqual(encoding.xpaths		,    lowerCAmelCase    )

										# Test batched
										snake_case								=			get_html_strings()
										snake_case								=			feature_extractor(lowerCAmelCase    )

										# fmt: off
										snake_case								=			expected_nodes + [['My First Heading', 'My first paragraph.']]
										snake_case								=			expected_xpaths + [['/html/body/h1', '/html/body/p']]

										self.assertEqual(len(encoding.nodes    )		,    2    )
										self.assertEqual(len(encoding.xpaths    )		,    2    )

										self.assertEqual(encoding.nodes		,    lowerCAmelCase    )
										self.assertEqual(encoding.xpaths		,    lowerCAmelCase    )
"""simple docstring"""
import enum
import os
from hashlib import shaaaa
from typing import Optional

from .. import config
from .logging import get_logger


SCREAMING_SNAKE_CASE__      						=  get_logger(__name__)



class   lowerCAmelCase_    (			enum.Enum					):



				"""simple docstring"""
				_lowerCAmelCase     :    Union[str, Any]			  =						"""all_checks"""
				_lowerCAmelCase     :    Optional[Any]			  =						"""basic_checks"""
				_lowerCAmelCase     :    Optional[int]			  =						"""no_checks"""





class   lowerCAmelCase_    (			lowerCAmelCase					):



				"""simple docstring"""





class   lowerCAmelCase_    (			lowerCAmelCase					):



				"""simple docstring"""





class   lowerCAmelCase_    (			lowerCAmelCase					):



				"""simple docstring"""





class   lowerCAmelCase_    (			lowerCAmelCase					):



				"""simple docstring"""





def    lowerCAmelCase__    (			_UpperCamelCase       :				Optional[dict] ,			_UpperCamelCase       :				dict ,			_UpperCamelCase       :				str=None					)					->				Dict:





						"""simple docstring"""






						if expected_checksums is None:
												logger.info('Unable to verify checksums.'					)
												return
						if len(set(_UpperCamelCase					) - set(_UpperCamelCase					)					) > 0:
												raise ExpectedMoreDownloadedFiles(str(set(_UpperCamelCase					) - set(_UpperCamelCase					)					)					)
						if len(set(_UpperCamelCase					) - set(_UpperCamelCase					)					) > 0:
												raise UnexpectedDownloadedFile(str(set(_UpperCamelCase					) - set(_UpperCamelCase					)					)					)
						snake_case								=			[url for url in expected_checksums if expected_checksums[url] != recorded_checksums[url]]
						snake_case								=			' for ' + verification_name if verification_name is not None else ''
						if len(_UpperCamelCase					) > 0:
												raise NonMatchingChecksumError(
												    f"""Checksums didn't match{for_verification_name}:\n"""
												    f"""{bad_urls}\n"""
												    'Set `verification_mode=\'no_checks\'` to skip checksums verification and ignore this error'					)
						logger.info('All the checksums matched successfully' + for_verification_name					)



class   lowerCAmelCase_    (			lowerCAmelCase					):



				"""simple docstring"""





class   lowerCAmelCase_    (			lowerCAmelCase					):



				"""simple docstring"""





class   lowerCAmelCase_    (			lowerCAmelCase					):



				"""simple docstring"""





class   lowerCAmelCase_    (			lowerCAmelCase					):



				"""simple docstring"""





def    lowerCAmelCase__    (			_UpperCamelCase       :				Optional[dict] ,			_UpperCamelCase       :				dict					)					->				Tuple:





						"""simple docstring"""






						if expected_splits is None:
												logger.info('Unable to verify splits sizes.'					)
												return
						if len(set(_UpperCamelCase					) - set(_UpperCamelCase					)					) > 0:
												raise ExpectedMoreSplits(str(set(_UpperCamelCase					) - set(_UpperCamelCase					)					)					)
						if len(set(_UpperCamelCase					) - set(_UpperCamelCase					)					) > 0:
												raise UnexpectedSplits(str(set(_UpperCamelCase					) - set(_UpperCamelCase					)					)					)
						snake_case								=			[
						    {'expected': expected_splits[name], 'recorded': recorded_splits[name]}
						    for name in expected_splits
						    if expected_splits[name].num_examples != recorded_splits[name].num_examples
						]
						if len(_UpperCamelCase					) > 0:
												raise NonMatchingSplitsSizesError(str(_UpperCamelCase					)					)
						logger.info('All the splits matched successfully.'					)





def    lowerCAmelCase__    (			_UpperCamelCase       :				str ,			_UpperCamelCase       :				bool = True					)					->				dict:





						"""simple docstring"""






						if record_checksum:
												snake_case								=			shaaaa()
												with open(_UpperCamelCase ,			'rb'					) as f:
																		for chunk in iter(lambda: f.read(1 << 2_0					) ,			B''					):
																								m.update(_UpperCamelCase					)
																		snake_case								=			m.hexdigest()
						else:
												snake_case								=			None
						return {"num_bytes": os.path.getsize(_UpperCamelCase					), "checksum": checksum}





def    lowerCAmelCase__    (			_UpperCamelCase       :				Optional[int]					)					->				int:





						"""simple docstring"""






						if dataset_size and config.IN_MEMORY_MAX_SIZE:
												return dataset_size < config.IN_MEMORY_MAX_SIZE
						else:
												return False


