206: Finished unit tests for Unicode.__init__()

This commit is contained in:
Jason Gerard DeRose 2008-08-27 22:56:51 +00:00
parent 2984041d00
commit 8fbc01ca86

View File

@ -188,3 +188,34 @@ class test_Unicode(ClassChecker):
kw = {key: value}
e = raises(ValueError, self.cls, **kw)
assert str(e) == '%s must be >= %d, got: %d' % (key, lower, value)
# Test pattern:
okay = [
'(hello|world)',
u'(take the blue pill|take the red pill)',
]
for value in okay:
o = self.cls(pattern=value)
assert o.pattern is value
assert o.regex is not None
fail = [
42,
True,
False,
object,
]
for value in fail:
e = raises(TypeError, self.cls, pattern=value)
assert str(e) == (
'pattern must be a basestring or None, got: %r' % value
)
# Test regex:
pat = '^(hello|world)$'
o = self.cls(pattern=pat)
for value in ('hello', 'world'):
m = o.regex.match(value)
assert m.group(1) == value
for value in ('hello beautiful', 'world!'):
assert o.regex.match(value) is None