translate: json cleanup improvement
parent
3988a73ade
commit
e195830e0a
|
@ -15,26 +15,26 @@ class TestTranslation(unittest.TestCase):
|
||||||
|
|
||||||
def test_translate(self):
|
def test_translate(self):
|
||||||
out = translate("plomo o plata", input='es')
|
out = translate("plomo o plata", input='es')
|
||||||
|
|
||||||
self.assertEqual(('lead or silver', 'es'), out)
|
self.assertEqual(('lead or silver', 'es'), out)
|
||||||
|
|
||||||
def test_tr(self):
|
def test_tr(self):
|
||||||
input = Mock(groups=lambda: ('fr', 'en', 'mon chien'))
|
input = Mock(groups=lambda: ('fr', 'en', 'mon chien'))
|
||||||
tr(self.phenny, input)
|
tr(self.phenny, input)
|
||||||
|
|
||||||
out = self.phenny.reply.call_args[0][0]
|
self.assertIn("my dog", self.phenny.reply.call_args[0][0])
|
||||||
m = re.match("^\"my dog\" \(fr to en, .*\)$",
|
|
||||||
out, flags=re.UNICODE)
|
|
||||||
self.assertTrue(m)
|
|
||||||
|
|
||||||
def test_tr2(self):
|
def test_tr2(self):
|
||||||
input = Mock(group=lambda x: 'Estoy bien')
|
input = Mock(group=lambda x: 'Estoy bien')
|
||||||
tr2(self.phenny, input)
|
tr2(self.phenny, input)
|
||||||
|
|
||||||
out = self.phenny.reply.call_args[0][0]
|
self.assertIn("I'm fine", self.phenny.reply.call_args[0][0])
|
||||||
m = re.match("^\"I'm fine\" \(es to en, .*\)$",
|
|
||||||
out, flags=re.UNICODE)
|
def test_translate_bracketnull(self):
|
||||||
self.assertTrue(m)
|
input = Mock(group=lambda x: 'Moja je lebdjelica puna jegulja')
|
||||||
|
tr2(self.phenny, input)
|
||||||
|
|
||||||
|
self.assertIn("My hovercraft is full of eels",
|
||||||
|
self.phenny.reply.call_args[0][0])
|
||||||
|
|
||||||
def test_mangle(self):
|
def test_mangle(self):
|
||||||
input = Mock(group=lambda x: 'Mangle this phrase!')
|
input = Mock(group=lambda x: 'Mangle this phrase!')
|
||||||
|
|
|
@ -34,6 +34,7 @@ def translate(text, input='auto', output='en'):
|
||||||
|
|
||||||
while ',,' in result:
|
while ',,' in result:
|
||||||
result = result.replace(',,', ',null,')
|
result = result.replace(',,', ',null,')
|
||||||
|
result = result.replace('[,', '[null,')
|
||||||
data = json.loads(result)
|
data = json.loads(result)
|
||||||
|
|
||||||
if raw:
|
if raw:
|
||||||
|
|
Loading…
Reference in New Issue