From e195830e0a21312172a574b0219b8aff052d3559 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Fri, 1 Nov 2013 21:54:37 -0700 Subject: [PATCH] translate: json cleanup improvement --- modules/test/test_translate.py | 18 +++++++++--------- modules/translate.py | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/test/test_translate.py b/modules/test/test_translate.py index b127a5c..c86bcb4 100644 --- a/modules/test/test_translate.py +++ b/modules/test/test_translate.py @@ -15,26 +15,26 @@ class TestTranslation(unittest.TestCase): def test_translate(self): out = translate("plomo o plata", input='es') - self.assertEqual(('lead or silver', 'es'), out) def test_tr(self): input = Mock(groups=lambda: ('fr', 'en', 'mon chien')) tr(self.phenny, input) - out = self.phenny.reply.call_args[0][0] - m = re.match("^\"my dog\" \(fr to en, .*\)$", - out, flags=re.UNICODE) - self.assertTrue(m) + self.assertIn("my dog", self.phenny.reply.call_args[0][0]) def test_tr2(self): input = Mock(group=lambda x: 'Estoy bien') tr2(self.phenny, input) - out = self.phenny.reply.call_args[0][0] - m = re.match("^\"I'm fine\" \(es to en, .*\)$", - out, flags=re.UNICODE) - self.assertTrue(m) + self.assertIn("I'm fine", self.phenny.reply.call_args[0][0]) + + def test_translate_bracketnull(self): + 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): input = Mock(group=lambda x: 'Mangle this phrase!') diff --git a/modules/translate.py b/modules/translate.py index d34bda0..7d26573 100644 --- a/modules/translate.py +++ b/modules/translate.py @@ -34,6 +34,7 @@ def translate(text, input='auto', output='en'): while ',,' in result: result = result.replace(',,', ',null,') + result = result.replace('[,', '[null,') data = json.loads(result) if raw: