Commit bee89758 authored by Jakob Lerch's avatar Jakob Lerch
Browse files

delete utils and old translation test

parent 07c3955e
import requests
import json
def translate_src_to_dst(url: str, src_string: str, src_lang: str, dst_lang: str, api_key: str) -> str:
r = requests.post(
url + "/translate",
data={
"q": src_string if src_string != "" else " ",
"source": src_lang,
"target": dst_lang,
"format": "text"
}
)
return json.loads(r.text)["translatedText"]
from configparser import ConfigParser
import json
import requests
from functools import cache
import protocol_translation.utils as utils
def init():
api_keys = ConfigParser()
api_keys.read("api_keys.conf")
config = ConfigParser()
config.read("config.conf")
return (api_keys, config)
def test_translate():
keys, conf = init()
text_de = "Dies ist ein Ball."
text_en = "this is a ball."
translated_text = utils.translate_src_to_dst(
conf["main"]["libretranslate_service_url"], text_de, "de", "en", keys["default"]["libretranslate_key"])
assert translated_text == text_en
def test_translate_empty():
keys, conf = init()
text_de = ""
text_en = ""
translated_text = utils.translate_src_to_dst(
conf["main"]["libretranslate_service_url"], text_de, "de", "en", keys["default"]["libretranslate_key"])
assert translated_text == text_en
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment