[1.7.x] Fixed #22255 -- Added support for specifying re flags in RegexValidator

Backport of 4d0c5f6142 from master.
This commit is contained in:
Dejan Noveski 2014-03-13 12:23:12 +01:00 committed by Erik Romijn
parent cc8a800d0c
commit b74ec85c1d
5 changed files with 61 additions and 8 deletions

View file

@ -198,6 +198,10 @@ TEST_DATA = (
(RegexValidator(re.compile('x'), inverse_match=True), 'y', None),
(RegexValidator('x', inverse_match=True), 'x', ValidationError),
(RegexValidator(re.compile('x'), inverse_match=True), 'x', ValidationError),
(RegexValidator('x', flags=re.IGNORECASE), 'y', ValidationError),
(RegexValidator('a'), 'A', ValidationError),
(RegexValidator('a', flags=re.IGNORECASE), 'A', None),
)
@ -250,6 +254,14 @@ class TestSimpleValidators(TestCase):
self.assertEqual(str(v), str_prefix("{%(_)s'first': [%(_)s'First Problem']}"))
self.assertEqual(repr(v), str_prefix("ValidationError({%(_)s'first': [%(_)s'First Problem']})"))
def test_regex_validator_flags(self):
try:
RegexValidator(re.compile('a'), flags=re.IGNORECASE)
except TypeError:
pass
else:
self.fail("TypeError not raised when flags and pre-compiled regex in RegexValidator")
test_counter = 0
for validator, value, expected in TEST_DATA:
name, method = create_simple_test_method(validator, expected, value, test_counter)