WTE: python 2 compatibility + tests

This commit is contained in:
James Lu 2014-12-03 16:17:55 -08:00
parent 84539d50b2
commit 37a55db8bf
2 changed files with 10 additions and 0 deletions

View File

@ -28,6 +28,7 @@
### ###
from __future__ import unicode_literals
import supybot.utils as utils import supybot.utils as utils
from supybot.commands import * from supybot.commands import *
import supybot.plugins as plugins import supybot.plugins as plugins
@ -40,6 +41,8 @@ try: # Python 3
from urllib.parse import urlencode from urllib.parse import urlencode
except ImportError: # Python 2 except ImportError: # Python 2
from urllib import urlencode from urllib import urlencode
from sys import version_info
try: try:
from supybot.i18n import PluginInternationalization from supybot.i18n import PluginInternationalization
_ = PluginInternationalization('WTE') _ = PluginInternationalization('WTE')
@ -66,6 +69,8 @@ class WTE(callbacks.Plugin):
'ur', 'pl', 'eo', 'yo', 'en', 'yi') 'ur', 'pl', 'eo', 'yo', 'en', 'yi')
def getTranslation(self, irc, sourceLang, targetLang, text): def getTranslation(self, irc, sourceLang, targetLang, text):
if version_info[0] < 3:
text = text.encode("utf-8")
url = "http://translate.google.com/translate_a/t?"+ \ url = "http://translate.google.com/translate_a/t?"+ \
urlencode({"client": "p", urlencode({"client": "p",
"sl":sourceLang, "tl":targetLang, "sl":sourceLang, "tl":targetLang,

View File

@ -33,5 +33,10 @@ from supybot.test import *
class WTETestCase(PluginTestCase): class WTETestCase(PluginTestCase):
plugins = ('WTE',) plugins = ('WTE',)
def testWTE(self):
m = self.getMsg("wte The quick brown fox jumps over "
"the lazy dog.")
print('\nResponse: %s' % m.args[1])
assert m, 'No response found.'
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: