File size: 2,296 Bytes
9dce458 |
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 |
import os
import sys
import pytest
pytest_plugins = ('pytest_asyncio')
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from manga_translator.translators import (
TRANSLATORS,
TranslatorChain,
OfflineTranslator,
MissingAPIKeyException,
dispatch,
)
@pytest.mark.asyncio
async def test_mixed_languages():
queries = ['How to be dead everyday', '', 'Ich bin ein deutscher', 'Test case m. HELLO THERE I WANT an audition! YOYOYOYO', '目标意识']
chain = TranslatorChain('google:ENG')
print(await dispatch(chain, queries))
@pytest.mark.asyncio
async def test_single_language():
queries = ['僕はアイネと共に一度、宿の方に戻った', '改めて直面するのは部屋の問題――部屋のベッドが一つでは、さすがに狭すぎるだろう。']
chain = TranslatorChain('google:ENG')
print(await dispatch(chain, queries))
@pytest.mark.asyncio
async def test_chain():
queries = ['僕はアイネと共に一度、宿の方に戻った', '改めて直面するのは部屋の問題――部屋のベッドが一つでは、さすがに狭すぎるだろう。']
chain = TranslatorChain('google:JPN;sugoi:ENG')
print(await dispatch(chain, queries))
@pytest.mark.asyncio
async def test_online_translators():
queries = ['僕はアイネと共に一度、宿の方に戻った', '改めて直面するのは部屋の問題――部屋のベッドが一つでは、さすがに狭すぎるだろう。']
for key in TRANSLATORS:
if issubclass(TRANSLATORS[key], OfflineTranslator):
continue
try:
chain = TranslatorChain(f'{key}:ENG')
print(await dispatch(chain, queries))
except MissingAPIKeyException as e:
print(e)
@pytest.mark.asyncio
async def test_offline_translators():
queries = ['僕はアイネと共に一度、宿の方に戻った', '改めて直面するのは部屋の問題――部屋のベッドが一つでは、さすがに狭すぎるだろう。']
for key in ('offline', 'sugoi', 'm2m100_big'):
if not issubclass(TRANSLATORS[key], OfflineTranslator):
continue
chain = TranslatorChain(f'{key}:ENG')
print(await dispatch(chain, queries))
|