errors.append(exceptions.NotBooleanSettingError(
'{}:{}'.format(component, setting), conf[setting]))
return errors
+
+
+def boolean_choice(component, settings, conf):
+ errors = []
+ for setting in settings:
+ if setting in conf:
+ if conf[setting] not in (
+ 'yes-always', 'choice-yes', 'choice-no', 'no-never'):
+ errors.append(exceptions.NotBooleanChoiceSettingError(
+ f'{component}:{setting}', conf[setting]))
+ return errors
.format(key))
+class NotBooleanChoiceSettingError(Error):
+ def __init__(self, key, value):
+ super().__init__(
+ f'Bad value ({value}) for the {key} setting',
+ (f'The "{key}" PGWUI setting must be one of: '
+ '"yes-always", "choice-yes", "choice-no", "no-never"'))
+
+
class BadAssetOverrideError(Error):
def __init__(self, asset, new_asset, exp):
super().__init__(
result = checkset.boolean_settings('testcomp', bools, conf)
assert result == []
+
+
+# boolean_choice()
+
+@pytest.mark.parametrize(
+ ('name', 'config', 'error_count'), [
+ ('settingname', {'settingname': 'yes-always'}, 0),
+ ('settingname', {'settingname': 'choice-yes'}, 0),
+ ('settingname', {'settingname': 'choice-no'}, 0),
+ ('settingname', {'settingname': 'no-never'}, 0),
+ ('settingname', {'settingname': 'unrecognized'}, 1),
+ ('settingname', {}, 0)])
+@pytest.mark.unittest
+def test_boolean_choice(name, config, error_count):
+ '''The right number of errors are returned
+ '''
+ result = checkset.boolean_choice('testcomp', [name], config)
+ assert len(result) == error_count