registry: forbid direct access to Regexp.setValue.

This is not a regression; this was already forbidden before
23417b0675, and this commit was not
tagged/released yet at the moment I'm writing this one.
This commit is contained in:
Valentin Lorentz 2020-09-15 09:59:08 +02:00
parent ac94c5291e
commit f4d6bd11be
2 changed files with 18 additions and 0 deletions

View File

@ -785,6 +785,17 @@ class Regexp(Value):
else:
super().set(v)
def setValue(self, v):
"""Don't call this function directly from plugins, it is subject
to change without notice."""
if v is not None and (not isinstance(v, tuple) or len(v) != 2):
raise InvalidRegistryValue(
'Can\'t setValue a regexp, there would be an inconsistency '
'between the regexp and the recorded string value. '
'Use .set() instead.')
super().setValue(v)
def __call__(self):
if self.value is None:
return None

View File

@ -183,6 +183,13 @@ class ValuesTestCase(SupyTestCase):
v.set('')
self.assertEqual(v(), None)
def testRegexpSetValue(self):
v = registry.Regexp(None, 'help')
self.assertRaises(registry.InvalidRegistryValue,
v.setValue, r'foo')
self.assertRaises(registry.InvalidRegistryValue,
v.setValue, re.compile(r'foo'))
def testRegexpDefaultString(self):
v = registry.Regexp('m/foo/', 'help')
self.assertEqual(v(), re.compile('foo'))