File size: 2,524 Bytes
f9fcbaf
 
 
 
 
 
3d1d87d
f9fcbaf
 
 
 
 
 
 
 
ffcba68
e4406a3
f9fcbaf
 
 
 
 
 
ffcba68
f9fcbaf
 
ffcba68
f9fcbaf
ffcba68
f9fcbaf
 
 
 
 
 
 
 
ffcba68
f9fcbaf
ffcba68
e4406a3
f9fcbaf
 
 
 
 
 
ffcba68
f9fcbaf
 
 
ffcba68
f9fcbaf
ffcba68
f9fcbaf
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import time
from pathlib import Path
import pytest

from lib.audio import play_audio, get_length
from lib.pages import TranslatorPage
from test_data.audio_clips.audio_list import test_audios, audio_texts
from lib.report import AccuracyReport, AccuracyItem
from lib.report import DelayReport, DelayItem, LogReport

@pytest.mark.parametrize("audio", test_audios.get("zh"))
def test_accuracy_and_delay_zh2en(app, log_file, page: TranslatorPage,
                                  delay_report: DelayReport, accuracy_report: AccuracyReport,
                                  audio:Path,):
    page.start_zh2en()
    translation_lang = "zh2en"
    time.sleep(3)
    audio_length = get_length(audio)
    play_audio(audio)
    web_records = page.get_current_node_text(duration=audio_length)
    page.set_off()
    log_records, delay_report.start_line = LogReport().from_logfile(log_file, delay_report.start_line)
    delay_report.items.append(
        DelayItem(translation_type=translation_lang, audio=audio.name, audio_length=audio_length,
                  web_items=web_records, log_items=log_records, )
    )
    zh, en = page.get_translated_texts(translation_lang)
    accuracy_report.items.append(
        AccuracyItem(translation_type=translation_lang, audio=audio.name,
                     audio_length=get_length(audio), audio_text=audio_texts.get(audio.stem),
                     src_text=zh, dst_text=en)
    )


@pytest.mark.parametrize("audio", test_audios.get("en"))
def test_accuracy_and_delay_en2zh(app, log_file, page: TranslatorPage,
                                  delay_report: DelayReport, accuracy_report: AccuracyReport,
                                  audio:Path):
    page.start_en2zh()
    translation_lang = "en2zh"
    time.sleep(3)
    audio_length = get_length(audio)
    play_audio(audio)
    web_records = page.get_current_node_text(duration=audio_length)
    page.set_off()
    log_records, delay_report.start_line = LogReport().from_logfile(log_file, delay_report.start_line)
    delay_report.items.append(
        DelayItem(translation_type=translation_lang, audio=audio.name, audio_length=audio_length,
                  web_items=web_records, log_items=log_records, )
    )

    en, zh = page.get_translated_texts(translation_lang)
    accuracy_report.items.append(
        AccuracyItem(translation_type=translation_lang, audio=audio.name,
                     audio_length=get_length(audio), audio_text=audio_texts.get(audio.stem),
                     src_text=en, dst_text=zh)
    )