mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Add --config-override feature
* add test and argument handler for runtime override of configurations.
* identify location to apply override in "main"
* update gitignore
* remove unneeded import
* add jrnl interface test for overriden configurations
* trivial whitespace change
* implement runtime override
* make format
* refactor override unittest
* clean up unused import
* start writing integration test
* add linewrap override scenario
* implement editor override step
* add dev dependencies on pytest -mock and -cov
* make format
* remove unused imports
* make format
* rename --override to --config-override
* move override implementation into own module
* begin TDD of dot notated overrides
* rewrite behavior scenario
* implement recursive config overrides
* clean up unittests
* iterate on behave step
* make format
* cleanup
* move override behave tests out of core
* refactor recursive code
* make format
* code cleanup
* remove unused import
* update test config
* rewrite test for better mock call expect
* make format
* binary search misbehaving windows test
* unittest multiple overrides
* uncomment dot notation unittest
* add multiple override scenario spec
* make format
* make format
* update unittests for new syntax
* update integ tests for new syntax
* update gitignore
* guard override application
* deserialize function as return type
* make format
* organize deserialization unittests
* better, more specific behave tests
* test different editor launch commands
* formatting
* handle datatypes in deserialization and update helptext
* stick to config convention in testbed
* update tests ith better verifications
* make format
* space
* review feedbac
* make format
* skip on win
* update deps
* update tests with better verifications
make format
space
review feedbac
* skip on win
* update deps
* refactor deserialization
organize test_parse_args
make format
* skip on win
* refactor deserialization
organize test_parse_args
make format
* update tests ith better verifications
* make format
* space
* make format
* document apply_overrides
* update gitignore
* document config-override enhancement
* Simplify config override syntax (#5)
* update tests and expected behavior
* clean up arg parsing tests
* update deserialization
* update deserialization
* config argparse action
* update override application logic
* update tests; delete unused imports
* override param must be list
* update docstring
* update test input to SUT
* update remaining override unittests
* make format
* forgot to update CLI syntax
* update documentation to sphinx style
* variable renames
* Lockfile merge (#7)
* Add brew and gitter badges to README
* Update changelog [ci skip]
* Make journal selection behavior more consistent when there's a colon with no date (#1164)
* Simplify config override syntax (#8)
* update tests and expected behavior
* clean up arg parsing tests
* update deserialization
* update deserialization
* config argparse action
* update override application logic
* update tests; delete unused imports
* override param must be list
* update docstring
* update test input to SUT
* update remaining override unittests
* make format
* forgot to update CLI syntax
* formatting
* Update pyproject.toml
* update lockfile to remove pytest-cov and pytest-mock deps
* update docs
* reuse existing mock; delete unneeded code
* move overrides earlier in the execution
use existing configs instead of custom
make format
clean up imports
* update for passworded access
context.parser -> parsed_args
* test that no editor is launched
* remove unnecessary mocks
* rename variable for intent
* reinstate getpass deletion
* update gitignore
* capture failure mode
* remove unneeded imports
* renamed variable
* delete redundant step
* comment on step
* clean up step behavior description
* [WIP] lock down journal access behavior
* skip -> wip
* correct command for overriding journal via dot keys
* update wip test for updating a "temp" journal and then reading baack its entries
* remove "mock" from poetry file
* make CI happy
* complex behavior sequence for default journal override
* separate out smaller pieces of logic
test that apply_overrides acts on base configuration and not the copy
* defer modification of loaded configuration to update_config
remove unused fixtures
delete complicated UT since behavior is covered in overrides.feature integ test
delete redundant UT
* Update .gitignore
* remove skip_win
* forward override unpacking to yaml library
* merge config override step with existing config_var step in core
delete config_override step
unify step description syntax
* delete unused and redundant code
* rebases are hard
* remove wip tag from test
* remove skipped tests for windows
* Address code review
yield -> return
remove needless copy
adjust spacing
re-inline args return
reset packaging info to e6c0a16342
revert package version for this PR
* consolidate imports
* Defer config_override unpacking to dict *after* base config is loaded
store cli overrides without unpacking just yet
move deserialize_config_args to config module
delete custom Action class for config operations
apply [k,v] -> {k, v} for each override
update test data
update import
* rename deserialize_config_args to better express intent
make format
77 lines
2.9 KiB
Python
77 lines
2.9 KiB
Python
from jrnl.jrnl import run
|
|
from unittest import mock
|
|
|
|
# from __future__ import with_statement
|
|
from jrnl.args import parse_args
|
|
from behave import then
|
|
|
|
from features.steps.core import _mock_getpass, _mock_time_parse
|
|
|
|
|
|
@then("the editor {editor} should have been called")
|
|
@then("No editor should have been called")
|
|
def editor_override(context, editor=None):
|
|
def _mock_write_in_editor(config):
|
|
editor = config["editor"]
|
|
journal = "features/journals/journal.jrnl"
|
|
context.tmpfile = journal
|
|
print("%s has been launched" % editor)
|
|
return journal
|
|
|
|
if "password" in context:
|
|
password = context.password
|
|
else:
|
|
password = ""
|
|
# fmt: off
|
|
# see: https://github.com/psf/black/issues/664
|
|
with \
|
|
mock.patch("jrnl.jrnl._write_in_editor", side_effect=_mock_write_in_editor(context.jrnl_config)) as mock_write_in_editor, \
|
|
mock.patch("sys.stdin.isatty", return_value=True), \
|
|
mock.patch('getpass.getpass',side_effect=_mock_getpass(password)), \
|
|
mock.patch("jrnl.time.parse", side_effect = _mock_time_parse(context)), \
|
|
mock.patch("jrnl.config.get_config_path", side_effect=lambda: context.config_path), \
|
|
mock.patch("jrnl.install.get_config_path", side_effect=lambda: context.config_path) \
|
|
:
|
|
try :
|
|
parsed_args = parse_args(context.args)
|
|
run(parsed_args)
|
|
context.exit_status = 0
|
|
context.editor = mock_write_in_editor
|
|
expected_config = context.jrnl_config
|
|
expected_config['editor'] = '%s'%editor
|
|
expected_config['journal'] ='features/journals/journal.jrnl'
|
|
|
|
if editor is not None:
|
|
assert mock_write_in_editor.call_count == 1
|
|
assert mock_write_in_editor.call_args[0][0]['editor']==editor
|
|
else:
|
|
# Expect that editor is *never* called
|
|
mock_write_in_editor.assert_not_called()
|
|
except SystemExit as e:
|
|
context.exit_status = e.code
|
|
# fmt: on
|
|
|
|
|
|
@then("the stdin prompt should have been called")
|
|
def override_editor_to_use_stdin(context):
|
|
|
|
try:
|
|
with mock.patch(
|
|
"sys.stdin.read",
|
|
return_value="Zwei peanuts walk into a bar und one of zem was a-salted",
|
|
) as mock_stdin_read, mock.patch(
|
|
"jrnl.install.load_or_install_jrnl", return_value=context.jrnl_config
|
|
), mock.patch(
|
|
"jrnl.Journal.open_journal",
|
|
spec=False,
|
|
return_value="features/journals/journal.jrnl",
|
|
), mock.patch(
|
|
"getpass.getpass", side_effect=_mock_getpass("test")
|
|
):
|
|
parsed_args = parse_args(context.args)
|
|
run(parsed_args)
|
|
context.exit_status = 0
|
|
mock_stdin_read.assert_called_once()
|
|
|
|
except SystemExit as e:
|
|
context.exit_status = e.code
|