




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       lowercase(  unittest.TestCase				):







 '''simple docstring'''





 def __init__(       self:	Optional[int],   a_:	int	):




   '''simple docstring'''



   _snake_case							:	Union[str, Any]			=						parent


 def 				UpperCamelCase_     (       self:	List[str]	):




   '''simple docstring'''



   return {}







def       UpperCAmelCase__ ():
  """simple docstring"""

  _snake_case							:	Optional[int]			=						"""<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							:	Optional[int]			=						"""\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       lowercase(  __a ,    unittest.TestCase				):







 '''simple docstring'''





 lowercase__				      =      MarkupLMFeatureExtractor if is_bsa_available() else None


 def 				UpperCamelCase_     (       self:	Any	):




   '''simple docstring'''



   _snake_case							:	Dict			=						MarkupLMFeatureExtractionTester(self	)


 @property
 def 				UpperCamelCase_     (       self:	Optional[int]	):




   '''simple docstring'''



   return self.feature_extract_tester.prepare_feat_extract_dict()


 def 				UpperCamelCase_     (       self:	Any	):




   '''simple docstring'''



   _snake_case							:	Optional[int]			=						self.feature_extraction_class()

   # Test not batched input
   _snake_case							:	Optional[int]			=						get_html_strings()[0]
   _snake_case							:	Optional[int]			=						feature_extractor(lowerCAmelCase_	)

   # fmt: off
   _snake_case							:	Optional[Any]			=						[["""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							:	List[str]			=						[["""/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							:	Any			=						get_html_strings()
   _snake_case							:	List[Any]			=						feature_extractor(lowerCAmelCase_	)

   # fmt: off
   _snake_case							:	Tuple			=						expected_nodes + [["""My First Heading""", """My first paragraph."""]]
   _snake_case							:	Tuple			=						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"""


from ...processing_utils import ProcessorMixin






class       lowercase(  __a				):







 '''simple docstring'''





 lowercase__				      =      ["image_processor", "feature_extractor"]
 lowercase__				      =      "TvltImageProcessor"
 lowercase__				      =      "TvltFeatureExtractor"


 def __init__(       self:	Dict,   a_:	Union[str, Any],   a_:	Union[str, Any]	):




   '''simple docstring'''



   super().__init__(image_processor=a_,   feature_extractor=a_	)

   _snake_case							:	Any			=						image_processor
   _snake_case							:	Dict			=						feature_extractor


 def __call__(       self:	int,   a_:	str=None,   a_:	Tuple=None,   a_:	Dict=None,   a_:	str=None,   a_:	Optional[int]=False,   a_:	Tuple=False,   *a_:	List[str],   **a_:	int,   ):




   '''simple docstring'''



   if images is None and audio is None:
     raise ValueError("""You need to specify either an `images` or `audio` input to process."""	)

   _snake_case							:	Optional[int]			=						None
   if images is not None:
     _snake_case							:	Tuple			=						self.image_processor(a_,   mask_pixel=a_,   *a_,   **a_	)
   if images_mixed is not None:
     _snake_case							:	Optional[int]			=						self.image_processor(a_,   is_mixed=a_,   *a_,   **a_	)
   if audio is not None:
     _snake_case							:	Any			=						self.feature_extractor(
         a_,   *a_,   sampling_rate=a_,   mask_audio=a_,   **a_	)

   _snake_case							:	List[str]			=						{}
   if audio is not None:
     output_dict.update(a_	)
   if images is not None:
     output_dict.update(a_	)
   if images_mixed_dict is not None:
     output_dict.update(a_	)
   return output_dict


 @property
 def 				UpperCamelCase_     (       self:	List[str]	):




   '''simple docstring'''



   _snake_case							:	Dict			=						self.image_processor.model_input_names
   _snake_case							:	List[str]			=						self.feature_extractor.model_input_names
   return list(dict.fromkeys(image_processor_input_names + feature_extractor_input_names	)	)


