mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 04:58:32 +02:00
begin TDD of dot notated overrides
This commit is contained in:
parent
9676290c27
commit
80d2c609ba
4 changed files with 41 additions and 9 deletions
|
@ -2,12 +2,12 @@ Feature: Implementing Runtime Overrides for Select Configuration Keys
|
||||||
|
|
||||||
Scenario: Override configured editor with built-in input === editor:''
|
Scenario: Override configured editor with built-in input === editor:''
|
||||||
Given we use the config "editor-args.yaml"
|
Given we use the config "editor-args.yaml"
|
||||||
When we run "jrnl --config-override '{\"editor\": \"\""}'"
|
When we run "jrnl --config-override '{"editor": """}'"
|
||||||
Then the editor "" should have been called
|
Then the editor "" should have been called
|
||||||
|
|
||||||
Scenario: Override configured editor with 'nano'
|
Scenario: Override configured editor with 'nano'
|
||||||
Given we use the config "editor.yaml"
|
Given we use the config "editor.yaml"
|
||||||
When we run "jrnl --config-override '{\"editor\": \"nano\"}'"
|
When we run "jrnl --config-override '{"editor": "nano"}'"
|
||||||
Then the editor "nano" should have been called
|
Then the editor "nano" should have been called
|
||||||
|
|
||||||
Scenario: Override configured linewrap with a value of 23
|
Scenario: Override configured linewrap with a value of 23
|
||||||
|
@ -28,4 +28,12 @@ Then the output should be
|
||||||
┠╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
┠╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
||||||
┃ But I'm better. │
|
┃ But I'm better. │
|
||||||
┖─────────────────────┘
|
┖─────────────────────┘
|
||||||
|
"""
|
||||||
|
|
||||||
|
Scenario: Override color selections with runtime overrides
|
||||||
|
Given we use the config "no_colors.yaml"
|
||||||
|
When we run "jrnl --config-override '{"colors.body": "blue"}'"
|
||||||
|
Then the config should have "colors" set to
|
||||||
|
"""
|
||||||
|
'body': 'blue'
|
||||||
"""
|
"""
|
10
jrnl/args.py
10
jrnl/args.py
|
@ -315,11 +315,11 @@ def parse_args(args=[]):
|
||||||
help=argparse.SUPPRESS,
|
help=argparse.SUPPRESS,
|
||||||
)
|
)
|
||||||
|
|
||||||
overrides = parser.add_argument_group(
|
config_overrides = parser.add_argument_group(
|
||||||
"Config file overrides",
|
"Config file overrides",
|
||||||
textwrap.dedent("These are one-off overrides of the config file options"),
|
textwrap.dedent("These are one-off overrides of the config file options"),
|
||||||
)
|
)
|
||||||
overrides.add_argument(
|
config_overrides.add_argument(
|
||||||
"--config-override",
|
"--config-override",
|
||||||
dest="config_override",
|
dest="config_override",
|
||||||
action="store",
|
action="store",
|
||||||
|
@ -330,9 +330,11 @@ def parse_args(args=[]):
|
||||||
help="""
|
help="""
|
||||||
Override configured key-value pairs with CONFIG_KV_PAIR for this command invocation only.
|
Override configured key-value pairs with CONFIG_KV_PAIR for this command invocation only.
|
||||||
|
|
||||||
For example, to use a different editor for this jrnl entry, call:
|
Examples:
|
||||||
|
- Use a different editor for this jrnl entry, call:
|
||||||
jrnl --config-override '{"editor": "nano"}'
|
jrnl --config-override '{"editor": "nano"}'
|
||||||
|
- Override color selections
|
||||||
|
jrnl --config-override '{"colors.body":"blue", "colors.title": "green"}
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import mock
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from jrnl.args import parse_args
|
from jrnl.args import parse_args
|
||||||
from jrnl.jrnl import run
|
from jrnl.jrnl import run, search_mode
|
||||||
from jrnl import install
|
from jrnl import install
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ def test_override_configured_editor(
|
||||||
cli_args = ["--config-override", '{"editor": "nano"}']
|
cli_args = ["--config-override", '{"editor": "nano"}']
|
||||||
parser = parse_args(cli_args)
|
parser = parse_args(cli_args)
|
||||||
assert parser.config_override.__len__() == 1
|
assert parser.config_override.__len__() == 1
|
||||||
|
assert "editor" in parser.config_override.keys()
|
||||||
def mock_editor_launch(editor):
|
def mock_editor_launch(editor):
|
||||||
print("%s launched! Success!" % editor)
|
print("%s launched! Success!" % editor)
|
||||||
|
|
||||||
|
@ -55,3 +55,22 @@ def test_override_configured_editor(
|
||||||
) as mock_write_in_editor:
|
) as mock_write_in_editor:
|
||||||
run(parser)
|
run(parser)
|
||||||
mock_write_in_editor.assert_called_once_with(expected_override)
|
mock_write_in_editor.assert_called_once_with(expected_override)
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def expected_color_override(minimal_config):
|
||||||
|
exp_out_cfg = minimal_config.copy()
|
||||||
|
exp_out_cfg["colors"] = {"body": "blue"}
|
||||||
|
exp_out_cfg["journal"] = "features/journals/simple.journal"
|
||||||
|
yield exp_out_cfg
|
||||||
|
|
||||||
|
# @mock.patch.object(install,'load_or_install_jrnl')
|
||||||
|
# @mock.patch('subprocess.call')
|
||||||
|
# def test_override_configured_colors(mock_load_or_install, mock_subprocess_call, minimal_config, expected_color_override, capsys):
|
||||||
|
# mock_load_or_install.return_value = minimal_config
|
||||||
|
|
||||||
|
# cli_args=["--config-override",'{"colors.body": "blue"}']
|
||||||
|
# parser = parse_args(cli_args)
|
||||||
|
# assert "colors.body" in parser.config_override.keys()
|
||||||
|
# run(parser)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,10 @@ def test_editor_override():
|
||||||
assert cli_as_dict('--config-override \'{"editor": "nano"}\'') == expected_args(
|
assert cli_as_dict('--config-override \'{"editor": "nano"}\'') == expected_args(
|
||||||
config_override={"editor": "nano"}
|
config_override={"editor": "nano"}
|
||||||
)
|
)
|
||||||
|
def test_color_override():
|
||||||
|
assert cli_as_dict('--config-override \'{"colors.body": "blue"}\'') == expected_args(
|
||||||
|
config_override={"colors.body":"blue"}
|
||||||
|
)
|
||||||
|
|
||||||
# @see https://github.com/jrnl-org/jrnl/issues/520
|
# @see https://github.com/jrnl-org/jrnl/issues/520
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
Loading…
Add table
Reference in a new issue