From 8f57f25e82f64e338b4cec1fb58fa27f3d432f8f Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Thu, 11 Apr 2013 12:27:25 +0200 Subject: Add ConcatenatedLazyText object This object will allow splitting large translatable strings into more pieces, so translators don't have to re-translate the entire text when a small part changes. https://fedorahosted.org/freeipa/ticket/3587 --- ipatests/test_ipalib/test_text.py | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'ipatests/test_ipalib') diff --git a/ipatests/test_ipalib/test_text.py b/ipatests/test_ipalib/test_text.py index 2a5ff7a36..4d4ce35c8 100644 --- a/ipatests/test_ipalib/test_text.py +++ b/ipatests/test_ipalib/test_text.py @@ -332,3 +332,49 @@ class test_NGettextFactory(object): assert ng.plural is plural assert ng.domain == 'foo' assert ng.localedir == 'bar' + + +class test_ConcatenatedText(object): + + klass = text.ConcatenatedLazyText + + def test_init(self): + lst = ['a', 'b', 'c', 3] + inst = self.klass(*lst) + assert inst.components == lst + assert unicode(inst) == 'abc3' + + def test_repr(self): + lazytext = text.Gettext('foo', 'bar', 'baz') + inst = self.klass(lazytext) + assert repr(inst) == "ConcatenatedLazyText([%r])" % lazytext + + def test_unicode(self): + inst = self.klass('[', text.Gettext('green', 'foo', 'bar'), 1, ']') + assert unicode(inst) == u'[green1]' + + def test_mod(self): + inst = self.klass('[', text.Gettext('%(color)s', 'foo', 'bar'), ']') + assert inst % dict(color='red', stuff='junk') == '[red]' + + def test_add(self): + inst = (text.Gettext('pale ', 'foo', 'bar') + + text.Gettext('blue', 'foo', 'bar')) + assert unicode(inst) == 'pale blue' + + inst = (text.Gettext('bright ', 'foo', 'bar') + + text.Gettext('pale ', 'foo', 'bar') + + text.Gettext('blue', 'foo', 'bar')) + assert unicode(inst) == 'bright pale blue' + + inst = text.Gettext('yellow', 'foo', 'bar') + '!' + assert unicode(inst) == 'yellow!' + + inst = '!' + text.Gettext('yellow', 'foo', 'bar') + assert unicode(inst) == '!yellow' + + inst = '!' + ('!' + text.Gettext('yellow', 'foo', 'bar')) + assert unicode(inst) == '!!yellow' + + inst = (text.Gettext('yellow', 'foo', 'bar') + '!') + '!' + assert unicode(inst) == 'yellow!!' -- cgit