Imported Debian patch 4.0.5-6~numeezy

This commit is contained in:
Alexandre Ellert
2016-02-17 15:07:45 +01:00
committed by Mario Fetka
parent c44de33144
commit 10dfc9587b
1203 changed files with 53869 additions and 241462 deletions

View File

@@ -21,26 +21,14 @@
Test the `ipalib.errors` module.
"""
# FIXME: Pylint errors
# pylint: disable=no-member
import re
import inspect
import pytest
import six
from ipatests.util import assert_equal, raises
from ipalib import errors, text
from ipaplatform.paths import paths
from ipalib.constants import TYPE_ERROR
if six.PY3:
unicode = str
pytestmark = pytest.mark.tier0
class PrivateExceptionTester(object):
_klass = None
@@ -49,21 +37,21 @@ class PrivateExceptionTester(object):
def __get_klass(self):
if self.__klass is None:
self.__klass = self._klass
assert issubclass(self.__klass, Exception)
assert issubclass(self.__klass, StandardError)
assert issubclass(self.__klass, errors.PrivateError)
assert not issubclass(self.__klass, errors.PublicError)
return self.__klass
klass = property(__get_klass)
def new(self, **kw):
for (key, value) in kw.items():
for (key, value) in kw.iteritems():
assert not hasattr(self.klass, key), key
inst = self.klass(**kw)
assert isinstance(inst, Exception)
assert isinstance(inst, StandardError)
assert isinstance(inst, errors.PrivateError)
assert isinstance(inst, self.klass)
assert not isinstance(inst, errors.PublicError)
for (key, value) in kw.items():
for (key, value) in kw.iteritems():
assert getattr(inst, key) is value
assert str(inst) == self.klass.format % kw
assert inst.message == str(inst)
@@ -207,7 +195,7 @@ class PublicExceptionTester(object):
def __get_klass(self):
if self.__klass is None:
self.__klass = self._klass
assert issubclass(self.__klass, Exception)
assert issubclass(self.__klass, StandardError)
assert issubclass(self.__klass, errors.PublicError)
assert not issubclass(self.__klass, errors.PrivateError)
assert type(self.__klass.errno) is int
@@ -217,18 +205,18 @@ class PublicExceptionTester(object):
def new(self, format=None, message=None, **kw):
# Test that TypeError is raised if message isn't unicode:
e = raises(TypeError, self.klass, message=b'The message')
assert str(e) == TYPE_ERROR % ('message', unicode, b'The message', bytes)
e = raises(TypeError, self.klass, message='The message')
assert str(e) == TYPE_ERROR % ('message', unicode, 'The message', str)
# Test the instance:
for (key, value) in kw.items():
for (key, value) in kw.iteritems():
assert not hasattr(self.klass, key), key
inst = self.klass(format=format, message=message, **kw)
for required_class in self.required_classes:
assert isinstance(inst, required_class)
assert isinstance(inst, self.klass)
assert not isinstance(inst, errors.PrivateError)
for (key, value) in kw.items():
for (key, value) in kw.iteritems():
assert getattr(inst, key) is value
return inst
@@ -238,7 +226,7 @@ class test_PublicError(PublicExceptionTester):
Test the `ipalib.errors.PublicError` exception.
"""
_klass = errors.PublicError
required_classes = Exception, errors.PublicError
required_classes = StandardError, errors.PublicError
def test_init(self):
message = u'The translated, interpolated message'
@@ -265,9 +253,9 @@ class test_PublicError(PublicExceptionTester):
assert inst.key1 is val1
assert inst.key2 is val2
# Test with format=None, message=bytes
e = raises(TypeError, self.klass, message=b'the message', **kw)
assert str(e) == TYPE_ERROR % ('message', unicode, b'the message', bytes)
# Test with format=None, message=str
e = raises(TypeError, self.klass, message='the message', **kw)
assert str(e) == TYPE_ERROR % ('message', unicode, 'the message', str)
# Test with format=None, message=None
e = raises(ValueError, self.klass, **kw)
@@ -338,7 +326,8 @@ class test_PublicError(PublicExceptionTester):
# this expression checks if each word of instructions
# exists in a string as a separate line, with right order
regexp = re.compile('(?ims).*' +
''.join('(%s).*' % (x) for x in instructions) +
''.join(map(lambda x: '(%s).*' % (x),
instructions)) +
'$')
inst = subclass(instructions=instructions, **kw)
assert inst.format is subclass.format
@@ -378,8 +367,8 @@ class BaseMessagesTest(object):
class test_PublicErrors(object):
message_list = errors.public_errors
errno_range = list(range(900, 5999))
required_classes = (Exception, errors.PublicError)
errno_range = xrange(900, 5999)
required_classes = (StandardError, errors.PublicError)
texts = errors._texts
def extratest(self, cls):