Commit 4add82e6 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

fix [de]serialization bug of vocabulary constraints in case

      where some vocabulary value contains a comma followed by a space

--HG--
branch : stable
parent b46342352e09
ChangeLog for yams
------------------
--
* fix [de]serialization bug of vocabulary constraints in case
where some vocabulary value contains a comma followed by a space
2010-06-21 -- 0.29.1
* not use a hardcoded datatype for string colums with a max length (closes
#35380). When a dbhelper provides a SizeConstrainedString entry in the
......
......@@ -338,12 +338,16 @@ class StaticVocabularyConstraint(BaseConstraint):
sample = unicode()
if not isinstance(sample, basestring):
return u', '.join(repr(word) for word in self.vocabulary())
return u', '.join(repr(unicode(word)) for word in self.vocabulary())
return u', '.join(repr(unicode(word).replace(',', ',,'))
for word in self.vocabulary())
@classmethod
def deserialize(cls, value):
"""deserialize possible values from a csv list of evaluable strings"""
return cls([eval(w) for w in value.split(', ')])
values = [eval(w) for w in re.split('(?<!,), ', value)]
if values and isinstance(values[0], basestring):
values = [v.replace(',,', ',') for v in values]
return cls(values)
class FormatConstraint(StaticVocabularyConstraint):
......
......@@ -19,8 +19,8 @@
Use either a sql derivated language for entities and relation definitions
files or a direct python definition file.
"""
__docformat__ = "restructuredtext en"
import sys
......@@ -140,7 +140,8 @@ class PyFileReader(object):
if modname in sys.modules:
module = sys.modules[modname]
# NOTE: don't test raw equality to avoid .pyc / .py comparisons
assert abspath(module.__file__).startswith(abspath(filepath)), (filepath, module.__file__)
assert abspath(module.__file__).startswith(abspath(filepath)), (
modname, filepath, module.__file__)
else:
# XXX until bw compat is gone, put context into builtins to allow proper
# control of deprecation warning
......
......@@ -110,6 +110,11 @@ class ConstraintTC(TestCase):
# fail, value > maxvalue
self.failIf(cstr2.check(None, 'hip', date.today() + timedelta(days=1)))
def test_vocab_constraint_serialization(self):
cstr = StaticVocabularyConstraint(['a, b', 'c'])
self.assertEquals(StaticVocabularyConstraint.deserialize(cstr.serialize()).values,
('a, b', 'c'))
if __name__ == '__main__':
unittest_main()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment