diff --git a/i18n/tests/test_converter.py b/i18n/tests/test_converter.py
index f2fec593d4..e893f7c258 100644
--- a/i18n/tests/test_converter.py
+++ b/i18n/tests/test_converter.py
@@ -1,5 +1,8 @@
+"""Tests of i18n/converter.py"""
+
import os
from unittest import TestCase
+import ddt
import converter
@@ -11,39 +14,48 @@ class UpcaseConverter(converter.Converter):
return string.upper()
+@ddt.ddt
class TestConverter(TestCase):
"""
Tests functionality of i18n/converter.py
"""
- def test_converter(self):
+ @ddt.data(
+ # no tags
+ ('big bad wolf',
+ 'BIG BAD WOLF'),
+ # one html tag
+ ('big bad wolf',
+ 'BIG BAD WOLF'),
+ # two html tags
+ ('big bad gray wolf',
+ 'BIG BAD GRAY WOLF'),
+ # html tags with attributes
+ ('bar baz',
+ 'BAR BAZ'),
+ ("bar baz",
+ "BAR BAZ"),
+ # one python tag
+ ('big %(adjective)s wolf',
+ 'BIG %(adjective)s WOLF'),
+ # two python tags
+ ('big %(adjective)s gray %(noun)s',
+ 'BIG %(adjective)s GRAY %(noun)s'),
+ # both kinds of tags
+ ('big %(adjective)s %(noun)s',
+ 'BIG %(adjective)s %(noun)s'),
+ # .format-style tags
+ ('The {0} barn is {1!r}.',
+ 'THE {0} BARN IS {1!r}.'),
+ # HTML entities
+ ('© 2013 edX, ',
+ '© 2013 EDX, '),
+ )
+ def test_converter(self, data):
"""
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'),
- # html tags with attributes
- ('bar baz', 'BAR BAZ'),
- ("bar baz", "BAR BAZ"),
- # 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'),
- # .format-style tags
- ('The {0} barn is {1!r}.', 'THE {0} BARN IS {1!r}.'),
- # HTML entities
- ('© 2013 edX, ', '© 2013 EDX, '),
- ]
- for source, expected in test_cases:
- result = c.convert(source)
- self.assertEquals(result, expected)
+ source, expected = data
+ result = UpcaseConverter().convert(source)
+ self.assertEquals(result, expected)
diff --git a/i18n/tests/test_dummy.py b/i18n/tests/test_dummy.py
index fbef3910ab..2d1b1b71c3 100644
--- a/i18n/tests/test_dummy.py
+++ b/i18n/tests/test_dummy.py
@@ -1,11 +1,16 @@
# -*- coding: utf-8 -*-
+"""Tests of i18n/dummy.py"""
+
import os, string, random
from unittest import TestCase
+
+import ddt
from polib import POEntry
import dummy
+@ddt.ddt
class TestDummy(TestCase):
"""
Tests functionality of i18n/dummy.py
@@ -27,24 +32,24 @@ class TestDummy(TestCase):
"Mismatch: %r != %r" % (str1, str2),
)
- def test_dummy(self):
+ @ddt.data(
+ (u"hello my name is Bond, James Bond",
+ u"héllø mý nämé ïs Bønd, Jämés Bønd Ⱡσяєм ι#"),
+
+ (u"don't convert tag ids",
+ u"døn't çønvért täg ïds Ⱡσяєм ιρѕυ#"),
+
+ (u"don't convert %(name)s tags on %(date)s",
+ u"døn't çønvért %(name)s tägs øn %(date)s Ⱡσяєм ιρѕ#"),
+ )
+ def test_dummy(self, data):
"""
Tests with a dummy converter (adds spurious accents to strings).
Assert that embedded HTML and python tags are not converted.
"""
- test_cases = [
- (u"hello my name is Bond, James Bond",
- u"héllø mý nämé ïs Bønd, Jämés Bønd Ⱡσяєм ι#"),
-
- (u"don't convert tag ids",
- u"døn't çønvért täg ïds Ⱡσяєм ιρѕυ#"),
-
- (u"don't convert %(name)s tags on %(date)s",
- u"døn't çønvért %(name)s tägs øn %(date)s Ⱡσяєм ιρѕ#"),
- ]
- for source, expected in test_cases:
- result = self.converter.convert(source)
- self.assertUnicodeEquals(result, expected)
+ source, expected = data
+ result = self.converter.convert(source)
+ self.assertUnicodeEquals(result, expected)
def test_singular(self):
entry = POEntry()