[gedit-plugins/translate] UT
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins/translate] UT
- Date: Mon, 17 Jul 2017 06:05:06 +0000 (UTC)
commit 88bc3e4a59592e0d5403d44a6024dfc03ae6a703
Author: Jordi Mas <jmas softcatala org>
Date: Mon Jul 17 08:04:45 2017 +0200
UT
plugins/translate/Makefile.am | 6 ++-
plugins/translate/run-tests.sh | 3 +
plugins/translate/tests/testapertium.py | 47 ++++++++++++++++++++
plugins/translate/translate/__init__.py | 2 +-
.../translate/translate/{ => backends}/apertium.py | 3 +
5 files changed, 58 insertions(+), 3 deletions(-)
---
diff --git a/plugins/translate/Makefile.am b/plugins/translate/Makefile.am
index 338bfd6..badda07 100644
--- a/plugins/translate/Makefile.am
+++ b/plugins/translate/Makefile.am
@@ -1,12 +1,14 @@
if ENABLE_PYTHON
plugins_translatedir = $(plugindir)/translate
plugins_translate_PYTHON = \
- plugins/translate/translate/apertium.py \
plugins/translate/translate/__init__.py \
plugins/translate/translate/preferences.py \
- plugins/translate/translate/translator.py \
plugins/translate/translate/translateview.py
+plugins_backendsdir = $(plugindir)/translate/backends
+dist_plugins_backends_DATA = plugins/translate/translate/backends/apertium.py \
+ plugins/translate/translate/backends/translator.py
+
plugins_preferences_uidir = $(GEDIT_PLUGINS_DATA_DIR)/translate/ui
dist_plugins_preferences_ui_DATA = plugins/translate/translate/ui/preferences.ui
diff --git a/plugins/translate/run-tests.sh b/plugins/translate/run-tests.sh
new file mode 100755
index 0000000..6d0731c
--- /dev/null
+++ b/plugins/translate/run-tests.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+export PYTHONPATH=$PYTHONPATH:translate/
+nosetests3 tests
diff --git a/plugins/translate/tests/testapertium.py b/plugins/translate/tests/testapertium.py
new file mode 100644
index 0000000..795c4e5
--- /dev/null
+++ b/plugins/translate/tests/testapertium.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2017 Jordi Mas i Hernandez <jmas softcatala org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+
+import unittest
+from backends.apertium import Apertium
+from unittest.mock import patch, MagicMock
+
+
+# See: https://stackoverflow.com/questions/32043035/python-3-urlopen-context-manager-mocking
+class TestPagination(unittest.TestCase):
+
+ @patch('urllib.request.urlopen')
+ def test_cm(self, mock_urlopen):
+ cm = MagicMock()
+ cm.getcode.return_value = 200
+ cm.read.return_value = bytes('{"responseData": {"translatedText": "Hauries d\'haver-hi rebut una
c\u00f2pia"}, "responseDetails": null, "responseStatus": 200}', 'utf-8')
+ cm.__enter__.return_value = cm
+ mock_urlopen.return_value = cm
+
+ apertium = Apertium('hola')
+ translated = apertium.translate_text('You should have received a copy', 'eng|cat')
+ self.assertEqual('Hauries d\'haver-hi rebut una còpia', translated)
+
mock_urlopen.assert_called_with("https://www.apertium.org/apy/translate?langpair=eng|cat&markUnknown=no&q=You+should+have+received+a+copy")
+ #with urllib.request.urlopen('http://foo') as response:
+ # self.assertEqual(response.getcode(), 200)
+ # self.assertEqual(response.read(), 'contents') self.assertEquals(pagination.page, 2)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/plugins/translate/translate/__init__.py b/plugins/translate/translate/__init__.py
index a8d10c2..47a05b0 100644
--- a/plugins/translate/translate/__init__.py
+++ b/plugins/translate/translate/__init__.py
@@ -23,7 +23,7 @@ gi.require_version('GtkSource', '3.0')
gi.require_version('PeasGtk', '1.0')
from gi.repository import GObject, Gio, Gtk, Gedit, PeasGtk
-from .apertium import Apertium
+from .backends.apertium import Apertium
from .translateview import TranslateView
from .preferences import Preferences
import gettext
diff --git a/plugins/translate/translate/apertium.py b/plugins/translate/translate/backends/apertium.py
similarity index 99%
rename from plugins/translate/translate/apertium.py
rename to plugins/translate/translate/backends/apertium.py
index a3f3f6d..63a4f7f 100644
--- a/plugins/translate/translate/apertium.py
+++ b/plugins/translate/translate/backends/apertium.py
@@ -44,6 +44,9 @@ class Apertium(Translator):
def __init__(self):
self._get_remote_language_names_and_pairs()
+ def __init__(self, string):
+ pass
+
def get_language_names(self):
if len(Apertium.g_language_codes) > 0 and len(Apertium.g_language_names) > 0:
return Apertium.g_language_names
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]