From 0c489cf1fa4ebea448c52e428b6f01cedb5f54b4 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 16 Nov 2010 13:43:28 +0100 Subject: [PATCH] [ADD] test: added smoke test for tools.translate.quote and unquote bzr revid: odo@openerp.com-20101116124328-1ez3w3jxvf5v3ilt --- bin/test/__init__.py | 1 + bin/test/test_translate.py | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 bin/test/test_translate.py diff --git a/bin/test/__init__.py b/bin/test/__init__.py index 86872258874..248f468a34c 100644 --- a/bin/test/__init__.py +++ b/bin/test/__init__.py @@ -20,3 +20,4 @@ ############################################################################## from test_osv import * +from test_translate import * diff --git a/bin/test/test_translate.py b/bin/test/test_translate.py new file mode 100644 index 00000000000..2e67884409b --- /dev/null +++ b/bin/test/test_translate.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010 OpenERP S.A. http://www.openerp.com +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import unittest +from tools.translate import quote, unquote + +class TranslationToolsTestCase(unittest.TestCase): + + def test_quote_unquote(self): + + def test_string(str): + quoted = quote(str) + #print "\n1:", repr(str) + #print "2:", repr(quoted) + unquoted = unquote("".join(quoted.split('"\n"'))) + #print "3:", repr(unquoted) + self.assertEquals(str, unquoted) + + test_string("""test \nall kinds\n \n o\r + \\\\ nope\n\n" + """) + + # The ones with 1+ backslashes directly followed by + # a newline or literal N can fail... we would need a + # state-machine parser to handle these, but this would + # be much slower so it's better to avoid them at the moment + self.assertRaises(AssertionError, quote, """test \nall kinds\n\no\r + \\\\nope\n\n" + """) +