From 3fab35ee737582c91212513444c297c6a3812539 Mon Sep 17 00:00:00 2001 From: ayush-iitkgp Date: Mon, 9 Sep 2024 22:36:58 +0200 Subject: [PATCH] Fixed test_translate_multiple_html_success text --- app/helper.py | 12 ++++++++++++ tests/translation/api/data/de/canvas_example.html | 2 +- tests/translation/api/data/en/canvas_example.html | 2 +- tests/translation/api/test_html_translation.py | 15 +++++++++------ translation/services/html_translation_service.py | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/helper.py b/app/helper.py index 0117a0f..3ba92f7 100644 --- a/app/helper.py +++ b/app/helper.py @@ -1,4 +1,5 @@ from argostranslate.tags import Tag +from bs4 import BeautifulSoup def print_tag(tag: Tag, level: int = 0) -> None: @@ -13,3 +14,14 @@ def print_tag(tag: Tag, level: int = 0) -> None: # If it's a string, just print the string elif isinstance(tag, str): print(f"{indent}'{tag}'") + + +def get_soup(html_content: str) -> BeautifulSoup: + return BeautifulSoup(html_content, "html.parser") + + +def compare_html_structure(expected_html: str, translated_html: str) -> bool: + expected_soup = get_soup(expected_html) + translated_soup = get_soup(translated_html) + + return str(expected_soup.prettify()) == str(translated_soup.prettify()) diff --git a/tests/translation/api/data/de/canvas_example.html b/tests/translation/api/data/de/canvas_example.html index 23348df..cdb1559 100644 --- a/tests/translation/api/data/de/canvas_example.html +++ b/tests/translation/api/data/de/canvas_example.html @@ -4,7 +4,7 @@

Beispiel mit Leinwand

- +