fixed name-clash + unit tests

This commit is contained in:
samuelgregorovic 2021-07-06 18:21:38 +02:00
parent 680b942325
commit 240e85d7d5
4 changed files with 34 additions and 3 deletions

View file

@ -0,0 +1,13 @@
default_hour: 9
default_hour: 9
default_minute: 0
editor: noop
template: false
encrypt: false
highlight: true
journals:
default: features/journals/work
linewrap: 80
tagsymbols: '@'
timeformat: '%Y-%m-%d %H:%M'
indent_character: "|"

View file

@ -36,7 +36,7 @@ def upgrade_config(config):
) )
def get_default_config(): def find_default_config():
config_path = ( config_path = (
get_config_path() get_config_path()
if os.path.exists(get_config_path()) if os.path.exists(get_config_path())
@ -45,7 +45,7 @@ def get_default_config():
return config_path return config_path
def get_alt_config(alt_config): def find_alt_config(alt_config):
if os.path.exists(alt_config): if os.path.exists(alt_config):
return alt_config return alt_config
else: else:
@ -62,7 +62,7 @@ def load_or_install_jrnl(alt_config):
If alternate config is specified via --config-file flag, it will be used. If alternate config is specified via --config-file flag, it will be used.
Else, perform various prompts to install jrnl. Else, perform various prompts to install jrnl.
""" """
config_path = get_alt_config(alt_config) if alt_config else get_default_config() config_path = find_alt_config(alt_config) if alt_config else find_default_config()
if os.path.exists(config_path): if os.path.exists(config_path):
logging.debug("Reading configuration from file %s", config_path) logging.debug("Reading configuration from file %s", config_path)

17
tests/test_config_file.py Normal file
View file

@ -0,0 +1,17 @@
import pytest
from jrnl.install import find_alt_config
def test_find_alt_config():
work_config_path = "features/data/configs/work-config.yaml"
found_alt_config = find_alt_config(work_config_path)
assert found_alt_config == work_config_path
def test_find_alt_config_not_exist():
bad_config_path = "features/data/configs/not-existing-config.yaml"
with pytest.raises(SystemExit) as ex:
found_alt_config = find_alt_config(bad_config_path)
assert found_alt_config is not None
assert isinstance(ex.value, SystemExit)

View file

@ -37,6 +37,7 @@ def expected_args(**kwargs):
"tags": False, "tags": False,
"text": [], "text": [],
"config_override": [], "config_override": [],
"config_file_path": "",
} }
return {**default_args, **kwargs} return {**default_args, **kwargs}