+ """
+ self.check_html(self.widget(choices=choices), "beatle", "J", html=html)
def test_nested_choices(self):
nested_choices = (
@@ -70,27 +77,286 @@ class RadioSelectTest(WidgetTest):
html=html,
)
+ def test_render_none(self):
+ """
+ If value is None, none of the options are selected.
+ """
+ choices = BLANK_CHOICE_DASH + self.beatles
+ html = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ self.check_html(self.widget(choices=choices), "beatle", None, html=html)
+
+ def test_render_label_value(self):
+ """
+ If the value corresponds to a label (but not to an option value), none
+ of the options are selected.
+ """
+ html = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ self.check_html(self.widget(choices=self.beatles), "beatle", "Ringo", html=html)
+
+ def test_render_selected(self):
+ """
+ Only one option can be selected.
+ """
+ choices = [("0", "0"), ("1", "1"), ("2", "2"), ("3", "3"), ("0", "extra")]
+ html = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ self.check_html(self.widget(choices=choices), "choices", "0", html=html)
+
def test_constructor_attrs(self):
"""
Attributes provided at instantiation are passed to the constituent
inputs.
"""
- widget = RadioSelect(attrs={"id": "foo"}, choices=self.beatles)
+ widget = self.widget(attrs={"id": "foo"}, choices=self.beatles)
html = """
+
+
+
+
+
+
+
+
+
+
+ """
+ self.check_html(widget, "beatle", "J", html=html)
+
+ def test_compare_to_str(self):
+ """
+ The value is compared to its str()
+ """
+ html = """
"""
- self.check_html(widget, "beatle", "J", html=html)
+ self.check_html(widget, "num", 3, html=html)
+
+ def test_choices_constructor_generator(self):
+ """
+ If choices is passed to the constructor and is a generator, it can be
+ iterated over multiple times without getting consumed.
+ """
+
+ def get_choices():
+ for i in range(4):
+ yield (i, i)
+
+ html = """
+