diff options
-rw-r--r-- | ipalib/tests/test_ipa_types.py | 31 |
1 files changed, 31 insertions, 0 deletions
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 |