mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-19 20:48:31 +02:00
move override implementation into own module
This commit is contained in:
parent
1a8bcfca64
commit
9676290c27
3 changed files with 38 additions and 4 deletions
|
@ -51,10 +51,9 @@ def run(args):
|
|||
|
||||
# Apply config overrides
|
||||
overrides = args.config_override
|
||||
# TODO: substitute overriden KV pairs in config dict ONLY AFTER ADDING TESTS
|
||||
for k in overrides:
|
||||
logging.debug("Overriding %s from %s to %s" % (k, config[k], overrides[k]))
|
||||
config[k] = overrides[k]
|
||||
from .override import apply_overrides
|
||||
config = apply_overrides(overrides,config)
|
||||
|
||||
# --- All the standalone commands are now done --- #
|
||||
|
||||
# Get the journal we're going to be working with
|
||||
|
|
8
jrnl/override.py
Normal file
8
jrnl/override.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
import logging
|
||||
def apply_overrides(overrides: dict, base_config: dict) -> dict:
|
||||
config = base_config.copy()
|
||||
for k in overrides:
|
||||
logging.debug("Overriding %s from %s to %s" % (k, config[k], overrides[k]))
|
||||
config[k] = overrides[k]
|
||||
|
||||
return config
|
27
tests/test_override.py
Normal file
27
tests/test_override.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import pytest
|
||||
|
||||
import mock
|
||||
|
||||
from jrnl.args import parse_args
|
||||
from jrnl.jrnl import run, search_mode
|
||||
from jrnl import install
|
||||
from jrnl.override import apply_overrides
|
||||
@pytest.fixture()
|
||||
def minimal_config():
|
||||
cfg = {
|
||||
"colors":{
|
||||
"body":"red",
|
||||
"date":"green"
|
||||
},
|
||||
"default":"/tmp/journal.jrnl",
|
||||
"editor":"vim"
|
||||
}
|
||||
yield cfg
|
||||
|
||||
def test_apply_override(minimal_config):
|
||||
config = minimal_config.copy()
|
||||
overrides = {
|
||||
'editor':'nano'
|
||||
}
|
||||
config = apply_overrides(overrides, config)
|
||||
assert config['editor']=='nano'
|
Loading…
Add table
Reference in a new issue