mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-30 22:46:12 +02:00
Merge develop to on-today-bug-741
This commit is contained in:
commit
f633a93aab
14 changed files with 329 additions and 29 deletions
|
@ -20,6 +20,19 @@ 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."
|
||||
|
||||
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
|
||||
Given we use the config "basic.yaml"
|
||||
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: "|"
|
76
features/dayone.feature
Normal file
76
features/dayone.feature
Normal file
|
@ -0,0 +1,76 @@
|
|||
Feature: Dayone specific implementation details.
|
||||
|
||||
# fails when system time is UTC (as on Travis-CI)
|
||||
@skip
|
||||
Scenario: Loading a DayOne Journal
|
||||
Given we use the config "dayone.yaml"
|
||||
When we run "jrnl -from 'feb 2013'"
|
||||
Then we should get no error
|
||||
and the output should be
|
||||
"""
|
||||
2013-05-17 11:39 This entry has tags!
|
||||
|
||||
2013-06-17 20:38 This entry has a location.
|
||||
|
||||
2013-07-17 11:38 This entry is starred!
|
||||
"""
|
||||
|
||||
# fails when system time is UTC (as on Travis-CI)
|
||||
@skip
|
||||
Scenario: Entries without timezone information will be interpreted as in the current timezone
|
||||
Given we use the config "dayone.yaml"
|
||||
When we run "jrnl -until 'feb 2013'"
|
||||
Then we should get no error
|
||||
and the output should contain "2013-01-17T18:37Z" in the local time
|
||||
|
||||
@skip
|
||||
Scenario: Writing into Dayone
|
||||
Given we use the config "dayone.yaml"
|
||||
When we run "jrnl 01 may 1979: Being born hurts."
|
||||
and we run "jrnl -until 1980"
|
||||
Then the output should be
|
||||
"""
|
||||
1979-05-01 09:00 Being born hurts.
|
||||
"""
|
||||
|
||||
# fails when system time is UTC (as on Travis-CI)
|
||||
@skip
|
||||
Scenario: Loading tags from a DayOne Journal
|
||||
Given we use the config "dayone.yaml"
|
||||
When we run "jrnl --tags"
|
||||
Then the output should be
|
||||
"""
|
||||
@work : 1
|
||||
@play : 1
|
||||
"""
|
||||
|
||||
# fails when system time is UTC (as on Travis-CI)
|
||||
@skip
|
||||
Scenario: Saving tags from a DayOne Journal
|
||||
Given we use the config "dayone.yaml"
|
||||
When we run "jrnl A hard day at @work"
|
||||
and we run "jrnl --tags"
|
||||
Then the output should be
|
||||
"""
|
||||
@work : 2
|
||||
@play : 1
|
||||
"""
|
||||
|
||||
# fails when system time is UTC (as on Travis-CI)
|
||||
@skip
|
||||
Scenario: Filtering by tags from a DayOne Journal
|
||||
Given we use the config "dayone.yaml"
|
||||
When we run "jrnl @work"
|
||||
Then the output should be
|
||||
"""
|
||||
2013-05-17 11:39 This entry has tags!
|
||||
"""
|
||||
|
||||
# fails when system time is UTC (as on Travis-CI)
|
||||
@skip
|
||||
Scenario: Exporting dayone to json
|
||||
Given we use the config "dayone.yaml"
|
||||
When we run "jrnl --export json"
|
||||
Then we should get no error
|
||||
and the output should be parsable as json
|
||||
and the json output should contain entries.0.uuid = "4BB1F46946AD439996C9B59DE7C4DDC1"
|
31
features/dayone_regressions.feature
Normal file
31
features/dayone_regressions.feature
Normal file
|
@ -0,0 +1,31 @@
|
|||
Feature: Zapped Dayone bugs stay dead!
|
||||
|
||||
# fails when system time is UTC (as on Travis-CI)
|
||||
@skip
|
||||
Scenario: DayOne tag searching should work with tags containing a mixture of upper and lower case.
|
||||
# https://github.com/jrnl-org/jrnl/issues/354
|
||||
Given we use the config "dayone.yaml"
|
||||
When we run "jrnl @plAy"
|
||||
Then the output should contain
|
||||
"""
|
||||
2013-05-17 11:39 This entry has tags!
|
||||
"""
|
||||
|
||||
# fails when system time is UTC (as on Travis-CI)
|
||||
@skip
|
||||
Scenario: Title with an embedded period on DayOne journal
|
||||
Given we use the config "dayone.yaml"
|
||||
When we run "jrnl 04-24-2014: "Ran 6.2 miles today in 1:02:03. I'm feeling sore because I forgot to stretch.""
|
||||
Then we should see the message "Entry added"
|
||||
When we run "jrnl -1"
|
||||
Then the output should be
|
||||
"""
|
||||
2014-04-24 09:00 Ran 6.2 miles today in 1:02:03.
|
||||
| I'm feeling sore because I forgot to stretch.
|
||||
"""
|
||||
|
||||
Scenario: Opening an folder that's not a DayOne folder gives a nice error message
|
||||
Given we use the config "empty_folder.yaml"
|
||||
When we run "jrnl Herro"
|
||||
Then we should get an error
|
||||
Then we should see the message "is a directory, but doesn't seem to be a DayOne journal either"
|
|
@ -2,6 +2,14 @@ import shutil
|
|||
import os
|
||||
|
||||
|
||||
def before_feature(context, feature):
|
||||
# add "skip" tag
|
||||
# https://stackoverflow.com/a/42721605/4276230
|
||||
if "skip" in feature.tags:
|
||||
feature.skip("Marked with @skip")
|
||||
return
|
||||
|
||||
|
||||
def before_scenario(context, scenario):
|
||||
"""Before each scenario, backup all config and journal test data."""
|
||||
# Clean up in case something went wrong
|
||||
|
@ -22,6 +30,12 @@ def before_scenario(context, scenario):
|
|||
else:
|
||||
shutil.copy2(source, working_dir)
|
||||
|
||||
# add "skip" tag
|
||||
# https://stackoverflow.com/a/42721605/4276230
|
||||
if "skip" in scenario.effective_tags:
|
||||
scenario.skip("Marked with @skip")
|
||||
return
|
||||
|
||||
|
||||
def after_scenario(context, scenario):
|
||||
"""After each scenario, restore all test data and remove working_dirs."""
|
||||
|
|
|
@ -69,3 +69,50 @@ Feature: Zapped bugs should stay dead.
|
|||
Then the output should not contain "Life is good"
|
||||
Then the output should not contain "But I'm better."
|
||||
|
||||
Scenario: Create entry using day of the week as entry date.
|
||||
Given we use the config "basic.yaml"
|
||||
When we run "jrnl monday: This is an entry on a Monday."
|
||||
Then we should see the message "Entry added"
|
||||
When we run "jrnl -1"
|
||||
Then the output should contain "monday at 9am" in the local time
|
||||
Then the output should contain "This is an entry on a Monday."
|
||||
|
||||
Scenario: Create entry using day of the week abbreviations as entry date.
|
||||
Given we use the config "basic.yaml"
|
||||
When we run "jrnl fri: This is an entry on a Friday."
|
||||
Then we should see the message "Entry added"
|
||||
When we run "jrnl -1"
|
||||
Then the output should contain "friday at 9am" in the local time
|
||||
|
||||
Scenario: Displaying entries using -on today should display entries created today.
|
||||
Given we use the config "basic.yaml"
|
||||
When we run "jrnl today: Adding an entry right now."
|
||||
Then we should see the message "Entry added"
|
||||
When we run "jrnl -on today"
|
||||
Then the output should contain "Adding an entry right now."
|
||||
|
||||
Scenario: Displaying entries using -from day should display correct entries
|
||||
Given we use the config "basic.yaml"
|
||||
When we run "jrnl yesterday: This thing happened yesterday"
|
||||
Then we should see the message "Entry added"
|
||||
When we run "jrnl today at 11:59pm: Adding an entry right now."
|
||||
Then we should see the message "Entry added"
|
||||
When we run "jrnl tomorrow: A future entry."
|
||||
Then we should see the message "Entry added"
|
||||
When we run "jrnl -from today"
|
||||
Then the output should contain "Adding an entry right now."
|
||||
Then the output should contain "A future entry."
|
||||
Then the output should not contain "This thing happened yesterday"
|
||||
|
||||
Scenario: Displaying entries using -from and -to day should display correct entries
|
||||
Given we use the config "basic.yaml"
|
||||
When we run "jrnl yesterday: This thing happened yesterday"
|
||||
Then we should see the message "Entry added"
|
||||
When we run "jrnl today at 11:59pm: Adding an entry right now."
|
||||
Then we should see the message "Entry added"
|
||||
When we run "jrnl tomorrow: A future entry."
|
||||
Then we should see the message "Entry added"
|
||||
When we run "jrnl -from yesterday -to today"
|
||||
Then the output should contain "This thing happened yesterday"
|
||||
Then the output should contain "Adding an entry right now."
|
||||
Then the output should not contain "A future entry."
|
||||
|
|
|
@ -5,6 +5,9 @@ from jrnl import cli, install, Journal, util, plugins
|
|||
from jrnl import __version__
|
||||
from dateutil import parser as date_parser
|
||||
from collections import defaultdict
|
||||
try: import parsedatetime.parsedatetime_consts as pdt
|
||||
except ImportError: import parsedatetime as pdt
|
||||
import time
|
||||
import os
|
||||
import json
|
||||
import yaml
|
||||
|
@ -13,6 +16,10 @@ import tzlocal
|
|||
import shlex
|
||||
import sys
|
||||
|
||||
consts = pdt.Constants(usePyICU=False)
|
||||
consts.DOWParseStyle = -1 # Prefers past weekdays
|
||||
CALENDAR = pdt.Calendar(consts)
|
||||
|
||||
|
||||
class TestKeyring(keyring.backend.KeyringBackend):
|
||||
"""A test keyring that just stores its values in a hash"""
|
||||
|
@ -29,6 +36,7 @@ class TestKeyring(keyring.backend.KeyringBackend):
|
|||
def delete_password(self, servicename, username, password):
|
||||
self.keys[servicename][username] = None
|
||||
|
||||
|
||||
# set the keyring for keyring lib
|
||||
keyring.set_keyring(TestKeyring())
|
||||
|
||||
|
@ -66,6 +74,24 @@ 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}"')
|
||||
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 prompt_return(prompt="Password: "):
|
||||
print(prompt)
|
||||
|
@ -82,12 +108,18 @@ def _mock_input(inputs):
|
|||
|
||||
|
||||
@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}" and "{inputs2}"')
|
||||
def run_with_input(context, command, inputs1="", inputs2=""):
|
||||
# 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()'
|
||||
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:]
|
||||
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:
|
||||
|
@ -196,9 +228,9 @@ def check_output(context, text=None):
|
|||
def check_output_time_inline(context, text):
|
||||
out = context.stdout_capture.getvalue()
|
||||
local_tz = tzlocal.get_localzone()
|
||||
utc_time = date_parser.parse(text)
|
||||
local_date = utc_time.astimezone(local_tz).strftime("%Y-%m-%d %H:%M")
|
||||
assert local_date in out, local_date
|
||||
date, flag = CALENDAR.parse(text)
|
||||
output_date = time.strftime("%Y-%m-%d %H:%M",date)
|
||||
assert output_date in out, output_date
|
||||
|
||||
|
||||
@then('the output should contain')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue