summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2010-03-08 20:42:26 -0700
committerJason Gerard DeRose <jderose@redhat.com>2010-03-16 11:41:22 -0600
commitc350f841342675440837740f9df1c582e499da25 (patch)
treee614cbb9ce6d59d00b618ae3b01211458451bdf0 /tests
parenta0a94a9a04d87133e57ce958f720131230746ec9 (diff)
downloadfreeipa-c350f841342675440837740f9df1c582e499da25.tar.gz
freeipa-c350f841342675440837740f9df1c582e499da25.tar.xz
freeipa-c350f841342675440837740f9df1c582e499da25.zip
Finish deferred translation mechanism
Diffstat (limited to 'tests')
-rw-r--r--tests/test_ipalib/test_text.py135
-rw-r--r--tests/util.py6
2 files changed, 126 insertions, 15 deletions
diff --git a/tests/test_ipalib/test_text.py b/tests/test_ipalib/test_text.py
index dc5d02f8b..ee7a1b32f 100644
--- a/tests/test_ipalib/test_text.py
+++ b/tests/test_ipalib/test_text.py
@@ -22,13 +22,20 @@ Test the `ipalib.text` module.
"""
from tests.util import raises, assert_equal
-from tests.data import utf8_bytes, unicode_str
+from ipalib.request import context
from ipalib import text
singular = '%(count)d goose makes a %(dish)s'
plural = '%(count)d geese make a %(dish)s'
+def test_create_translation():
+ f = text.create_translation
+ key = ('foo', None)
+ t = f(key)
+ assert context.__dict__[key] is t
+
+
class test_LazyText(object):
klass = text.LazyText
@@ -37,6 +44,7 @@ class test_LazyText(object):
inst = self.klass('foo', 'bar')
assert inst.domain == 'foo'
assert inst.localedir == 'bar'
+ assert inst.key == ('foo', 'bar')
class test_FixMe(object):
@@ -63,19 +71,56 @@ class test_Gettext(object):
klass = text.Gettext
def test_init(self):
- inst = self.klass(utf8_bytes, 'foo', 'bar')
+ inst = self.klass('what up?', 'foo', 'bar')
assert inst.domain == 'foo'
assert inst.localedir == 'bar'
- assert inst.msg is utf8_bytes
+ assert inst.msg is 'what up?'
+ assert inst.args == ('what up?', 'foo', 'bar')
+
+ def test_repr(self):
+ inst = self.klass('foo', 'bar', 'baz')
+ assert repr(inst) == "Gettext('foo', domain='bar', localedir='baz')"
def test_unicode(self):
- inst = self.klass(utf8_bytes, 'foo', 'bar')
- assert unicode(inst) == unicode_str
+ inst = self.klass('what up?', 'foo', 'bar')
+ assert unicode(inst) == u'what up?'
def test_mod(self):
inst = self.klass('hello %(adj)s nurse', 'foo', 'bar')
assert inst % dict(adj='naughty', stuff='junk') == 'hello naughty nurse'
+ def test_eq(self):
+ inst1 = self.klass('what up?', 'foo', 'bar')
+ inst2 = self.klass('what up?', 'foo', 'bar')
+ inst3 = self.klass('Hello world', 'foo', 'bar')
+ inst4 = self.klass('what up?', 'foo', 'baz')
+
+ assert (inst1 == inst1) is True
+ assert (inst1 == inst2) is True
+ assert (inst1 == inst3) is False
+ assert (inst1 == inst4) is False
+
+ # Test with args flipped
+ assert (inst2 == inst1) is True
+ assert (inst3 == inst1) is False
+ assert (inst4 == inst1) is False
+
+ def test_ne(self):
+ inst1 = self.klass('what up?', 'foo', 'bar')
+ inst2 = self.klass('what up?', 'foo', 'bar')
+ inst3 = self.klass('Hello world', 'foo', 'bar')
+ inst4 = self.klass('what up?', 'foo', 'baz')
+
+ assert (inst1 != inst2) is False
+ assert (inst1 != inst2) is False
+ assert (inst1 != inst3) is True
+ assert (inst1 != inst4) is True
+
+ # Test with args flipped
+ assert (inst2 != inst1) is False
+ assert (inst3 != inst1) is True
+ assert (inst4 != inst1) is True
+
class test_NGettext(object):
@@ -87,6 +132,12 @@ class test_NGettext(object):
assert inst.plural is plural
assert inst.domain == 'foo'
assert inst.localedir == 'bar'
+ assert inst.args == (singular, plural, 'foo', 'bar')
+
+ def test_repr(self):
+ inst = self.klass('sig', 'plu', 'foo', 'bar')
+ assert repr(inst) == \
+ "NGettext('sig', 'plu', domain='foo', localedir='bar')"
def test_call(self):
inst = self.klass(singular, plural, 'foo', 'bar')
@@ -101,34 +152,96 @@ class test_NGettext(object):
assert inst % dict(count=1, dish='stew') == '1 goose makes a stew'
assert inst % dict(count=2, dish='pie') == '2 geese make a pie'
+ def test_eq(self):
+ inst1 = self.klass(singular, plural, 'foo', 'bar')
+ inst2 = self.klass(singular, plural, 'foo', 'bar')
+ inst3 = self.klass(singular, '%(count)d thingies', 'foo', 'bar')
+ inst4 = self.klass(singular, plural, 'foo', 'baz')
+
+ assert (inst1 == inst1) is True
+ assert (inst1 == inst2) is True
+ assert (inst1 == inst3) is False
+ assert (inst1 == inst4) is False
+
+ # Test with args flipped
+ assert (inst2 == inst1) is True
+ assert (inst3 == inst1) is False
+ assert (inst4 == inst1) is False
+
+ def test_ne(self):
+ inst1 = self.klass(singular, plural, 'foo', 'bar')
+ inst2 = self.klass(singular, plural, 'foo', 'bar')
+ inst3 = self.klass(singular, '%(count)d thingies', 'foo', 'bar')
+ inst4 = self.klass(singular, plural, 'foo', 'baz')
-class test_gettext_factory(object):
+ assert (inst1 != inst2) is False
+ assert (inst1 != inst2) is False
+ assert (inst1 != inst3) is True
+ assert (inst1 != inst4) is True
- klass = text.gettext_factory
+ # Test with args flipped
+ assert (inst2 != inst1) is False
+ assert (inst3 != inst1) is True
+ assert (inst4 != inst1) is True
+
+
+class test_GettextFactory(object):
+
+ klass = text.GettextFactory
def test_init(self):
+ # Test with defaults:
+ inst = self.klass()
+ assert inst.domain == 'ipa'
+ assert inst.localedir is None
+
+ # Test with overrides:
inst = self.klass('foo', 'bar')
assert inst.domain == 'foo'
assert inst.localedir == 'bar'
+ def test_repr(self):
+ # Test with defaults:
+ inst = self.klass()
+ assert repr(inst) == "GettextFactory(domain='ipa', localedir=None)"
+
+ # Test with overrides:
+ inst = self.klass('foo', 'bar')
+ assert repr(inst) == "GettextFactory(domain='foo', localedir='bar')"
+
def test_call(self):
inst = self.klass('foo', 'bar')
- g = inst(utf8_bytes)
+ g = inst('what up?')
assert type(g) is text.Gettext
- assert g.msg is utf8_bytes
+ assert g.msg is 'what up?'
assert g.domain == 'foo'
assert g.localedir == 'bar'
-class test_ngettext_factory(object):
+class test_NGettextFactory(object):
- klass = text.ngettext_factory
+ klass = text.NGettextFactory
def test_init(self):
+ # Test with defaults:
+ inst = self.klass()
+ assert inst.domain == 'ipa'
+ assert inst.localedir is None
+
+ # Test with overrides:
inst = self.klass('foo', 'bar')
assert inst.domain == 'foo'
assert inst.localedir == 'bar'
+ def test_repr(self):
+ # Test with defaults:
+ inst = self.klass()
+ assert repr(inst) == "NGettextFactory(domain='ipa', localedir=None)"
+
+ # Test with overrides:
+ inst = self.klass('foo', 'bar')
+ assert repr(inst) == "NGettextFactory(domain='foo', localedir='bar')"
+
def test_call(self):
inst = self.klass('foo', 'bar')
ng = inst(singular, plural, 7)
diff --git a/tests/util.py b/tests/util.py
index f3215e7d7..c22167a30 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -417,8 +417,7 @@ class ClassChecker(object):
"""
nose tear-down fixture.
"""
- for name in context.__dict__.keys():
- delattr(context, name)
+ context.__dict__.clear()
@@ -509,8 +508,7 @@ class PluginTester(object):
"""
nose tear-down fixture.
"""
- for name in context.__dict__.keys():
- delattr(context, name)
+ context.__dict__.clear()
class dummy_ugettext(object):