2020-11-04 17:21:52 +01:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from edmond.tests.test_plugin import get_plugin_patcher
|
|
|
|
from ..translate import TranslatePlugin
|
|
|
|
|
|
|
|
|
|
|
|
class TestTranslatePlugin(unittest.TestCase):
|
|
|
|
def test_parse_words(self):
|
|
|
|
with get_plugin_patcher(TranslatePlugin):
|
|
|
|
plugin = TranslatePlugin()
|
|
|
|
plugin.config = {
|
|
|
|
"default_dest": "en",
|
|
|
|
"param_source": "from",
|
|
|
|
"param_dest": "to",
|
|
|
|
}
|
|
|
|
|
|
|
|
# No params.
|
2022-08-15 14:26:31 +02:00
|
|
|
result = plugin.parse_words("test".split())
|
2020-11-04 17:21:52 +01:00
|
|
|
self.assertEqual(result, ("autodetect", "en", "test"))
|
2022-08-15 14:26:31 +02:00
|
|
|
# Source param (alone, so wrong).
|
|
|
|
result = plugin.parse_words("from fr test".split())
|
|
|
|
self.assertEqual(result, ("autodetect", "en", "from fr test"))
|
|
|
|
# Destination param (alone, so wrong).
|
|
|
|
result = plugin.parse_words("to fr test".split())
|
|
|
|
self.assertEqual(result, ("autodetect", "en", "to fr test"))
|
|
|
|
# Both source and dest params, OK.
|
|
|
|
result = plugin.parse_words("from it to fr test".split())
|
2020-11-04 17:21:52 +01:00
|
|
|
self.assertEqual(result, ("it", "fr", "test"))
|
|
|
|
# Badly placed param.
|
2022-08-15 14:26:31 +02:00
|
|
|
result = plugin.parse_words("from it test to fr".split())
|
|
|
|
self.assertEqual(result, ("autodetect", "en", "from it test to fr"))
|