# ruff: noqa: RUF001 def test_text_from_html_success_english(): """ Given - html string:

This is heading 1

When - extracting text from the html Then - ensure we return "This is heading 1" """ import TextFromHTML html = """

This is heading 1

""" body = TextFromHTML.get_body(html, html_tag="body") res = TextFromHTML.get_plain_text(body, replace_line_breaks=False, trim_result=False) assert res == "\nThis is heading 1\n" def test_text_from_html_success_hebrew(): """ Given - html string:

משפט בעברית לבדיקה

When - extracting text from the html Then - ensure we return "משפט בעברית לבדיקה" """ import TextFromHTML html = """

משפט בעברית לבדיקה

""" body = TextFromHTML.get_body(html, html_tag="body") res = TextFromHTML.get_plain_text(body, replace_line_breaks=False, trim_result=False) assert res == "\nמשפט בעברית לבדיקה\n" def test_text_from_html_success_spanish(): """ Given - html string:

Frase en español para revisión

When - extracting text from the html Then - ensure we return "Frase en español para revisión" """ import TextFromHTML html = """

Frase en español para revisión

""" body = TextFromHTML.get_body(html, html_tag="body") res = TextFromHTML.get_plain_text(body, replace_line_breaks=False, trim_result=False) assert res == "\nFrase en español para revisión\n" def test_extract_text_from_complex_html(): """ Given - html string:

HTML Links

HTML links are defined with the a tag:

This is a link When - extracting text from the html Then - ensure we return "This is heading 1" """ import TextFromHTML html = """

HTML Links

HTML links are defined with the a tag:

This is a link """ body = TextFromHTML.get_body(html, html_tag="body") res = TextFromHTML.get_plain_text(body, replace_line_breaks=False, trim_result=False) assert res == "\n\nHTML Links\nHTML links are defined with the a tag:\n\nThis is a link\n\n" def test_extract_text_from_html_with_breaks(): """ Given - html string:

HTML Breaks

HTML can contain break tags


Which should lead to a proper linebreak

When - extracting text from the html Then - ensure we return "\nHTML Breaks\nHTML can contain break tags\n\n\nWhich should lead to a proper linebreak" """ import TextFromHTML html = """

HTML Breaks

HTML can contain break tags


Which should lead to a proper linebreak

""" body = TextFromHTML.get_body(html, html_tag="body") res = TextFromHTML.get_plain_text(body, replace_line_breaks=True, trim_result=False) assert res == "\nHTML Breaks\nHTML can contain break tags\n\n\nWhich should lead to a proper linebreak\n" def test_extract_text_from_html_with_breaks_trimed(): """ Given - html string:

HTML Breaks

HTML can contain break tags


Which should lead to a proper linebreak

When - extracting text from the html with replace_line_breaks and trim_result enabled Then - ensure we return "HTML Breaks\nHTML can contain break tags\n\nWhich should lead to a proper linebreak" """ import TextFromHTML html = """

HTML Breaks

HTML can contain break tags


Which should lead to a proper linebreak

""" body = TextFromHTML.get_body(html, html_tag="body") res = TextFromHTML.get_plain_text(body, replace_line_breaks=True, trim_result=True) assert res == "HTML Breaks\nHTML can contain break tags\n\nWhich should lead to a proper linebreak" def test_extract_text_from_specific_tag(): """ Given - html string:

HTML links are defined with the a tag:

When - extracting text from the html Then - ensure we return "HTML links are defined with the a tag:" """ import TextFromHTML html = """

HTML links are defined with the a tag:

""" body = TextFromHTML.get_body(html, html_tag="p") res = TextFromHTML.get_plain_text(body, replace_line_breaks=False, trim_result=False) assert res == "HTML links are defined with the a tag:" def test_extract_with_fallback(): """ Given - html string:
Some HTML does not have a body Tag
When - extracting text from the html with fallback enabled Then - ensure we return "Some HTML does not have a body Tag" """ import TextFromHTML html = """
Some HTML does not have a body Tag
""" body = TextFromHTML.get_body(html, html_tag="body", allow_fallback=True) res = TextFromHTML.get_plain_text(body, replace_line_breaks=False, trim_result=False) assert res == "Some HTML does not have a body Tag" def test_extract_without_fallback(): """ Given - html string:
Some HTML does not have a body Tag
When - extracting text from the html Then - ensure we return "" """ import TextFromHTML html = """
Some HTML does not have a body Tag
""" body = TextFromHTML.get_body(html, html_tag="body", allow_fallback=False) res = TextFromHTML.get_plain_text(body, replace_line_breaks=False, trim_result=False) assert res == "" def test_get_body(): """ Given - html string:

This is heading 1

When - extracting body from html Then - ensure we return "\n

This is heading 1

\n" """ import TextFromHTML html = """

This is heading 1

""" body = TextFromHTML.get_body(html, html_tag="body", allow_fallback=False) assert body == "\n

This is heading 1

\n" def test_get_body_without_fallback(): """ Given - html string:
Some HTML does not have a body Tag
When - extracting body from html Then - ensure we return "" """ import TextFromHTML html = """
Some HTML does not have a body Tag
""" body = TextFromHTML.get_body(html, html_tag="body", allow_fallback=False) assert body == "" def test_get_body_with_fallback(): """ Given - html string:
Some HTML does not have a body Tag
When - extracting body from html Then - ensure we return "" """ import TextFromHTML html = """
Some HTML does not have a body Tag
""" body = TextFromHTML.get_body(html, html_tag="body", allow_fallback=True) assert body == "
Some HTML does not have a body Tag
"