From 77646eaa1a2fa6907affca325e4824a36790f4fc Mon Sep 17 00:00:00 2001 From: Suhas Date: Sat, 23 Jan 2021 11:18:13 -0500 Subject: [PATCH] make format --- features/steps/core.py | 49 ++++++++++++++++++++++-------------------- tests/test_config.py | 38 +++++++++++++++++--------------- 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/features/steps/core.py b/features/steps/core.py index e6c88609..bee060f7 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -212,32 +212,35 @@ def open_editor_and_enter(context, method, text=""): # fmt: on + @then("the editor {editor} should have been called") -def editor_override(context, editor): - - def _mock_editor(command_and_journal_file): +def editor_override(context, editor): + def _mock_editor(command_and_journal_file): editor = command_and_journal_file[0] - context.tmpfile = command_and_journal_file[-1] - print("%s has been launched"%editor) + tmpfile = command_and_journal_file[-1] + context.tmpfile = tmpfile + print("%s has been launched" % editor) return tmpfile - - try : - # fmt: off - # see: https://github.com/psf/black/issues/664 - with \ - patch("subprocess.call", side_effect=_mock_editor) as mock_editor, \ - patch("sys.stdin.isatty", return_value=True), \ - patch("jrnl.time.parse", side_effect=_mock_time_parse(context)), \ - patch("jrnl.config.get_config_path", side_effect=lambda: context.config_path), \ - patch("jrnl.install.get_config_path", side_effect=lambda: context.config_path) \ - : - cli(['--override','{"editor": "%s"}'%editor]) - context.exit_status = 0 - context.editor = mock_editor - assert mock_editor.assert_called_once_with(editor, context.tmpfile) - except SystemExit as e: - context.exit_status = e.code - + + # fmt: off + # see: https://github.com/psf/black/issues/664 + with \ + patch("subprocess.call", side_effect=_mock_editor) as mock_editor, \ + patch("sys.stdin.isatty", return_value=True), \ + patch("jrnl.time.parse", side_effect=_mock_time_parse(context)), \ + patch("jrnl.config.get_config_path", side_effect=lambda: context.config_path), \ + patch("jrnl.install.get_config_path", side_effect=lambda: context.config_path) \ + : + try : + cli(['--override','{"editor": "%s"}'%editor]) + context.exit_status = 0 + context.editor = mock_editor + assert mock_editor.assert_called_once_with(editor, context.tmpfile) + except SystemExit as e: + context.exit_status = e.code + # fmt: on + + @then("the editor should have been called") @then("the editor should have been called with {num} arguments") def count_editor_args(context, num=None): diff --git a/tests/test_config.py b/tests/test_config.py index 21dcc521..19ef3172 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -12,31 +12,31 @@ from jrnl import install, editor @pytest.fixture() def minimal_config(): with open("features/data/configs/editor.yaml", "r") as cfg_file: - cfg = yaml.load(cfg_file.read()) - yield cfg + cfg = yaml.load(cfg_file.read()) + yield cfg + @pytest.fixture() def expected_override(minimal_config): exp_out_cfg = minimal_config.copy() - exp_out_cfg['editor'] = 'nano' - exp_out_cfg['journal'] = 'features/journals/simple.journal' + exp_out_cfg["editor"] = "nano" + exp_out_cfg["journal"] = "features/journals/simple.journal" yield exp_out_cfg from jrnl import jrnl - -@mock.patch('sys.stdin.isatty') +@mock.patch("sys.stdin.isatty") @mock.patch.object(install, "load_or_install_jrnl") -@mock.patch('subprocess.call') +@mock.patch("subprocess.call") def test_override_configured_editor( mock_subprocess_call, - mock_load_or_install, - mock_isatty, - minimal_config, + mock_load_or_install, + mock_isatty, + minimal_config, expected_override, - capsys + capsys, ): mock_load_or_install.return_value = minimal_config mock_isatty.return_value = True @@ -44,11 +44,15 @@ def test_override_configured_editor( cli_args = ["--override", '{"editor": "nano"}'] parser = parse_args(cli_args) assert parser.config_override.__len__() == 1 - def mock_editor_launch(editor): - print("%s launched! Success!"%editor) - with mock.patch.object(jrnl,'_write_in_editor', side_effect=mock_editor_launch(parser.config_override['editor']), return_value = 'note_contents') as mock_write_in_editor: + + def mock_editor_launch(editor): + print("%s launched! Success!" % editor) + + with mock.patch.object( + jrnl, + "_write_in_editor", + side_effect=mock_editor_launch(parser.config_override["editor"]), + return_value="note_contents", + ) as mock_write_in_editor: run(parser) mock_write_in_editor.assert_called_once_with(expected_override) - - -