From 18cd48003bdb4a29d5a4a5cc4e37a1b7eed36f1a Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Fri, 16 Apr 2021 22:40:42 -0400 Subject: [PATCH] fix: make user_interface configuration optional --- src/plotman/_tests/configuration_test.py | 15 +++++++++++++++ src/plotman/configuration.py | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/plotman/_tests/configuration_test.py b/src/plotman/_tests/configuration_test.py index 2f197efa..0be0c990 100644 --- a/src/plotman/_tests/configuration_test.py +++ b/src/plotman/_tests/configuration_test.py @@ -50,3 +50,18 @@ def test_get_validated_configs__missing(mocker, config_path): f"No 'plotman.yaml' file exists at expected location: '{nonexistent_config}'. To generate " f"default config file, run: 'plotman config generate'" ) + + +def test_loads_without_user_interface(mocker, config_path, tmp_path): + with open(config_path, "r") as file: + loaded_yaml = yaml.load(file, Loader=yaml.SafeLoader) + + del loaded_yaml["user_interface"] + + temporary_configuration_path = tmp_path.joinpath("config.yaml") + temporary_configuration_path.write_text(yaml.safe_dump(loaded_yaml)) + + mocker.patch("plotman.configuration.get_path", return_value=temporary_configuration_path) + reloaded_yaml = configuration.get_validated_configs() + + assert reloaded_yaml.user_interface == configuration.UserInterface() diff --git a/src/plotman/configuration.py b/src/plotman/configuration.py index e8eaa905..4efbfac6 100644 --- a/src/plotman/configuration.py +++ b/src/plotman/configuration.py @@ -1,4 +1,4 @@ -from dataclasses import dataclass +from dataclasses import dataclass, field from typing import Dict, List, Optional import appdirs @@ -82,11 +82,11 @@ class Plotting: @dataclass class UserInterface: - use_stty_size: bool + use_stty_size: bool = True @dataclass class PlotmanConfig: - user_interface: UserInterface directories: Directories scheduling: Scheduling plotting: Plotting + user_interface: UserInterface = field(default_factory=UserInterface)