mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 21:18:32 +02:00
Merge pull request #744 from alichtman/exit-after-no-text-entry
Exit jrnl if no text entered into editor
This commit is contained in:
commit
0bd94c7872
4 changed files with 53 additions and 3 deletions
|
@ -20,6 +20,19 @@ Feature: Basic reading and writing to a journal
|
||||||
When we run "jrnl -n 1"
|
When we run "jrnl -n 1"
|
||||||
Then the output should contain "2013-07-23 09:00 A cold and stormy day."
|
Then the output should contain "2013-07-23 09:00 A cold and stormy day."
|
||||||
|
|
||||||
|
Scenario: Writing an empty entry from the editor
|
||||||
|
Given we use the config "editor.yaml"
|
||||||
|
When we open the editor and enter ""
|
||||||
|
Then we should see the message "[Nothing saved to file]"
|
||||||
|
|
||||||
|
Scenario: Writing an empty entry from the command line
|
||||||
|
Given we use the config "basic.yaml"
|
||||||
|
When we run "jrnl" and enter ""
|
||||||
|
Then the output should be
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
Scenario: Filtering for dates
|
Scenario: Filtering for dates
|
||||||
Given we use the config "basic.yaml"
|
Given we use the config "basic.yaml"
|
||||||
When we run "jrnl -on 2013-06-10 --short"
|
When we run "jrnl -on 2013-06-10 --short"
|
||||||
|
|
12
features/data/configs/editor.yaml
Normal file
12
features/data/configs/editor.yaml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
default_hour: 9
|
||||||
|
default_minute: 0
|
||||||
|
editor: "vim"
|
||||||
|
encrypt: false
|
||||||
|
highlight: true
|
||||||
|
journals:
|
||||||
|
default: features/journals/simple.journal
|
||||||
|
linewrap: 80
|
||||||
|
tagsymbols: "@"
|
||||||
|
template: false
|
||||||
|
timeformat: "%Y-%m-%d %H:%M"
|
||||||
|
indent_character: "|"
|
|
@ -29,6 +29,7 @@ class TestKeyring(keyring.backend.KeyringBackend):
|
||||||
def delete_password(self, servicename, username, password):
|
def delete_password(self, servicename, username, password):
|
||||||
self.keys[servicename][username] = None
|
self.keys[servicename][username] = None
|
||||||
|
|
||||||
|
|
||||||
# set the keyring for keyring lib
|
# set the keyring for keyring lib
|
||||||
keyring.set_keyring(TestKeyring())
|
keyring.set_keyring(TestKeyring())
|
||||||
|
|
||||||
|
@ -66,6 +67,24 @@ def set_config(context, config_file):
|
||||||
cf.write("version: {}".format(__version__))
|
cf.write("version: {}".format(__version__))
|
||||||
|
|
||||||
|
|
||||||
|
@when('we open the editor and enter ""')
|
||||||
|
@when('we open the editor and enter "{text}"')
|
||||||
|
def open_editor_and_enter(context, text=""):
|
||||||
|
text = (text or context.text)
|
||||||
|
def _mock_editor_function(command):
|
||||||
|
tmpfile = command[-1]
|
||||||
|
with open(tmpfile, "w+") as f:
|
||||||
|
if text is not None:
|
||||||
|
f.write(text)
|
||||||
|
else:
|
||||||
|
f.write("")
|
||||||
|
|
||||||
|
return tmpfile
|
||||||
|
|
||||||
|
with patch('subprocess.call', side_effect=_mock_editor_function):
|
||||||
|
run(context, "jrnl")
|
||||||
|
|
||||||
|
|
||||||
def _mock_getpass(inputs):
|
def _mock_getpass(inputs):
|
||||||
def prompt_return(prompt="Password: "):
|
def prompt_return(prompt="Password: "):
|
||||||
print(prompt)
|
print(prompt)
|
||||||
|
@ -82,12 +101,18 @@ def _mock_input(inputs):
|
||||||
|
|
||||||
|
|
||||||
@when('we run "{command}" and enter')
|
@when('we run "{command}" and enter')
|
||||||
|
@when('we run "{command}" and enter ""')
|
||||||
@when('we run "{command}" and enter "{inputs1}"')
|
@when('we run "{command}" and enter "{inputs1}"')
|
||||||
@when('we run "{command}" and enter "{inputs1}" and "{inputs2}"')
|
@when('we run "{command}" and enter "{inputs1}" and "{inputs2}"')
|
||||||
def run_with_input(context, command, inputs1="", inputs2=""):
|
def run_with_input(context, command, inputs1="", inputs2=""):
|
||||||
# create an iterator through all inputs. These inputs will be fed one by one
|
# create an iterator through all inputs. These inputs will be fed one by one
|
||||||
# to the mocked calls for 'input()', 'util.getpass()' and 'sys.stdin.read()'
|
# to the mocked calls for 'input()', 'util.getpass()' and 'sys.stdin.read()'
|
||||||
text = iter((inputs1, inputs2)) if inputs1 else iter(context.text.split("\n"))
|
if inputs1:
|
||||||
|
text = iter((inputs1, inputs2))
|
||||||
|
elif context.text:
|
||||||
|
text = iter(context.text.split("\n"))
|
||||||
|
else:
|
||||||
|
text = iter(("", ""))
|
||||||
args = ushlex(command)[1:]
|
args = ushlex(command)[1:]
|
||||||
with patch("builtins.input", side_effect=_mock_input(text)) as mock_input:
|
with patch("builtins.input", side_effect=_mock_input(text)) as mock_input:
|
||||||
with patch("jrnl.util.getpass", side_effect=_mock_getpass(text)) as mock_getpass:
|
with patch("jrnl.util.getpass", side_effect=_mock_getpass(text)) as mock_getpass:
|
||||||
|
|
|
@ -206,7 +206,7 @@ def run(manual_args=None):
|
||||||
if raw:
|
if raw:
|
||||||
args.text = [raw]
|
args.text = [raw]
|
||||||
else:
|
else:
|
||||||
mode_compose = False
|
sys.exit()
|
||||||
|
|
||||||
# This is where we finally open the journal!
|
# This is where we finally open the journal!
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Reference in a new issue