From 1df4b74e5314a953fffc138cdaa6b4388da883b9 Mon Sep 17 00:00:00 2001 From: sriniv27 Date: Mon, 8 Feb 2021 20:15:10 -0500 Subject: [PATCH] move overrides earlier in the execution use existing configs instead of custom make format clean up imports --- features/data/configs/tiny.yaml | 8 -------- features/overrides.feature | 21 +++++++++++++-------- features/steps/core.py | 3 ++- features/steps/override.py | 7 ++----- jrnl/jrnl.py | 11 ++++++----- 5 files changed, 23 insertions(+), 27 deletions(-) delete mode 100644 features/data/configs/tiny.yaml diff --git a/features/data/configs/tiny.yaml b/features/data/configs/tiny.yaml deleted file mode 100644 index 578cd234..00000000 --- a/features/data/configs/tiny.yaml +++ /dev/null @@ -1,8 +0,0 @@ -journals: - default: features/journals/simple.journal -colors: - body: none - title: green -editor: "vim" -encrypt: false -# \ No newline at end of file diff --git a/features/overrides.feature b/features/overrides.feature index fec787e3..765c6f23 100644 --- a/features/overrides.feature +++ b/features/overrides.feature @@ -1,7 +1,8 @@ Feature: Implementing Runtime Overrides for Select Configuration Keys Scenario: Override configured editor with built-in input === editor:'' - Given we use the config "tiny.yaml" + Given we use the config "basic_encrypted.yaml" + And we use the password "test" if prompted When we run "jrnl --config-override editor ''" Then the stdin prompt should have been called @@ -11,11 +12,12 @@ Feature: Implementing Runtime Overrides for Select Configuration Keys When we run "jrnl --decrypt --config-override highlight false --config-override editor nano" Then the runtime config should have "encrypt" set to "false" And the runtime config should have "highlight" set to "false" - And the editor "nano" should have been called + And the editor "N/A" should have been called @skip_win Scenario: Override configured linewrap with a value of 23 - Given we use the config "tiny.yaml" + Given we use the config "simple.yaml" + And we use the password "test" if prompted When we run "jrnl -2 --config-override linewrap 23 --format fancy" Then the output should be @@ -37,13 +39,15 @@ Feature: Implementing Runtime Overrides for Select Configuration Keys @skip_win Scenario: Override color selections with runtime overrides - Given we use the config "tiny.yaml" + Given we use the config "basic_encrypted.yaml" + And we use the password "test" if prompted When we run "jrnl -1 --config-override colors.body blue" Then the runtime config should have colors.body set to blue @skip_win Scenario: Apply multiple config overrides - Given we use the config "tiny.yaml" + Given we use the config "basic_encrypted.yaml" + And we use the password "test" if prompted When we run "jrnl -1 --config-override colors.body green --config-override editor 'nano'" Then the runtime config should have colors.body set to green And the runtime config should have editor set to nano @@ -51,11 +55,12 @@ Feature: Implementing Runtime Overrides for Select Configuration Keys @skip_win Scenario Outline: Override configured editor - Given we use the config "tiny.yaml" - When we run "jrnl --config-override editor \"\"" + Given we use the config "basic_encrypted.yaml" + And we use the password "test" if prompted + When we run "jrnl --config-override editor ''" Then the editor should have been called Examples: Editor Commands | editor | | nano | | vi -c startinsert | - | code -w - | + | code -w | diff --git a/features/steps/core.py b/features/steps/core.py index 1040d854..b457894e 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -400,13 +400,14 @@ def run(context, command, text=""): if "cache_dir" in context and context.cache_dir is not None: cache_dir = os.path.join("features", "cache", context.cache_dir) command = command.format(cache_dir=cache_dir) - if "config_path" in context and context.config_path is not None: + if "config_path" in context and context.config_path is not None: with open(context.config_path, "r") as f: cfg = yaml.load(f, Loader=FullLoader) context.jrnl_config = cfg args = split_args(command) context.args = args[1:] + def _mock_editor(command): context.editor_command = command tmpfile = command[-1] diff --git a/features/steps/override.py b/features/steps/override.py index 766bea77..404c9bfb 100644 --- a/features/steps/override.py +++ b/features/steps/override.py @@ -1,17 +1,14 @@ from jrnl.jrnl import run -from jrnl.os_compat import split_args from unittest import mock # from __future__ import with_statement from jrnl.args import parse_args import os -from behave import given, when, then -import yaml -from yaml.loader import FullLoader +from behave import given, then import jrnl -from features.steps.core import _mock_time_parse +from features.steps.core import _mock_getpass, _mock_time_parse @given("we use the config {config_file}") diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 25fd191a..383cceee 100644 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -38,6 +38,12 @@ def run(args): try: config = install.load_or_install_jrnl() original_config = config.copy() + + # Apply config overrides + overrides = args.config_override + if overrides: + config = apply_overrides(overrides, config) + args = get_journal_name(args, config) config = scope_config(config, args.journal_name) except UserAbort as err: @@ -50,11 +56,6 @@ def run(args): args=args, config=config, original_config=original_config ) - # Apply config overrides - overrides = args.config_override - if overrides: - config = apply_overrides(overrides, config) - # --- All the standalone commands are now done --- # # Get the journal we're going to be working with