move override implementation into own module

This commit is contained in:
Suhas 2021-01-24 07:17:53 -05:00
parent 1a8bcfca64
commit 9676290c27
3 changed files with 38 additions and 4 deletions

View file

@ -51,10 +51,9 @@ def run(args):
# Apply config overrides # Apply config overrides
overrides = args.config_override overrides = args.config_override
# TODO: substitute overriden KV pairs in config dict ONLY AFTER ADDING TESTS from .override import apply_overrides
for k in overrides: config = apply_overrides(overrides,config)
logging.debug("Overriding %s from %s to %s" % (k, config[k], overrides[k]))
config[k] = overrides[k]
# --- All the standalone commands are now done --- # # --- All the standalone commands are now done --- #
# Get the journal we're going to be working with # Get the journal we're going to be working with

8
jrnl/override.py Normal file
View 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
View 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'