mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 11:38:32 +02:00
move exception for no alt config to new handling
This commit is contained in:
parent
782adef681
commit
0b160aa845
3 changed files with 17 additions and 10 deletions
|
@ -71,6 +71,11 @@ class JrnlExceptionMessage(Enum):
|
|||
https://jrnl.sh/en/stable/external-editors/
|
||||
"""
|
||||
|
||||
AltConfigNotFound = """
|
||||
Alternate configuration file not found at the given path:
|
||||
{config_file}
|
||||
"""
|
||||
|
||||
SomeTest = """
|
||||
Some error or something
|
||||
|
||||
|
|
|
@ -17,6 +17,9 @@ from .config import verify_config_colors
|
|||
from .prompt import yesno
|
||||
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):
|
||||
"""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):
|
||||
if os.path.exists(alt_config):
|
||||
return alt_config
|
||||
else:
|
||||
print(
|
||||
"Alternate configuration file not found at path specified.", file=sys.stderr
|
||||
if not os.path.exists(alt_config):
|
||||
raise JrnlException(
|
||||
JrnlExceptionMessage.AltConfigNotFound, config_file=alt_config
|
||||
)
|
||||
print("Exiting.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
return alt_config
|
||||
|
||||
|
||||
def load_or_install_jrnl(alt_config_path):
|
||||
|
|
|
@ -2,6 +2,7 @@ import pytest
|
|||
import os
|
||||
|
||||
from jrnl.install import find_alt_config
|
||||
from jrnl.exception import JrnlException
|
||||
|
||||
|
||||
def test_find_alt_config(request):
|
||||
|
@ -14,9 +15,9 @@ def test_find_alt_config(request):
|
|||
|
||||
def test_find_alt_config_not_exist(request):
|
||||
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)
|
||||
assert found_alt_config is not None
|
||||
assert isinstance(ex.value, SystemExit)
|
||||
assert isinstance(ex.value, JrnlException)
|
||||
|
|
Loading…
Add table
Reference in a new issue