Added tests for configoptions.py

This commit is contained in:
Rhet Turnbull
2020-12-12 07:25:50 -08:00
parent 09687cfca4
commit 0262e0d97e
5 changed files with 145 additions and 2 deletions

View File

@@ -27,6 +27,7 @@ class ConfigOptions:
Args:
name: name for these options, will be used for section heading in TOML file when saving/loading from file
attrs: dict with name and default value for all allowed attributes
ignore: optional list of strings of keys to ignore from attrs dict
"""
self._name = name
self._attrs = attrs.copy()
@@ -113,7 +114,7 @@ class ConfigOptions:
strb = ", ".join(prefix + x.replace("_", "-") for x in b)
else:
stra = a
strb = ", ".join(x for x in b)
strb = ", ".join(b)
raise ConfigOptionsInvalidError(
f"{stra} must be used with at least one of: {strb}."
)
@@ -166,7 +167,7 @@ class ConfigOptions:
if type(self._attrs[attr]) == tuple:
val = tuple(val)
setattr(self, attr, val)
return self, None
return self
def asdict(self):
return {attr: getattr(self, attr) for attr in sorted(self._attrs.keys())}