summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPavel Zuna <pzuna@redhat.com>2011-02-15 15:20:51 -0500
committerRob Crittenden <rcritten@redhat.com>2011-03-01 10:31:41 -0500
commit18dda28c563770730837e2b771a0acdc2e849158 (patch)
tree4d1514697c90de0de5876f23123c7a7b6c8fbedb /tests
parentf3de95ce99855cb15e26d8007c8901aaec96c595 (diff)
downloadfreeipa-18dda28c563770730837e2b771a0acdc2e849158.tar.gz
freeipa-18dda28c563770730837e2b771a0acdc2e849158.tar.xz
freeipa-18dda28c563770730837e2b771a0acdc2e849158.zip
Fix i18n related failures in unit tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_ipalib/test_errors.py30
-rw-r--r--tests/test_ipalib/test_frontend.py2
-rw-r--r--tests/test_ipalib/test_parameters.py44
-rw-r--r--tests/test_ipalib/test_plugable.py7
-rw-r--r--tests/test_ipalib/test_text.py3
5 files changed, 29 insertions, 57 deletions
diff --git a/tests/test_ipalib/test_errors.py b/tests/test_ipalib/test_errors.py
index b65c58705..2fcdc56c8 100644
--- a/tests/test_ipalib/test_errors.py
+++ b/tests/test_ipalib/test_errors.py
@@ -23,8 +23,8 @@ Test the `ipalib.errors` module.
import re
import inspect
-from tests.util import assert_equal, raises, dummy_ugettext
-from ipalib import errors, request
+from tests.util import assert_equal, raises
+from ipalib import errors, text
from ipalib.constants import TYPE_ERROR
@@ -229,7 +229,6 @@ class test_PublicError(PublicExceptionTester):
"""
Test the `ipalib.errors.PublicError.__init__` method.
"""
- context = request.context
message = u'The translated, interpolated message'
format = 'key=%(key1)r and key2=%(key2)r'
uformat = u'Translated key=%(key1)r and key2=%(key2)r'
@@ -237,25 +236,16 @@ class test_PublicError(PublicExceptionTester):
val2 = 'Value 2'
kw = dict(key1=val1, key2=val2)
- assert not hasattr(context, 'ugettext')
-
# Test with format=str, message=None
- dummy = dummy_ugettext(uformat)
- context.ugettext = dummy
inst = self.klass(format, **kw)
- assert dummy.message is format # Means ugettext() called
assert inst.format is format
assert_equal(inst.message, format % kw)
- assert_equal(inst.strerror, uformat % kw)
assert inst.forwarded is False
assert inst.key1 is val1
assert inst.key2 is val2
# Test with format=None, message=unicode
- dummy = dummy_ugettext(uformat)
- context.ugettext = dummy
inst = self.klass(message=message, **kw)
- assert not hasattr(dummy, 'message') # Means ugettext() not called
assert inst.format is None
assert inst.message is message
assert inst.strerror is message
@@ -277,24 +267,17 @@ class test_PublicError(PublicExceptionTester):
# Test via PublicExceptionTester.new()
# Test with format=str, message=None
- dummy = dummy_ugettext(uformat)
- context.ugettext = dummy
inst = self.new(format, **kw)
assert isinstance(inst, self.klass)
- assert dummy.message is format # Means ugettext() called
assert inst.format is format
assert_equal(inst.message, format % kw)
- assert_equal(inst.strerror, uformat % kw)
assert inst.forwarded is False
assert inst.key1 is val1
assert inst.key2 is val2
# Test with format=None, message=unicode
- dummy = dummy_ugettext(uformat)
- context.ugettext = dummy
inst = self.new(message=message, **kw)
assert isinstance(inst, self.klass)
- assert not hasattr(dummy, 'message') # Means ugettext() not called
assert inst.format is None
assert inst.message is message
assert inst.strerror is message
@@ -311,9 +294,6 @@ class test_PublicError(PublicExceptionTester):
uformat = u'Translated %(true)r %(text)r %(number)r'
kw = dict(true=True, text='Hello!', number=18)
- dummy = dummy_ugettext(uformat)
- context.ugettext = dummy
-
# Test with format=str, message=None
e = raises(ValueError, subclass, format, **kw)
assert str(e) == 'non-generic %r needs format=None; got format=%r' % (
@@ -321,20 +301,15 @@ class test_PublicError(PublicExceptionTester):
# Test with format=None, message=None:
inst = subclass(**kw)
- assert dummy.message is subclass.format # Means ugettext() called
assert inst.format is subclass.format
assert_equal(inst.message, subclass.format % kw)
- assert_equal(inst.strerror, uformat % kw)
assert inst.forwarded is False
assert inst.true is True
assert inst.text is kw['text']
assert inst.number is kw['number']
# Test with format=None, message=unicode:
- dummy = dummy_ugettext(uformat)
- context.ugettext = dummy
inst = subclass(message=message, **kw)
- assert not hasattr(dummy, 'message') # Means ugettext() not called
assert inst.format is subclass.format
assert inst.message is message
assert inst.strerror is message
@@ -342,7 +317,6 @@ class test_PublicError(PublicExceptionTester):
assert inst.true is True
assert inst.text is kw['text']
assert inst.number is kw['number']
- del context.ugettext
def test_public_errors():
diff --git a/tests/test_ipalib/test_frontend.py b/tests/test_ipalib/test_frontend.py
index 200dfe0a9..7381d9ad8 100644
--- a/tests/test_ipalib/test_frontend.py
+++ b/tests/test_ipalib/test_frontend.py
@@ -1091,4 +1091,4 @@ class test_Property(ClassChecker):
param = o.param
assert isinstance(param, parameters.Str)
assert param.name == 'givenname'
- assert param.doc == 'User first name'
+ assert unicode(param.doc) == u'User first name'
diff --git a/tests/test_ipalib/test_parameters.py b/tests/test_ipalib/test_parameters.py
index ffdc864b6..9e840176f 100644
--- a/tests/test_ipalib/test_parameters.py
+++ b/tests/test_ipalib/test_parameters.py
@@ -29,7 +29,7 @@ from inspect import isclass
from tests.util import raises, ClassChecker, read_only
from tests.util import dummy_ugettext, assert_equal
from tests.data import binary_bytes, utf8_bytes, unicode_str
-from ipalib import parameters, request, errors, config
+from ipalib import parameters, text, errors, config
from ipalib.constants import TYPE_ERROR, CALLABLE_ERROR, NULLS
from ipalib.errors import ValidationError
from ipalib import _
@@ -482,8 +482,8 @@ class test_Param(ClassChecker):
o = Example('example', pass1, pass2)
assert o.multivalue is False
assert o.validate(11, 'cli') is None
- assert pass1.calls == [(request.ugettext, 11)]
- assert pass2.calls == [(request.ugettext, 11)]
+ assert pass1.calls == [(text.ugettext, 11)]
+ assert pass2.calls == [(text.ugettext, 11)]
pass1.reset()
pass2.reset()
o = Example('example', pass1, pass2, fail)
@@ -491,9 +491,9 @@ class test_Param(ClassChecker):
assert e.name == 'example'
assert e.error == u'no good'
assert e.index is None
- assert pass1.calls == [(request.ugettext, 42)]
- assert pass2.calls == [(request.ugettext, 42)]
- assert fail.calls == [(request.ugettext, 42)]
+ assert pass1.calls == [(text.ugettext, 42)]
+ assert pass2.calls == [(text.ugettext, 42)]
+ assert fail.calls == [(text.ugettext, 42)]
# Test with some rules and multivalue=True
pass1 = DummyRule()
@@ -503,12 +503,12 @@ class test_Param(ClassChecker):
assert o.multivalue is True
assert o.validate((3, 9), 'cli') is None
assert pass1.calls == [
- (request.ugettext, 3),
- (request.ugettext, 9),
+ (text.ugettext, 3),
+ (text.ugettext, 9),
]
assert pass2.calls == [
- (request.ugettext, 3),
- (request.ugettext, 9),
+ (text.ugettext, 3),
+ (text.ugettext, 9),
]
pass1.reset()
pass2.reset()
@@ -518,9 +518,9 @@ class test_Param(ClassChecker):
assert e.name == 'multi_example'
assert e.error == u'this one is not good'
assert e.index == 0
- assert pass1.calls == [(request.ugettext, 3)]
- assert pass2.calls == [(request.ugettext, 3)]
- assert fail.calls == [(request.ugettext, 3)]
+ assert pass1.calls == [(text.ugettext, 3)]
+ assert pass2.calls == [(text.ugettext, 3)]
+ assert fail.calls == [(text.ugettext, 3)]
def test_validate_scalar(self):
"""
@@ -543,8 +543,8 @@ class test_Param(ClassChecker):
assert o._validate_scalar(True, index=None) is None
assert o._validate_scalar(False, index=None) is None
assert okay.calls == [
- (request.ugettext, True),
- (request.ugettext, False),
+ (text.ugettext, True),
+ (text.ugettext, False),
]
# Test with a failing rule:
@@ -560,12 +560,12 @@ class test_Param(ClassChecker):
assert e.error == u'this describes the error'
assert e.index == 2
assert okay.calls == [
- (request.ugettext, True),
- (request.ugettext, False),
+ (text.ugettext, True),
+ (text.ugettext, False),
]
assert fail.calls == [
- (request.ugettext, True),
- (request.ugettext, False),
+ (text.ugettext, True),
+ (text.ugettext, False),
]
def test_get_default(self):
@@ -927,17 +927,17 @@ class test_Str(ClassChecker):
e = raises(errors.ConversionError, mthd, value)
assert e.name == 'my_str'
assert e.index is None
- assert_equal(e.error, u'must be Unicode text')
+ assert_equal(unicode(e.error), u'must be Unicode text')
e = raises(errors.ConversionError, mthd, value, index=18)
assert e.name == 'my_str'
assert e.index == 18
- assert_equal(e.error, u'must be Unicode text')
+ assert_equal(unicode(e.error), u'must be Unicode text')
bad = [(u'Hello',), [42.3]]
for value in bad:
e = raises(errors.ConversionError, mthd, value)
assert e.name == 'my_str'
assert e.index is None
- assert_equal(e.error, u'Only one value is allowed')
+ assert_equal(unicode(e.error), u'Only one value is allowed')
assert o.convert(None) is None
def test_rule_minlength(self):
diff --git a/tests/test_ipalib/test_plugable.py b/tests/test_ipalib/test_plugable.py
index 147bff702..23b733096 100644
--- a/tests/test_ipalib/test_plugable.py
+++ b/tests/test_ipalib/test_plugable.py
@@ -25,7 +25,7 @@ import inspect
from tests.util import raises, no_set, no_del, read_only
from tests.util import getitem, setitem, delitem
from tests.util import ClassChecker, create_test_api
-from ipalib import plugable, errors
+from ipalib import plugable, errors, text
class test_SetProxy(ClassChecker):
@@ -219,7 +219,7 @@ class test_Plugin(ClassChecker):
assert o.name == 'Plugin'
assert o.module == 'ipalib.plugable'
assert o.fullname == 'ipalib.plugable.Plugin'
- assert o.doc == inspect.getdoc(self.cls)
+ assert isinstance(o.doc, text.Gettext)
class some_subclass(self.cls):
"""
Do sub-classy things.
@@ -234,12 +234,11 @@ class test_Plugin(ClassChecker):
assert o.name == 'some_subclass'
assert o.module == __name__
assert o.fullname == '%s.some_subclass' % __name__
- assert o.doc == inspect.getdoc(some_subclass)
assert o.summary == 'Do sub-classy things.'
+ assert isinstance(o.doc, text.Gettext)
class another_subclass(self.cls):
pass
o = another_subclass()
- assert o.doc is None
assert o.summary == '<%s>' % o.fullname
# Test that Plugin makes sure the subclass hasn't defined attributes
diff --git a/tests/test_ipalib/test_text.py b/tests/test_ipalib/test_text.py
index 5ffcb8b82..67fd0172a 100644
--- a/tests/test_ipalib/test_text.py
+++ b/tests/test_ipalib/test_text.py
@@ -80,7 +80,7 @@ def test_gettext():
# language not associated with any real language, but the
# setlocale function demands the locale be a valid known locale,
# U.S. English is a reasonable choice.
- request.set_languages('en_US.UTF-8')
+ # request.set_languages('en_US.UTF-8')
# Tell gettext that our domain is 'ipa', that locale_dir is
# 'test_locale' (i.e. where to look for the message catalog)
@@ -117,7 +117,6 @@ def test_gettext():
# Reset the language and assure we don't get the test values
context.__dict__.clear()
- request.set_languages('fr_FR')
translated = unicode(localized)
assert(translated[0] != prefix)