When loading invalid config, wrap exceptions with OvgenError

Fix unit test (switching to OvgenError)
pull/357/head
nyanpasu64 2018-12-13 06:58:45 -08:00
rodzic b352d2bf8e
commit 027ba504bd
2 zmienionych plików z 13 dodań i 6 usunięć

Wyświetl plik

@ -303,9 +303,16 @@ def default_property(path: str, default):
return property(getter, setter)
def adapter_property(path: str, adapter: Callable[[Any], Any]):
def color2hex_property(path: str):
def getter(self: 'ConfigModel'):
return adapter(rgetattr(self.cfg, path))
color_attr = rgetattr(self.cfg, path)
try:
return color2hex(color_attr)
except ValueError:
raise OvgenError(f'invalid config color {color_attr}')
except Exception as e:
raise OvgenError(
f'doubly invalid config color {color_attr}, raises {e} (report bug!)')
def setter(self: 'ConfigModel', val: int):
rsetattr(self.cfg, path, val)
@ -318,8 +325,8 @@ class ConfigModel(PresentationModel):
combo_symbols = {}
combo_text = {}
render__bg_color = adapter_property('render__bg_color', color2hex)
render__init_line_color = adapter_property('render__init_line_color', color2hex)
render__bg_color = color2hex_property('render__bg_color')
render__init_line_color = color2hex_property('render__init_line_color')
@property
def render_video_size(self) -> str:

Wyświetl plik

@ -1,7 +1,7 @@
import pytest
from ruamel.yaml import yaml_object
from ovgenpy.config import register_config, yaml, Alias, Ignored, kw_config
from ovgenpy.config import register_config, yaml, Alias, Ignored, kw_config, OvgenError
# YAML Idiosyncrasies: https://docs.saltstack.com/en/develop/topics/troubleshooting/yaml_idiosyncrasies.html
@ -163,7 +163,7 @@ xx: 1
x: 1
xx: 1
'''
with pytest.raises(TypeError):
with pytest.raises(OvgenError):
yaml.load(s)