mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-28 05:26:13 +02:00
Add new -today-in-history
, -month
, -day
, and -year
search filters (#1145)
* Introduce -reminisce, -month, -day, and -year * Update expected_args in parse_args tests * Add check before creating compare_d * Misc changes * Implement testing for -month, -day, -year, and -reminisce * Compress tests into one Scenario Outline * Fix failing tests by updating dates_similar journal * Create 'we set current date and time to' step * Use time.parse in reminisce * Update dates_similar journal * Make 'Searching in a journal' test shorter * Lint * Implement reminiscing test * Add combination tests * Finalize tests * Finalize pytests * Simplify reminisce tests * Change reminsice help (since it also shows today's entries) * Re-do tests; use various tests * Remove old test data * Better scenario description * Standardize format for compare_d * Rename -reminisce to -today-in-history
This commit is contained in:
parent
18058c74e5
commit
f0e8fa2060
6 changed files with 184 additions and 0 deletions
|
@ -214,6 +214,96 @@ Feature: Searching in a journal
|
|||
| But I'm better.
|
||||
"""
|
||||
|
||||
Scenario Outline: Searching by month
|
||||
Given we use the config "<config>.yaml"
|
||||
And we use the password "test" if prompted
|
||||
When we run "jrnl -month 9 --short"
|
||||
Then the output should be "2020-09-24 09:14 The third entry finally after weeks without writing."
|
||||
And we flush the output
|
||||
When we run "jrnl -month Sept --short"
|
||||
Then the output should be "2020-09-24 09:14 The third entry finally after weeks without writing."
|
||||
And we flush the output
|
||||
When we run "jrnl -month September --short"
|
||||
Then the output should be "2020-09-24 09:14 The third entry finally after weeks without writing."
|
||||
|
||||
Examples: configs
|
||||
| config |
|
||||
| basic_onefile |
|
||||
| basic_encrypted |
|
||||
| basic_folder |
|
||||
| basic_dayone |
|
||||
|
||||
Scenario Outline: Searching by day
|
||||
Given we use the config "<config>.yaml"
|
||||
And we use the password "test" if prompted
|
||||
When we run "jrnl -day 31 --short"
|
||||
Then the output should be "2020-08-31 14:32 A second entry in what I hope to be a long series."
|
||||
|
||||
Examples: configs
|
||||
| config |
|
||||
| basic_onefile |
|
||||
| basic_encrypted |
|
||||
| basic_folder |
|
||||
| basic_dayone |
|
||||
|
||||
Scenario Outline: Searching by year
|
||||
Given we use the config "<config>.yaml"
|
||||
And we use the password "test" if prompted
|
||||
When we run "jrnl 2019-01-01 01:01: I like this year."
|
||||
And we run "jrnl -year 2019 --short"
|
||||
Then the output should be "2019-01-01 01:01 I like this year."
|
||||
And we flush the output
|
||||
When we run "jrnl -year 19 --short"
|
||||
Then the output should be "2019-01-01 01:01 I like this year."
|
||||
|
||||
Examples: configs
|
||||
| config |
|
||||
| basic_onefile |
|
||||
| basic_encrypted |
|
||||
| basic_folder |
|
||||
| basic_dayone |
|
||||
|
||||
Scenario Outline: Combining month, day, and year search terms
|
||||
Given we use the config "<config>.yaml"
|
||||
And we use the password "test" if prompted
|
||||
When we run "jrnl -month 08 -day 29 --short"
|
||||
Then the output should be "2020-08-29 11:11 Entry the first."
|
||||
And we flush the output
|
||||
When we run "jrnl -day 29 -year 2020 --short"
|
||||
Then the output should be "2020-08-29 11:11 Entry the first."
|
||||
And we flush the output
|
||||
When we run "jrnl -month 09 -year 2020 --short"
|
||||
Then the output should be "2020-09-24 09:14 The third entry finally after weeks without writing."
|
||||
And we flush the output
|
||||
When we run "jrnl -month 08 -day 29 -year 2020 --short"
|
||||
Then the output should be "2020-08-29 11:11 Entry the first."
|
||||
|
||||
Examples: configs
|
||||
| config |
|
||||
| basic_onefile |
|
||||
| basic_encrypted |
|
||||
| basic_folder |
|
||||
| basic_dayone |
|
||||
|
||||
Scenario Outline: Searching today in history
|
||||
Given we use the config "<config>.yaml"
|
||||
And we use the password "test" if prompted
|
||||
And we set current date and time to "2020-08-31 14:32"
|
||||
When we run "jrnl 2019-08-31 01:01: Hi, from last year."
|
||||
And we run "jrnl -today-in-history --short"
|
||||
Then the output should be
|
||||
"""
|
||||
2019-08-31 01:01 Hi, from last year.
|
||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||
"""
|
||||
|
||||
Examples: configs
|
||||
| config |
|
||||
| basic_onefile |
|
||||
| basic_encrypted |
|
||||
| basic_folder |
|
||||
| basic_dayone |
|
||||
|
||||
Scenario: Loading a DayOne Journal
|
||||
Given we use the config "dayone.yaml"
|
||||
When we run "jrnl -from 'feb 2013'"
|
||||
|
|
|
@ -17,6 +17,7 @@ import keyring
|
|||
import toml
|
||||
import yaml
|
||||
|
||||
import jrnl.time
|
||||
from jrnl import Journal
|
||||
from jrnl import __version__
|
||||
from jrnl import plugins
|
||||
|
@ -159,6 +160,11 @@ def disable_keyring(context):
|
|||
keyring.core.set_keyring(NoKeyring())
|
||||
|
||||
|
||||
@given('we set current date and time to "{dt}"')
|
||||
def set_datetime(context, dt):
|
||||
context.now = dt
|
||||
|
||||
|
||||
@when('we change directory to "{path}"')
|
||||
def move_up_dir(context, path):
|
||||
os.chdir(path)
|
||||
|
@ -197,6 +203,7 @@ def open_editor_and_enter(context, method, text=""):
|
|||
patch("subprocess.call", side_effect=_mock_editor) as mock_editor, \
|
||||
patch("getpass.getpass", side_effect=_mock_getpass(password)) as mock_getpass, \
|
||||
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) \
|
||||
:
|
||||
|
@ -289,6 +296,18 @@ def _mock_input(inputs):
|
|||
return prompt_return
|
||||
|
||||
|
||||
def _mock_time_parse(context):
|
||||
original_parse = jrnl.time.parse
|
||||
if "now" not in context:
|
||||
return original_parse
|
||||
|
||||
def wrapper(input, *args, **kwargs):
|
||||
input = context.now if input == "now" else input
|
||||
return original_parse(input, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
@when('we run "{command}" and enter')
|
||||
@when('we run "{command}" and enter nothing')
|
||||
@when('we run "{command}" and enter "{inputs}"')
|
||||
|
@ -322,6 +341,7 @@ def run_with_input(context, command, inputs=""):
|
|||
patch("getpass.getpass", side_effect=_mock_getpass(password)) as mock_getpass, \
|
||||
patch("sys.stdin.read", side_effect=text) as mock_read, \
|
||||
patch("subprocess.call", side_effect=_mock_editor) as mock_editor, \
|
||||
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) \
|
||||
:
|
||||
|
@ -406,6 +426,7 @@ def run(context, command, text=""):
|
|||
patch("getpass.getpass", side_effect=_mock_getpass(password)) as mock_getpass, \
|
||||
patch("subprocess.call", side_effect=_mock_editor) as mock_editor, \
|
||||
patch("sys.stdin.read", side_effect=lambda: text), \
|
||||
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) \
|
||||
:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue