Commit d8df97aa by Ned Batchelder

Use ddt to separate test cases into tests.

parent 209f8cc3
"""Tests of i18n/converter.py"""
import os import os
from unittest import TestCase from unittest import TestCase
import ddt
import converter import converter
...@@ -11,39 +14,48 @@ class UpcaseConverter(converter.Converter): ...@@ -11,39 +14,48 @@ class UpcaseConverter(converter.Converter):
return string.upper() return string.upper()
@ddt.ddt
class TestConverter(TestCase): class TestConverter(TestCase):
""" """
Tests functionality of i18n/converter.py Tests functionality of i18n/converter.py
""" """
def test_converter(self): @ddt.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 # no tags
('big bad wolf', 'BIG BAD WOLF'), ('big bad wolf',
'BIG BAD WOLF'),
# one html tag # one html tag
('big <strong>bad</strong> wolf', 'BIG <strong>BAD</strong> WOLF'), ('big <strong>bad</strong> wolf',
'BIG <strong>BAD</strong> WOLF'),
# two html tags # two html tags
('big <b>bad</b> <i>wolf</i>', 'BIG <b>BAD</b> <i>WOLF</i>'), ('big <b>bad</b> gray <i>wolf</i>',
'BIG <b>BAD</b> GRAY <i>WOLF</i>'),
# html tags with attributes # html tags with attributes
('<a href="foo">bar</a> baz', '<a href="foo">BAR</a> BAZ'), ('<a href="foo">bar</a> baz',
("<a href='foo'>bar</a> baz", "<a href='foo'>BAR</a> BAZ"), '<a href="foo">BAR</a> BAZ'),
("<a href='foo'>bar</a> baz",
"<a href='foo'>BAR</a> BAZ"),
# one python tag # one python tag
('big %(adjective)s wolf', 'BIG %(adjective)s WOLF'), ('big %(adjective)s wolf',
'BIG %(adjective)s WOLF'),
# two python tags # two python tags
('big %(adjective)s %(noun)s', 'BIG %(adjective)s %(noun)s'), ('big %(adjective)s gray %(noun)s',
'BIG %(adjective)s GRAY %(noun)s'),
# both kinds of tags # both kinds of tags
('<strong>big</strong> %(adjective)s %(noun)s', ('<strong>big</strong> %(adjective)s %(noun)s',
'<strong>BIG</strong> %(adjective)s %(noun)s'), '<strong>BIG</strong> %(adjective)s %(noun)s'),
# .format-style tags # .format-style tags
('The {0} barn is {1!r}.', 'THE {0} BARN IS {1!r}.'), ('The {0} barn is {1!r}.',
'THE {0} BARN IS {1!r}.'),
# HTML entities # HTML entities
('<b>&copy; 2013 edX, &#xa0;</b>', '<b>&copy; 2013 EDX, &#xa0;</b>'), ('<b>&copy; 2013 edX, &#xa0;</b>',
] '<b>&copy; 2013 EDX, &#xa0;</b>'),
for source, expected in test_cases: )
result = c.convert(source) def test_converter(self, data):
"""
Tests with a simple converter (converts strings to uppercase).
Assert that embedded HTML and python tags are not converted.
"""
source, expected = data
result = UpcaseConverter().convert(source)
self.assertEquals(result, expected) self.assertEquals(result, expected)
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Tests of i18n/dummy.py"""
import os, string, random import os, string, random
from unittest import TestCase from unittest import TestCase
import ddt
from polib import POEntry from polib import POEntry
import dummy import dummy
@ddt.ddt
class TestDummy(TestCase): class TestDummy(TestCase):
""" """
Tests functionality of i18n/dummy.py Tests functionality of i18n/dummy.py
...@@ -27,12 +32,7 @@ class TestDummy(TestCase): ...@@ -27,12 +32,7 @@ class TestDummy(TestCase):
"Mismatch: %r != %r" % (str1, str2), "Mismatch: %r != %r" % (str1, str2),
) )
def test_dummy(self): @ddt.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"hello my name is Bond, James Bond",
u"héllø mý nämé ïs Bønd, Jämés Bønd Ⱡσяєм ι#"), u"héllø mý nämé ïs Bønd, Jämés Bønd Ⱡσяєм ι#"),
...@@ -41,8 +41,13 @@ class TestDummy(TestCase): ...@@ -41,8 +41,13 @@ class TestDummy(TestCase):
(u"don't convert %(name)s tags on %(date)s", (u"don't convert %(name)s tags on %(date)s",
u"døn't çønvért %(name)s tägs øn %(date)s Ⱡσяєм ιρѕ#"), u"døn't çønvért %(name)s tägs øn %(date)s Ⱡσяєм ιρѕ#"),
] )
for source, expected in test_cases: 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.
"""
source, expected = data
result = self.converter.convert(source) result = self.converter.convert(source)
self.assertUnicodeEquals(result, expected) self.assertUnicodeEquals(result, expected)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment