From 8fbc01ca864df332afe16ed51ea661ae88892d8b Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 27 Aug 2008 22:56:51 +0000 Subject: 206: Finished unit tests for Unicode.__init__() --- ipalib/tests/test_ipa_types.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ipalib/tests/test_ipa_types.py b/ipalib/tests/test_ipa_types.py index 8e4f379f..d78160db 100644 --- a/ipalib/tests/test_ipa_types.py +++ b/ipalib/tests/test_ipa_types.py @@ -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 -- cgit