Skip to content

Commit

Permalink
migrate editor to a newer, up to date implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Cube707 committed Jan 3, 2024
1 parent adbed51 commit 895726e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 28 deletions.
62 changes: 48 additions & 14 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
python = ">=3.8.1"
blessed = ">=1.19.0"
readchar = ">=3.0.6"
python-editor = ">=1.0.4"
editor = { git = "https://github.com/Cube707/editor" } # ">=1.5.1" # TODO: waiting for https://github.com/rec/editor/pull/8

[tool.poetry.dev-dependencies]
bandit = ">=1.7.4"
Expand Down
4 changes: 2 additions & 2 deletions src/inquirer/render/console/_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def process_input(self, pressed):
raise KeyboardInterrupt()

if pressed in (key.CR, key.LF, key.ENTER):
data = editor.edit(contents=self.question.default or "")
raise errors.EndOfInput(data.decode("utf-8"))
data = editor(text=self.question.default or "")
raise errors.EndOfInput(data)

raise errors.ValidationError(
"You have pressed unknown key! " "Press <enter> to open editor or " "CTRL+C to exit."
Expand Down
22 changes: 11 additions & 11 deletions tests/integration/console_render/test_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def setUp(self):
def tearDown(self):
self.base_teardown()

@patch("editor.edit")
def test_basic_render(self, edit):
edit.return_value = b"Some text"
@patch("inquirer.render.console._editor.editor")
def test_basic_render(self, editor):
editor.return_value = "Some text"
stdin = [key.ENTER]
message = "Foo message"
variable = "Bar variable"
Expand All @@ -30,11 +30,11 @@ def test_basic_render(self, edit):

self.assertEqual("Some text", result)
self.assertInStdout(message)
self.assertTrue(edit.called)
self.assertTrue(editor.called)

@patch("editor.edit")
@patch("inquirer.render.console._editor.editor")
def test_ignore_true_should_return(self, edit):
edit.return_value = b"Some text"
edit.return_value = "Some text"
stdin = [key.ENTER]
message = "Foo message"
variable = "Bar variable"
Expand All @@ -49,10 +49,10 @@ def test_ignore_true_should_return(self, edit):
self.assertNotInStdout(message)
self.assertFalse(edit.called)

@patch("editor.edit")
@patch("inquirer.render.console._editor.editor")
def test_validation_fails(self, edit):
stdin = [key.ENTER, key.ENTER]
edit.side_effect = [b"Only one line", b"Two\nLines\nCool"]
edit.side_effect = ["Only one line", "Two\nLines\nCool"]

message = "Insert number"
variable = "foo"
Expand All @@ -70,10 +70,10 @@ def val(_, x):
self.assertInStdout("Entered value is not a valid foo")
self.assertTrue(edit.called)

@patch("editor.edit")
@patch("inquirer.render.console._editor.editor")
def test_validation_fails_with_custom_error(self, edit):
stdin = [key.ENTER, key.ENTER]
edit.side_effect = [b"Only one line", b"Two\nLines\nCool"]
edit.side_effect = ["Only one line", "Two\nLines\nCool"]

message = "Insert number"
variable = "foo"
Expand All @@ -94,7 +94,7 @@ def val(_, x):
self.assertInStdout("Some bad reason")
self.assertTrue(edit.called)

@patch("editor.edit")
@patch("inquirer.render.console._editor.editor")
def test_ctrl_c_breaks_execution(self, edit):
stdin = [key.CTRL_C]
message = "Foo message"
Expand Down

0 comments on commit 895726e

Please sign in to comment.