[wwwsearch-commits] r17802 - wwwsearch/ClientForm/trunk
jjlee at codespeak.net
jjlee at codespeak.net
Sat Sep 24 00:36:05 CEST 2005
Author: jjlee
Date: Sat Sep 24 00:36:00 2005
New Revision: 17802
Modified:
wwwsearch/ClientForm/trunk/ClientForm.py
wwwsearch/ClientForm/trunk/test.py
Log:
Fix disambiguate bug: raise ItemCountError, not IndexError, when nr is too high
Modified: wwwsearch/ClientForm/trunk/ClientForm.py
==============================================================================
--- wwwsearch/ClientForm/trunk/ClientForm.py (original)
+++ wwwsearch/ClientForm/trunk/ClientForm.py Sat Sep 24 00:36:00 2005
@@ -26,7 +26,6 @@
# XXXX
# _find_control &c. and ambiguous control labels
-# SelectControl and labels -- backwards compat., multiple labels
# XXX
# Add some more functional tests
@@ -1413,9 +1412,10 @@
if nr is None:
if len(items) > 1:
raise AmbiguityError(name)
- return items[0]
- else:
- return items[nr]
+ nr = 0
+ if len(items) <= nr:
+ raise ItemNotFoundError(name)
+ return items[nr]
class ListControl(Control):
"""Control representing a sequence of items.
@@ -1821,7 +1821,7 @@
off[0].selected = True
def _multiple_set_value(self, value):
- turn_on = [] # transactional-ish
+ turn_on = [] # transactional-ish
turn_off = [item for item in self.items if item.selected and not item.disabled]
names = {}
for nn in value:
@@ -1970,7 +1970,7 @@
o.selected = True
break
else:
- # Ensure only onr item selected. Choose the last one,
+ # Ensure only one item selected. Choose the last one,
# following IE and Firefox.
for o in found[:-1]:
o.selected = False
@@ -2038,7 +2038,8 @@
<OPTION>this bit</OPTION>
"""
- # HTML attributes here are treated slightly from other list controls:
+ # HTML attributes here are treated slightly differently from other list
+ # controls:
# -The SELECT HTML attributes dictionary is stuffed into the OPTION
# HTML attributes dictionary under the "__select" key.
# -The content of each OPTION element is stored under the special
@@ -2096,7 +2097,7 @@
o.selected = True
break
elif not self.multiple:
- # Ensure only onr item selected. Choose the last one,
+ # Ensure only one item selected. Choose the last one,
# following IE and Firefox.
for o in found[:-1]:
o.selected = False
Modified: wwwsearch/ClientForm/trunk/test.py
==============================================================================
--- wwwsearch/ClientForm/trunk/test.py (original)
+++ wwwsearch/ClientForm/trunk/test.py Sat Sep 24 00:36:00 2005
@@ -2437,6 +2437,38 @@
self.assert_(not c.get_item_attrs("3").has_key("blah"))
reset_deprecations()
+ def test_select_control_nr_and_label(self):
+ f = StringIO("""\
+<form>
+ <select multiple name="form.grocery">
+ <option value="p" label="a" id="1">a</option>
+ <option value="q" label="b" id="2">a</option>
+ <option value="p" label="a" id="3">b</option>
+ </select>
+</form>
+""")
+ form = ClientForm.ParseFile(f, "http://example.com/",
+ ignore_ambiguity=True)[0]
+ ctl = form.find_control("form.grocery")
+ # ordinary case
+ self.assertEqual(ctl.get("p", nr=1).id, "3")
+ # nr too high
+ self.assertRaises(ItemNotFoundError, ctl.get, "p", nr=50)
+ # first having label "a"
+ self.assertEqual(ctl.get("a", nr=0, by_label=True).id, "1")
+ # second having label "a"...
+ item = ctl.get("a", nr=1, by_label=True)
+ # ...as opposed to second with label attribute "a"! -- each item
+ # has multiple labels accessible by .get_labels(), but only one
+ # label HTML-attribute
+ self.assertEqual(item.id, "2")
+ self.assertEqual(item.attrs.get("label"), "b") # !
+ # third having label "a" (but only the second whose label is "a")
+ self.assertEqual(ctl.get("a", nr=1, by_label=True).id, "2")
+ # nr too high again
+ self.assertRaises(ItemNotFoundError, ctl.get, "a", nr=3, by_label=True)
+
+
def startswith(string, initial):
if len(initial) > len(string): return False
return string[:len(initial)] == initial
More information about the wwwsearch-commits
mailing list