Imported Upstream version 4.0.5
This commit is contained in:
@@ -21,20 +21,11 @@
|
||||
Test the `ipalib.base` module.
|
||||
"""
|
||||
|
||||
import six
|
||||
import pytest
|
||||
|
||||
from ipatests.util import ClassChecker, raises
|
||||
from ipalib.constants import NAME_REGEX, NAME_ERROR
|
||||
from ipalib.constants import TYPE_ERROR, SET_ERROR, DEL_ERROR, OVERRIDE_ERROR
|
||||
from ipalib import base
|
||||
|
||||
if six.PY3:
|
||||
unicode = str
|
||||
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
|
||||
class test_ReadOnly(ClassChecker):
|
||||
"""
|
||||
@@ -187,14 +178,8 @@ def test_check_name():
|
||||
]
|
||||
for name in okay:
|
||||
assert name is f(name)
|
||||
if six.PY2:
|
||||
bad_type = unicode
|
||||
bad_value = unicode(name)
|
||||
else:
|
||||
bad_type = bytes
|
||||
bad_value = name.encode('ascii')
|
||||
e = raises(TypeError, f, bad_value)
|
||||
assert str(e) == TYPE_ERROR % ('name', str, bad_value, bad_type)
|
||||
e = raises(TypeError, f, unicode(name))
|
||||
assert str(e) == TYPE_ERROR % ('name', str, unicode(name), unicode)
|
||||
for name in nope:
|
||||
e = raises(ValueError, f, name)
|
||||
assert str(e) == NAME_ERROR % (NAME_REGEX, name)
|
||||
@@ -224,7 +209,7 @@ class test_NameSpace(ClassChecker):
|
||||
_cls = base.NameSpace
|
||||
|
||||
def new(self, count, sort=True):
|
||||
members = tuple(DummyMember(i) for i in range(count, 0, -1))
|
||||
members = tuple(DummyMember(i) for i in xrange(count, 0, -1))
|
||||
assert len(members) == count
|
||||
o = self.cls(members, sort=sort)
|
||||
return (o, members)
|
||||
@@ -263,9 +248,9 @@ class test_NameSpace(ClassChecker):
|
||||
Test the `ipalib.base.NameSpace.__len__` method.
|
||||
"""
|
||||
for count in (5, 18, 127):
|
||||
o, _members = self.new(count)
|
||||
(o, members) = self.new(count)
|
||||
assert len(o) == count
|
||||
o, _members = self.new(count, sort=False)
|
||||
(o, members) = self.new(count, sort=False)
|
||||
assert len(o) == count
|
||||
|
||||
def test_iter(self):
|
||||
@@ -320,12 +305,12 @@ class test_NameSpace(ClassChecker):
|
||||
e = raises(KeyError, o.__getitem__, 'nope')
|
||||
|
||||
# Test int indexes:
|
||||
for i in range(cnt):
|
||||
for i in xrange(cnt):
|
||||
assert o[i] is members[i]
|
||||
e = raises(IndexError, o.__getitem__, cnt)
|
||||
|
||||
# Test negative int indexes:
|
||||
for i in range(1, cnt + 1):
|
||||
for i in xrange(1, cnt + 1):
|
||||
assert o[-i] is members[-i]
|
||||
e = raises(IndexError, o.__getitem__, -(cnt + 1))
|
||||
|
||||
@@ -353,7 +338,7 @@ class test_NameSpace(ClassChecker):
|
||||
"""
|
||||
for cnt in (0, 1, 2):
|
||||
for sort in (True, False):
|
||||
o, _members = self.new(cnt, sort=sort)
|
||||
(o, members) = self.new(cnt, sort=sort)
|
||||
if cnt == 1:
|
||||
assert repr(o) == \
|
||||
'NameSpace(<%d member>, sort=%r)' % (cnt, sort)
|
||||
|
||||
Reference in New Issue
Block a user