259: Option.__normalize_scalar() now raises a TypeError if not isinstance(value, basestring); updated corresponding unit tests

This commit is contained in:
Jason Gerard DeRose 2008-09-04 07:47:07 +00:00
parent 71d36aa6a0
commit c7cd694d4f
2 changed files with 8 additions and 8 deletions

View File

@ -125,8 +125,8 @@ class Option(plugable.ReadOnly):
return self.__convert_scalar(value) return self.__convert_scalar(value)
def __normalize_scalar(self, value): def __normalize_scalar(self, value):
if type(value) is not self.type.type: if not isinstance(value, basestring):
raise_TypeError(value, self.type.type, 'value') raise_TypeError(value, basestring, 'value')
return self.__normalize(value) return self.__normalize(value)
def normalize(self, value): def normalize(self, value):

View File

@ -202,10 +202,10 @@ class test_Option(ClassChecker):
# Scenario 2: multivalue=False, normalize=callback # Scenario 2: multivalue=False, normalize=callback
o = self.cls(name, doc, t, normalize=callback) o = self.cls(name, doc, t, normalize=callback)
for v in (u'Hello', u'hello'): # Okay for v in (u'Hello', u'hello', 'Hello'): # Okay
assert o.normalize(v) == u'hello' assert o.normalize(v) == 'hello'
for v in [None, 'hello', (u'Hello',)]: # Not unicode for v in [None, 42, (u'Hello',)]: # Not basestring
check_TypeError(v, unicode, 'value', o.normalize, v) check_TypeError(v, basestring, 'value', o.normalize, v)
# Scenario 3: multivalue=True, normalize=None # Scenario 3: multivalue=True, normalize=None
o = self.cls(name, doc, t, multivalue=True) o = self.cls(name, doc, t, multivalue=True)
@ -219,9 +219,9 @@ class test_Option(ClassChecker):
assert o.normalize(value) == (u'hello',) assert o.normalize(value) == (u'hello',)
for v in (None, u'Hello', [u'hello']): # Not tuple for v in (None, u'Hello', [u'hello']): # Not tuple
check_TypeError(v, tuple, 'value', o.normalize, v) check_TypeError(v, tuple, 'value', o.normalize, v)
fail = 'Hello' # Not unicode fail = 42 # Not basestring
for v in [(fail,), (u'Hello', fail)]: # Non unicode member for v in [(fail,), (u'Hello', fail)]: # Non unicode member
check_TypeError(fail, unicode, 'value', o.normalize, v) check_TypeError(fail, basestring, 'value', o.normalize, v)
def test_validate(self): def test_validate(self):
""" """