Skip to content
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

Exit jrnl if no text entered into editor #744

Merged
merged 28 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2890e33
Exit jrnl if no text entered into editor
alichtman Nov 14, 2019
7a90f40
Add test for aborting jrnl entry from editor
alichtman Nov 15, 2019
f0e5fe9
Use native mocking
alichtman Nov 15, 2019
ac21a4f
Merge branch 'master' into exit-after-no-text-entry
alichtman Nov 15, 2019
d378e25
Add comment explaining discrepancy between expected and asserted output
alichtman Nov 15, 2019
c0a1c17
Fix check_empty_output method
alichtman Nov 16, 2019
ccb5539
Check message on stderr and patch subprocess.call
alichtman Nov 16, 2019
9b0ebb7
Add _mock_editor_function
alichtman Nov 16, 2019
68772d3
Update features/steps/core.py
alichtman Nov 16, 2019
e63ae25
Add return from mock function
alichtman Nov 16, 2019
7dcc914
Add debug statements
alichtman Nov 16, 2019
87571fa
Debug
alichtman Nov 16, 2019
8d22283
Update features/steps/core.py
alichtman Nov 16, 2019
4cfff00
Move sys.exit() down
alichtman Nov 16, 2019
c23efa7
Fix test?
alichtman Nov 16, 2019
bca12b4
Fix test?
alichtman Nov 16, 2019
5d75bc2
Fix test?
alichtman Nov 16, 2019
b1c7deb
Clean up debug statements
alichtman Nov 16, 2019
7b84935
Clean up debug statements
alichtman Nov 16, 2019
59a6aa3
Remove extraneous code
alichtman Nov 16, 2019
91dcb81
Remove extra space
alichtman Nov 17, 2019
455261c
Add test for empty stdin input
alichtman Nov 17, 2019
fce60a3
Remove extra debug line
alichtman Nov 17, 2019
0aee900
Fix test?
alichtman Nov 17, 2019
b793ce5
Fix test?
alichtman Nov 17, 2019
e401242
Update features/core.feature
alichtman Nov 17, 2019
9701401
Fix test?
alichtman Nov 18, 2019
7fbb5db
Fix no stdin input test
alichtman Nov 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions features/core.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ Feature: Basic reading and writing to a journal
When we run "jrnl -n 1"
Then the output should contain "2013-07-23 09:00 A cold and stormy day."

# Note that the expected output is actually "[Nothing saved to file]" but due to mocking limitations, we expect no output here.
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: Filtering for dates
Given we use the config "basic.yaml"
When we run "jrnl -on 2013-06-10 --short"
Expand Down
12 changes: 12 additions & 0 deletions features/data/configs/editor.yaml
Original file line number Diff line number Diff line change
@@ -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: "|"
25 changes: 25 additions & 0 deletions features/steps/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def get_password(self, servicename, username):
def delete_password(self, servicename, username, password):
self.keys[servicename][username] = None


# set the keyring for keyring lib
keyring.set_keyring(TestKeyring())

Expand Down Expand Up @@ -66,6 +67,25 @@ def set_config(context, config_file):
cf.write("version: {}".format(__version__))


@when('we open the editor and enter')
@when('we open the editor and enter "{text}"')
alichtman marked this conversation as resolved.
Show resolved Hide resolved
def open_editor_and_enter(context, text=""):
text = (text or context.text)
print("open_editor_and_enter called")
def _mock_editor_function(command):
print("_mock_editor_function called")
tmpfile = command[-1]
print("TMPFILE:", tmpfile)
with open(tmpfile, "w+") as f:
f.write(text)

print("File contents:", open(tmpfile, "r").read())
return tmpfile

with patch('subprocess.call', side_effect=_mock_editor_function):
run(context, "jrnl")


def _mock_getpass(inputs):
def prompt_return(prompt="Password: "):
print(prompt)
Expand Down Expand Up @@ -182,6 +202,11 @@ def check_json_output_path(context, path, value):
assert struct == value, struct


@then('the output should be empty')
def check_empty_output(context):
assert context.stdout_capture is None


@then('the output should be')
@then('the output should be "{text}"')
def check_output(context, text=None):
Expand Down
2 changes: 1 addition & 1 deletion jrnl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def run(manual_args=None):
if raw:
args.text = [raw]
else:
mode_compose = False
sys.exit()

# This is where we finally open the journal!
try:
Expand Down
2 changes: 2 additions & 0 deletions jrnl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def get_text_from_editor(config, template=""):
os.remove(tmpfile)
if not raw:
print('[Nothing saved to file]', file=sys.stderr)
else:
print("RAW: '" + raw + "'")
return raw


Expand Down