-
Notifications
You must be signed in to change notification settings - Fork 96
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
Added checkbox locked choices feature #327
Changes from 6 commits
39eb6be
3a6cee7
27c0418
4161849
5ee64bb
bf20f55
5f51882
fcb98ba
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,21 @@ | ||
import os | ||
import sys | ||
from pprint import pprint | ||
|
||
|
||
sys.path.append(os.path.realpath(".")) | ||
import inquirer # noqa | ||
|
||
|
||
questions = [ | ||
inquirer.Checkbox( | ||
"courses", | ||
message="Which courses would you like to take?", | ||
choices=["Programming fundamentals", "Fullstack development", "Data science", "DevOps"], | ||
locked=["Programming fundamentals"], | ||
), | ||
] | ||
|
||
answers = inquirer.prompt(questions) | ||
|
||
pprint(answers) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,3 +147,27 @@ def setUp(self): | |
def test_default_selection(self): | ||
self.sut.send(key.ENTER) | ||
self.sut.expect("{'interests': ", timeout=1) | ||
|
||
|
||
@unittest.skipUnless(sys.platform.startswith("lin"), "Linux only") | ||
class CheckLockedTest(unittest.TestCase): | ||
def setUp(self): | ||
self.sut = pexpect.spawn("python examples/checkbox_locked.py") | ||
self.sut.expect("DevOps.*", timeout=1) | ||
|
||
def test_default_selection(self): | ||
self.sut.send(key.ENTER) | ||
self.sut.expect(r"{'courses': \['Programming fundamentals'\]}", timeout=1) | ||
|
||
def test_locked_option(self): | ||
self.sut.send(key.SPACE) | ||
self.sut.send(key.LEFT) | ||
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. Its a good idea to test for both keys to select a option. But in this case the test would actually succseed even if the locking code didn't work, as it deselects and than imediatly selects againt. So please seperate this into two seperate tests 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. Seprated into two tests |
||
self.sut.send(key.ENTER) | ||
self.sut.expect(r"{'courses': \['Programming fundamentals'\]}", timeout=1) | ||
|
||
def test_locked_with_another_option(self): | ||
self.sut.send(key.DOWN) | ||
self.sut.send(key.DOWN) | ||
self.sut.send(key.SPACE) | ||
self.sut.send(key.ENTER) | ||
self.sut.expect(r"{'courses': \['Programming fundamentals', 'Data science'\]}", timeout=1) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -324,3 +324,59 @@ def test_double_invert_all(self): | |
result = sut.render(question) | ||
|
||
assert result == [] | ||
|
||
def test_unselect_locked(self): | ||
stdin_array = [key.SPACE, key.LEFT, key.ENTER] | ||
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. same as above 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. Seprated into two tests as well |
||
stdin = helper.event_factory(*stdin_array) | ||
message = "Foo message" | ||
variable = "Bar variable" | ||
choices = ["foo", "bar", "bazz"] | ||
|
||
question = questions.Checkbox(variable, message, choices=choices, locked=["foo"]) | ||
|
||
sut = ConsoleRender(event_generator=stdin) | ||
result = sut.render(question) | ||
|
||
assert result == ["foo"] | ||
|
||
def test_two_locked_options(self): | ||
stdin_array = [key.ENTER] | ||
stdin = helper.event_factory(*stdin_array) | ||
message = "Foo message" | ||
variable = "Bar variable" | ||
choices = ["foo", "bar", "bazz"] | ||
|
||
question = questions.Checkbox(variable, message, choices=choices, locked=["foo", "bazz"]) | ||
|
||
sut = ConsoleRender(event_generator=stdin) | ||
result = sut.render(question) | ||
|
||
assert result == ["foo", "bazz"] | ||
|
||
def test_locked_with_typo(self): | ||
stdin_array = [key.ENTER] | ||
stdin = helper.event_factory(*stdin_array) | ||
message = "Foo message" | ||
variable = "Bar variable" | ||
choices = ["foo", "bar", "bazz"] | ||
|
||
question = questions.Checkbox(variable, message, choices=choices, locked=["fooo"]) | ||
|
||
sut = ConsoleRender(event_generator=stdin) | ||
result = sut.render(question) | ||
|
||
assert result == [] | ||
|
||
def test_locked_with_default(self): | ||
stdin_array = [key.DOWN, key.SPACE, key.ENTER] | ||
stdin = helper.event_factory(*stdin_array) | ||
message = "Foo message" | ||
variable = "Bar variable" | ||
choices = ["foo", "bar", "bazz"] | ||
|
||
question = questions.Checkbox(variable, message, choices=choices, locked=["bar"], default=["bar"]) | ||
|
||
sut = ConsoleRender(event_generator=stdin) | ||
result = sut.render(question) | ||
|
||
assert result == ["bar"] |
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.
this function is named strangely. I assume you wanted to make its return type clear? (which changed in the meantime)
However like this its named as a Setter-Methode, which it is clearly not.
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.
Renamed