Use Spaces to connect paragraphs in English
Browse files- lib/pages.py +6 -1
- tests/test_accuracy.py +6 -4
- tests/test_accuracy_and_delay.py +9 -7
lib/pages.py
CHANGED
|
@@ -74,9 +74,14 @@ class TranslatorPage:
|
|
| 74 |
print(f"capture page latest content finished")
|
| 75 |
return translate_items
|
| 76 |
|
| 77 |
-
def get_translated_texts(self):
|
| 78 |
src_all = self.page.locator(".trans-list").locator(".trans-src-lang").all_inner_texts()
|
| 79 |
dst_all = self.page.locator(".trans-list").locator(".trans-dst-lang").all_inner_texts()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
return "".join(src_all), "".join(dst_all)
|
| 81 |
|
| 82 |
|
|
|
|
| 74 |
print(f"capture page latest content finished")
|
| 75 |
return translate_items
|
| 76 |
|
| 77 |
+
def get_translated_texts(self, translation_lang):
|
| 78 |
src_all = self.page.locator(".trans-list").locator(".trans-src-lang").all_inner_texts()
|
| 79 |
dst_all = self.page.locator(".trans-list").locator(".trans-dst-lang").all_inner_texts()
|
| 80 |
+
# 使用空格连接英文的不同段落
|
| 81 |
+
if translation_lang == "zh2en":
|
| 82 |
+
return "".join(src_all), " ".join(dst_all)
|
| 83 |
+
elif translation_lang == "en2zh":
|
| 84 |
+
return " ".join(src_all), "".join(dst_all)
|
| 85 |
return "".join(src_all), "".join(dst_all)
|
| 86 |
|
| 87 |
|
tests/test_accuracy.py
CHANGED
|
@@ -10,12 +10,13 @@ from lib.report import AccuracyReport, AccuracyItem
|
|
| 10 |
@pytest.mark.parametrize("audio", test_audios.get("zh"))
|
| 11 |
def test_accuracy_zh2en(app, page: TranslatorPage, accuracy_report: AccuracyReport, audio:Path):
|
| 12 |
page.start_zh2en()
|
|
|
|
| 13 |
play_audio_until_end(audio)
|
| 14 |
time.sleep(4)
|
| 15 |
page.set_off()
|
| 16 |
-
zh, en = page.get_translated_texts()
|
| 17 |
accuracy_report.items.append(
|
| 18 |
-
AccuracyItem(translation_type=
|
| 19 |
audio_length=get_length(audio), audio_text=audio_texts.get(audio.stem),
|
| 20 |
src_text=zh, dst_text=en)
|
| 21 |
)
|
|
@@ -24,12 +25,13 @@ def test_accuracy_zh2en(app, page: TranslatorPage, accuracy_report: AccuracyRepo
|
|
| 24 |
@pytest.mark.parametrize("audio", test_audios.get("en"))
|
| 25 |
def test_accuracy_en2zh(app, page: TranslatorPage, accuracy_report: AccuracyReport, audio):
|
| 26 |
page.start_en2zh()
|
|
|
|
| 27 |
play_audio_until_end(audio)
|
| 28 |
time.sleep(4)
|
| 29 |
page.set_off()
|
| 30 |
-
en, zh = page.get_translated_texts()
|
| 31 |
accuracy_report.items.append(
|
| 32 |
-
AccuracyItem(translation_type=
|
| 33 |
audio_length=get_length(audio), audio_text=audio_texts.get(audio.stem),
|
| 34 |
src_text=en, dst_text=zh)
|
| 35 |
)
|
|
|
|
| 10 |
@pytest.mark.parametrize("audio", test_audios.get("zh"))
|
| 11 |
def test_accuracy_zh2en(app, page: TranslatorPage, accuracy_report: AccuracyReport, audio:Path):
|
| 12 |
page.start_zh2en()
|
| 13 |
+
translation_lang = "zh2en"
|
| 14 |
play_audio_until_end(audio)
|
| 15 |
time.sleep(4)
|
| 16 |
page.set_off()
|
| 17 |
+
zh, en = page.get_translated_texts(translation_lang)
|
| 18 |
accuracy_report.items.append(
|
| 19 |
+
AccuracyItem(translation_type=translation_lang, audio=audio.name,
|
| 20 |
audio_length=get_length(audio), audio_text=audio_texts.get(audio.stem),
|
| 21 |
src_text=zh, dst_text=en)
|
| 22 |
)
|
|
|
|
| 25 |
@pytest.mark.parametrize("audio", test_audios.get("en"))
|
| 26 |
def test_accuracy_en2zh(app, page: TranslatorPage, accuracy_report: AccuracyReport, audio):
|
| 27 |
page.start_en2zh()
|
| 28 |
+
translation_lang = "en2zh"
|
| 29 |
play_audio_until_end(audio)
|
| 30 |
time.sleep(4)
|
| 31 |
page.set_off()
|
| 32 |
+
en, zh = page.get_translated_texts(translation_lang)
|
| 33 |
accuracy_report.items.append(
|
| 34 |
+
AccuracyItem(translation_type=translation_lang, audio=audio.name,
|
| 35 |
audio_length=get_length(audio), audio_text=audio_texts.get(audio.stem),
|
| 36 |
src_text=en, dst_text=zh)
|
| 37 |
)
|
tests/test_accuracy_and_delay.py
CHANGED
|
@@ -13,6 +13,7 @@ def test_accuracy_and_delay_zh2en(app, log_file, page: TranslatorPage,
|
|
| 13 |
delay_report: DelayReport, accuracy_report: AccuracyReport,
|
| 14 |
audio:Path,):
|
| 15 |
page.start_zh2en()
|
|
|
|
| 16 |
time.sleep(2)
|
| 17 |
audio_length = get_length(audio)
|
| 18 |
play_audio(audio)
|
|
@@ -20,12 +21,12 @@ def test_accuracy_and_delay_zh2en(app, log_file, page: TranslatorPage,
|
|
| 20 |
page.set_off()
|
| 21 |
log_records, delay_report.start_line = LogReport().from_logfile(log_file, delay_report.start_line)
|
| 22 |
delay_report.items.append(
|
| 23 |
-
DelayItem(translation_type=
|
| 24 |
web_items=web_records, log_items=log_records, )
|
| 25 |
)
|
| 26 |
-
zh, en = page.get_translated_texts()
|
| 27 |
accuracy_report.items.append(
|
| 28 |
-
AccuracyItem(translation_type=
|
| 29 |
audio_length=get_length(audio), audio_text=audio_texts.get(audio.stem),
|
| 30 |
src_text=zh, dst_text=en)
|
| 31 |
)
|
|
@@ -34,8 +35,9 @@ def test_accuracy_and_delay_zh2en(app, log_file, page: TranslatorPage,
|
|
| 34 |
@pytest.mark.parametrize("audio", test_audios.get("en"))
|
| 35 |
def test_accuracy_and_delay_en2zh(app, log_file, page: TranslatorPage,
|
| 36 |
delay_report: DelayReport, accuracy_report: AccuracyReport,
|
| 37 |
-
audio:Path
|
| 38 |
page.start_en2zh()
|
|
|
|
| 39 |
time.sleep(2)
|
| 40 |
audio_length = get_length(audio)
|
| 41 |
play_audio(audio)
|
|
@@ -43,13 +45,13 @@ def test_accuracy_and_delay_en2zh(app, log_file, page: TranslatorPage,
|
|
| 43 |
page.set_off()
|
| 44 |
log_records, delay_report.start_line = LogReport().from_logfile(log_file, delay_report.start_line)
|
| 45 |
delay_report.items.append(
|
| 46 |
-
DelayItem(translation_type=
|
| 47 |
web_items=web_records, log_items=log_records, )
|
| 48 |
)
|
| 49 |
|
| 50 |
-
en, zh = page.get_translated_texts()
|
| 51 |
accuracy_report.items.append(
|
| 52 |
-
AccuracyItem(translation_type=
|
| 53 |
audio_length=get_length(audio), audio_text=audio_texts.get(audio.stem),
|
| 54 |
src_text=en, dst_text=zh)
|
| 55 |
)
|
|
|
|
| 13 |
delay_report: DelayReport, accuracy_report: AccuracyReport,
|
| 14 |
audio:Path,):
|
| 15 |
page.start_zh2en()
|
| 16 |
+
translation_lang = "zh2en"
|
| 17 |
time.sleep(2)
|
| 18 |
audio_length = get_length(audio)
|
| 19 |
play_audio(audio)
|
|
|
|
| 21 |
page.set_off()
|
| 22 |
log_records, delay_report.start_line = LogReport().from_logfile(log_file, delay_report.start_line)
|
| 23 |
delay_report.items.append(
|
| 24 |
+
DelayItem(translation_type=translation_lang, audio=audio.name, audio_length=audio_length,
|
| 25 |
web_items=web_records, log_items=log_records, )
|
| 26 |
)
|
| 27 |
+
zh, en = page.get_translated_texts(translation_lang)
|
| 28 |
accuracy_report.items.append(
|
| 29 |
+
AccuracyItem(translation_type=translation_lang, audio=audio.name,
|
| 30 |
audio_length=get_length(audio), audio_text=audio_texts.get(audio.stem),
|
| 31 |
src_text=zh, dst_text=en)
|
| 32 |
)
|
|
|
|
| 35 |
@pytest.mark.parametrize("audio", test_audios.get("en"))
|
| 36 |
def test_accuracy_and_delay_en2zh(app, log_file, page: TranslatorPage,
|
| 37 |
delay_report: DelayReport, accuracy_report: AccuracyReport,
|
| 38 |
+
audio:Path):
|
| 39 |
page.start_en2zh()
|
| 40 |
+
translation_lang = "en2zh"
|
| 41 |
time.sleep(2)
|
| 42 |
audio_length = get_length(audio)
|
| 43 |
play_audio(audio)
|
|
|
|
| 45 |
page.set_off()
|
| 46 |
log_records, delay_report.start_line = LogReport().from_logfile(log_file, delay_report.start_line)
|
| 47 |
delay_report.items.append(
|
| 48 |
+
DelayItem(translation_type=translation_lang, audio=audio.name, audio_length=audio_length,
|
| 49 |
web_items=web_records, log_items=log_records, )
|
| 50 |
)
|
| 51 |
|
| 52 |
+
en, zh = page.get_translated_texts(translation_lang)
|
| 53 |
accuracy_report.items.append(
|
| 54 |
+
AccuracyItem(translation_type=translation_lang, audio=audio.name,
|
| 55 |
audio_length=get_length(audio), audio_text=audio_texts.get(audio.stem),
|
| 56 |
src_text=en, dst_text=zh)
|
| 57 |
)
|