-
Notifications
You must be signed in to change notification settings - Fork 738
Added default
parameter to RadioList and radiolist_dialog
#651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from __future__ import unicode_literals | ||
|
||
from prompt_toolkit.widgets import RadioList | ||
|
||
import pytest | ||
|
||
def test_initial(): | ||
values = [ | ||
(1, 'some_text'), | ||
('fizz', 'some_more_text'), | ||
({'foo':'bar'}, 'even_more_text') | ||
] | ||
radiolist = RadioList(values) | ||
assert radiolist.current_value == 1 | ||
assert radiolist._selected_index == 0 | ||
|
||
def test_default(): | ||
values = [ | ||
(1, 'some_text'), | ||
('fizz', 'some_more_text'), | ||
({'foo':'bar'}, 'even_more_text') | ||
] | ||
radiolist = RadioList(values, 1) | ||
assert radiolist.current_value == 'fizz' | ||
assert radiolist._selected_index == 1 | ||
|
||
def test_bad_params(): | ||
with pytest.raises(AssertionError): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Arrowbox, I think raising There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to change that, but there are a bunch of other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked at testing if assert has been stripped to decide if we should just drop the test but that did not seem trivial. |
||
radiolist = RadioList([]) | ||
|
||
with pytest.raises(AssertionError): | ||
radiolist = RadioList(None) | ||
|
||
with pytest.raises(AssertionError): | ||
values = ( | ||
(1, 'some_text'), | ||
('fizz', 'some_more_text'), | ||
({'foo':'bar'}, 'even_more_text') | ||
) | ||
radiolist = RadioList(values) | ||
|
||
with pytest.raises(AssertionError): | ||
values = [ | ||
(1, 'some_text', 'whoops'), | ||
('fizz', 'some_more_text'), | ||
({'foo':'bar'}, 'even_more_text') | ||
] | ||
radiolist = RadioList(values) | ||
|
||
with pytest.raises(AssertionError): | ||
values = [ | ||
(1, 'some_text'), | ||
('fizz', ), | ||
({'foo':'bar'}, 'even_more_text') | ||
] | ||
radiolist = RadioList(values) | ||
|
||
with pytest.raises(AssertionError): | ||
values = [ | ||
(1, 'some_text'), | ||
('fizz', 'some_more_text'), | ||
[{'foo':'bar'}, 'even_more_text'] | ||
] | ||
radiolist = RadioList(values) | ||
|
||
with pytest.raises(AssertionError): | ||
values = [ | ||
(1, 'some_text'), | ||
('fizz', 'some_more_text'), | ||
({'foo':'bar'}, 'even_more_text') | ||
] | ||
radiolist = RadioList(values, 3) | ||
|
||
with pytest.raises(AssertionError): | ||
values = [ | ||
(1, 'some_text'), | ||
('fizz', 'some_more_text'), | ||
({'foo':'bar'}, 'even_more_text') | ||
] | ||
radiolist = RadioList(values, -1) | ||
|
||
with pytest.raises(AssertionError): | ||
values = [ | ||
(1, 'some_text'), | ||
('fizz', 'some_more_text'), | ||
({'foo':'bar'}, 'even_more_text') | ||
] | ||
radiolist = RadioList(values, None) | ||
|
||
with pytest.raises(AssertionError): | ||
values = [ | ||
(1, 'some_text'), | ||
('fizz', 'some_more_text'), | ||
({'foo':'bar'}, 'even_more_text') | ||
] | ||
radiolist = RadioList(values, 'whoops') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the
default
argument, but I would prefer if it was not an integer, but a key from thevalues
list. Would it be possible to change it that way. The default can beNone
which always takes the first value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd hesitate because the input is a list of tuples. There is no guarantee of uniqueness on the values or key. Maybe also accept the tuple from the list? And do a check internally and decide what to do?