From 393e6ffc23ea2e2f3d5c99ed35a30bef67a985e6 Mon Sep 17 00:00:00 2001 From: Steve Strassmann Date: Mon, 29 Apr 2013 11:35:01 -0400 Subject: [PATCH] added test cases for converter and dummy --- i18n/test/test_converter.py | 42 +++++++++++++++++++++++++++++++ i18n/test/test_dummy.py | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 i18n/test/test_converter.py create mode 100644 i18n/test/test_dummy.py diff --git a/i18n/test/test_converter.py b/i18n/test/test_converter.py new file mode 100644 index 0000000000..4dd5f02e3f --- /dev/null +++ b/i18n/test/test_converter.py @@ -0,0 +1,42 @@ +import os +from unittest import TestCase + +import converter + +class UpcaseConverter (converter.Converter): + """ + Converts a string to uppercase. Just used for testing. + """ + def inner_convert_string(self, string): + return string.upper() + + +class TestConverter(TestCase): + """ + Tests functionality of i18n/converter.py + """ + + def test_converter(self): + """ + Tests with a simple converter (converts strings to uppercase). + Assert that embedded HTML and python tags are not converted. + """ + c = UpcaseConverter() + test_cases = ( + # no tags + ('big bad wolf', 'BIG BAD WOLF'), + # one html tag + ('big bad wolf', 'BIG BAD WOLF'), + # two html tags + ('big bad wolf', 'BIG BAD WOLF'), + # one python tag + ('big %(adjective)s wolf', 'BIG %(adjective)s WOLF'), + # two python tags + ('big %(adjective)s %(noun)s', 'BIG %(adjective)s %(noun)s'), + # both kinds of tags + ('big %(adjective)s %(noun)s', + 'BIG %(adjective)s %(noun)s'), + ) + for (source, expected) in test_cases: + result = c.convert(source) + self.assertEquals(result, expected) diff --git a/i18n/test/test_dummy.py b/i18n/test/test_dummy.py new file mode 100644 index 0000000000..88addb5a95 --- /dev/null +++ b/i18n/test/test_dummy.py @@ -0,0 +1,50 @@ +import os, string, random +from unittest import TestCase +from polib import POEntry + +import dummy + + +class TestDummy(TestCase): + """ + Tests functionality of i18n/dummy.py + """ + + def setUp(self): + self.converter = dummy.Dummy() + + def test_dummy(self): + """ + Tests with a dummy converter (adds spurious accents to strings). + Assert that embedded HTML and python tags are not converted. + """ + test_cases = (("hello my name is Bond, James Bond", + u'h\xe9ll\xf6 my n\xe4m\xe9 \xefs B\xf6nd, J\xe4m\xe9s B\xf6nd Lorem i#'), + + ('don\'t convert tag ids', + u'd\xf6n\'t \xe7\xf6nv\xe9rt t\xe4g \xefds Lorem ipsu#'), + + ('don\'t convert %(name)s tags on %(date)s', + u"d\xf6n't \xe7\xf6nv\xe9rt %(name)s t\xe4gs \xf6n %(date)s Lorem ips#") + ) + for (source, expected) in test_cases: + result = self.converter.convert(source) + self.assertEquals(result, expected) + + def test_singular(self): + entry = POEntry() + entry.msgid = 'A lovely day for a cup of tea.' + expected = u'\xc0 l\xf6v\xe9ly d\xe4y f\xf6r \xe4 \xe7\xfcp \xf6f t\xe9\xe4. Lorem i#' + self.converter.convert_msg(entry) + self.assertEquals(entry.msgstr, expected) + + def test_plural(self): + entry = POEntry() + entry.msgid = 'A lovely day for a cup of tea.' + entry.msgid_plural = 'A lovely day for some cups of tea.' + expected_s = u'\xc0 l\xf6v\xe9ly d\xe4y f\xf6r \xe4 \xe7\xfcp \xf6f t\xe9\xe4. Lorem i#' + expected_p = u'\xc0 l\xf6v\xe9ly d\xe4y f\xf6r s\xf6m\xe9 \xe7\xfcps \xf6f t\xe9\xe4. Lorem ip#' + self.converter.convert_msg(entry) + result = entry.msgstr_plural + self.assertEquals(result['0'], expected_s) + self.assertEquals(result['1'], expected_p)