Merge "Fix printing object reference on StringType"

This commit is contained in:
Jenkins 2015-01-22 17:17:10 +00:00 committed by Gerrit Code Review
commit a24f4c4449
2 changed files with 10 additions and 1 deletions

View File

@ -326,6 +326,15 @@ Value: 'v3'. Value should be one of: v., v.",
v.validate('A')
self.assertRaises(ValueError, v.validate, '_')
def test_validate_string_type_pattern_exception_message(self):
regex = '^[a-zA-Z0-9]*$'
v = types.StringType(pattern=regex)
try:
v.validate('_')
self.assertFail()
except ValueError as e:
self.assertIn(regex, str(e))
def test_validate_ipv4_address_type(self):
v = types.IPv4AddressType()
v.validate('127.0.0.1')

View File

@ -218,7 +218,7 @@ class StringType(UserType):
raise ValueError(error)
if self.pattern is not None and not self.pattern.search(value):
error = 'Value should match the pattern %s' % self.pattern
error = 'Value should match the pattern %s' % self.pattern.pattern
raise ValueError(error)
return value