Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #535 (closed defect: fixed)

Opened 13 years ago

Last modified 12 years ago

SelectionField vs. test_formmaker

Reported by: alberto@… Owned by: anonymous
Priority: normal Milestone: 0.9
Component: TG Widgets Version:
Severity: normal Keywords:


test_formmaker is currently failing as a DataCheckBox? field expects a Set() validator (but finds a ForEach?() validator):

FAIL: test_simpleWidgets (turbogears.fastdata.tests.test_formmaker.TestSQLObject
Traceback (most recent call last):
  File "/home/alberto/src/turbogearsCOMMIT/turbogears/fastdata/tests/test_formma
ker.py", line 19, in test_simpleWidgets
    assert isinstance(widgetlist[3].validator, validators.Set)

 http://formencode.org/class-formencode.validators.Set.html says that a Set() validator is equivalent to a ForEach? validator but converts single valued inputs to a single item list so i thought it was a typo at form.py

I tried to fix this at r699 and everything (from a nosetest point of view) was looking good, better than good, as that failing test was passing ;).

But the final authority, that is a look-it-thorough-a-browser test, revealed that checked options on a CheckList? didn't prevail when the form was submitted.

I'm not a formencode expert so I leave this here with the hope of someone more knowledgeable than me to take a chance. Maybe it's just the test that needs to be updated...


Change History

comment:1 Changed 13 years ago by michele

I'm also not a big formencode expert. Anyway I've used Set and then switched to ForEach? but I don't remember why, I think for the issue you mentioned. I'm using the development version of formencode and ForEach? always return a list, at least here.

comment:2 Changed 13 years ago by michele

Ok, now I remember.

We *must* use ForEach? otherwise we can't wrap a validator to be applied to every value of a multiple selection and to get a list as a result.

With Set() you can't use a validator (at least I'm not being able to do it) it does only the conversion to a list.

That's the relevant output:

>>> import formencode as f
>>> from formencode import validators as v
>>> test1 = f.ForEach(v.Int())
>>> test1.to_python('1')
>>> test1 = v.Set(v.Int())
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "formencode/api.py", line 122, in __init__
  File "formencode/declarative.py", line 135, in __init__
TypeError: Set() takes at most 0 arguments (1 given)
>>> test1 = v.Set()
>>> test1.to_python('1')
>>> test1.validators.append(v.Int())
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'Set' object has no attribute 'validators'
>>> test1 = f.ForEach()
>>> test1.validators.append(v.Int())
>>> test1.to_python('1')

Again, the problem is that we need to compare python values, so we need a good conversion of the values coming from the web, that's why with Set() your FF test doesn't work, we get '1' from the web but the conversion is still '1' and not 1 as it should be if we are talking about integers.

As you can see from my example above ForEach? always gives you a list.

Conclusion: the formmaker test should be fixed.

But I would like to hear from a more experienced formencode user.

comment:3 Changed 13 years ago by anonymous

  • Status changed from new to closed
  • Resolution set to fixed

I've fixed the test as I think it is outdated (though I'm no formencode experienced user). Everything seems ok from a browser point of view so I'll listen to FF ;).

I've fixed the test at r713

Note: See TracTickets for help on using tickets.