Fix incorrect path logic for default YAML location

pull/5/head
Robert Dailey 4 years ago
parent 30a9bd4018
commit f128939f57

@ -9,12 +9,12 @@ def find_profile_by_name(config, profile_type):
return None
# --------------------------------------------------------------------------------------------------
def load_config(args, logger):
def load_config(args, logger, default_load_path: Path):
if args.config_file:
config_path = Path(args.config_file)
else:
# Look for `trash.yml` in the same directory as the main (entrypoint) python script.
config_path = Path(__name__).parent / 'trash.yml'
config_path = default_load_path / 'trash.yml'
logger.debug(f'Using configuration file: {config_path}')
@ -28,6 +28,8 @@ def load_config(args, logger):
# --------------------------------------------------------------------------------------------------
def load_config_string(args, logger, config_yaml):
config = yaml.load(config_yaml, Loader=yaml.Loader)
if not config:
return
server_name, type_name = args.type.split(':')
server_config = config[server_name]
@ -43,4 +45,4 @@ def load_config_string(args, logger, config_yaml):
if profile:
if args.tags is None:
args.tags = []
args.tags.extend(t for t in profile['tags'] if t not in args.tags)
args.tags.extend(t for t in profile['tags'] if t not in args.tags)

@ -1,9 +1,29 @@
from inspect import cleandoc
from pathlib import Path
from app import cmd
from app.logic import config
from tests.mock_logger import MockLogger
def test_config_load_from_file_default(mocker):
mock_open = mocker.patch('app.logic.config.open', mocker.mock_open(read_data=''))
mocker.patch.object(Path, 'exists', return_value=True)
args = cmd.setup_and_parse_args(['profile', 'sonarr:anime'])
default_root = Path(__file__).parent
config.load_config(args, MockLogger(), default_root)
mock_open.assert_called_once_with(default_root / 'trash.yml', 'r')
def test_config_load_from_file_args(mocker):
mock_open = mocker.patch('app.logic.config.open', mocker.mock_open(read_data=''))
mocker.patch.object(Path, 'exists', return_value=True)
expected_yml_path = Path(__file__).parent.parent / 'overridden_config.yml'
args = cmd.setup_and_parse_args(['profile', 'sonarr:anime', '--config-file', str(expected_yml_path)])
config.load_config(args, MockLogger(), '.')
mock_open.assert_called_once_with(expected_yml_path, 'r')
def test_config_tags():
yaml = cleandoc('''

@ -1,15 +1,16 @@
from pathlib import Path
from app.logic import sonarr, config
from app.cmd import setup_and_parse_args
from app.logger import Logger
from app.trash_error import TrashError
# --------------------------------------------------------------------------------------------------
def main():
args = setup_and_parse_args()
logger = Logger(args)
config.load_config(args, logger)
config.load_config(args, logger, Path(__file__).parent)
if args.subcommand == 'profile':
if args.type.startswith('sonarr:'):

Loading…
Cancel
Save