move exception for no alt config to new handling

This commit is contained in:
Jonathan Wren 2022-02-19 17:56:48 -08:00
parent 782adef681
commit 0b160aa845
3 changed files with 17 additions and 10 deletions

View file

@ -71,6 +71,11 @@ class JrnlExceptionMessage(Enum):
https://jrnl.sh/en/stable/external-editors/ https://jrnl.sh/en/stable/external-editors/
""" """
AltConfigNotFound = """
Alternate configuration file not found at the given path:
{config_file}
"""
SomeTest = """ SomeTest = """
Some error or something Some error or something

View file

@ -17,6 +17,9 @@ from .config import verify_config_colors
from .prompt import yesno from .prompt import yesno
from .upgrade import is_old_version from .upgrade import is_old_version
from jrnl.exception import JrnlException
from jrnl.exception import JrnlExceptionMessage
def upgrade_config(config_data, alt_config_path=None): def upgrade_config(config_data, alt_config_path=None):
"""Checks if there are keys missing in a given config dict, and if so, updates the config file accordingly. """Checks if there are keys missing in a given config dict, and if so, updates the config file accordingly.
@ -46,14 +49,12 @@ def find_default_config():
def find_alt_config(alt_config): def find_alt_config(alt_config):
if os.path.exists(alt_config): if not os.path.exists(alt_config):
return alt_config raise JrnlException(
else: JrnlExceptionMessage.AltConfigNotFound, config_file=alt_config
print(
"Alternate configuration file not found at path specified.", file=sys.stderr
) )
print("Exiting.", file=sys.stderr)
sys.exit(1) return alt_config
def load_or_install_jrnl(alt_config_path): def load_or_install_jrnl(alt_config_path):

View file

@ -2,6 +2,7 @@ import pytest
import os import os
from jrnl.install import find_alt_config from jrnl.install import find_alt_config
from jrnl.exception import JrnlException
def test_find_alt_config(request): def test_find_alt_config(request):
@ -14,9 +15,9 @@ def test_find_alt_config(request):
def test_find_alt_config_not_exist(request): def test_find_alt_config_not_exist(request):
bad_config_path = os.path.join( bad_config_path = os.path.join(
request.fspath.dirname, "..", "data", "configs", "not-existing-config.yaml" request.fspath.dirname, "..", "data", "configs", "does-not-exist.yaml"
) )
with pytest.raises(SystemExit) as ex: with pytest.raises(JrnlException) as ex:
found_alt_config = find_alt_config(bad_config_path) found_alt_config = find_alt_config(bad_config_path)
assert found_alt_config is not None assert found_alt_config is not None
assert isinstance(ex.value, SystemExit) assert isinstance(ex.value, JrnlException)