Пример #1
0
    def test_translate_full(self):
        translator = GoogleTranslator()

        self.assertEqual(translator.translate("house", "de"), "Haus")
        self.assertEqual(translator.translate("σπίτι", "en"), "home")
        self.assertEqual(
            translator.translate("house", "el", additional=True), {
                "verbs": {
                    "στεγάζω": ["house", "roof"],
                    "εστιώ": ["house"]
                },
                "nouns": {
                    "σπίτι": ["home", "house"],
                    "κατοικία": [
                        "residence", "house", "home", "dwelling", "domicile",
                        "residency"
                    ],
                    "οικία": ["house", "home"],
                    "οίκος": ["house", "home"],
                    "βουλή": [
                        "parliament", "house", "legislature", "diet",
                        "State house"
                    ]
                }
            })
Пример #2
0
    def test_translate(self, mock_do_work, mock_val_lang):
        translator = GoogleTranslator()

        self.assertEqual(translator.translate("test", "ru"),
                         mock_do_work.return_value)
        mock_val_lang.assert_has_calls(
            [mock.call("auto"),
             mock.call("ru", allow_auto=False)])
        mock_do_work.assert_called_once_with(translator._translate, "test",
                                             mock_val_lang.return_value,
                                             mock_val_lang.return_value, False,
                                             "text")

        mock_do_work.reset_mock()
        mock_val_lang.reset_mock()

        self.assertEqual(
            translator.translate("test",
                                 "ru",
                                 src_lang="en",
                                 additional=True,
                                 output="dict"), mock_do_work.return_value)
        mock_val_lang.assert_has_calls(
            [mock.call("en"),
             mock.call("ru", allow_auto=False)])
        mock_do_work.assert_called_once_with(translator._translate, "test",
                                             mock_val_lang.return_value,
                                             mock_val_lang.return_value, True,
                                             "dict")

        # Test invalid 'additional' param
        self.assertRaises(ValueError, translator.translate, "test", "ru", "en",
                          1234)