Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for substituting YAML value to global config variables #23743

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into config-value-substitution
tehampson committed Nov 24, 2022
commit 299be93705d27451d97ac66a639ca04bb8f1b9a5
104 changes: 0 additions & 104 deletions src/controller/python/chip/yaml/parser.py
Original file line number Diff line number Diff line change
@@ -50,110 +50,6 @@ class _ExecutionContext:
config_values: dict = None


class _ConstraintValue:
'''Constraints that are numeric primitive data types'''

def __init__(self, value, field_type, context: _ExecutionContext):
self._variable_storage = context.variable_storage
# When not none _indirect_value_key is binding a name to the constraint value, and the
# actual value can only be looked-up dynamically, which is why this is a key name.
self._indirect_value_key = None
self._value = None

if value is None:
# Default values set above is all we need here.
return

if isinstance(value, str) and self._variable_storage.is_key_saved(value):
self._indirect_value_key = value
else:
self._value = Converter.parse_and_convert_yaml_value(
value, field_type, context.config_values)

def get_value(self):
'''Gets the current value of the constraint.

This method accounts for getting the runtime saved value from DUT previous responses.
'''
if self._indirect_value_key:
return self._variable_storage.load(self._indirect_value_key)
return self._value


class _Constraints:
def __init__(self, constraints: dict, field_type, context: _ExecutionContext):
self._variable_storage = context.variable_storage
self._has_value = constraints.get('hasValue')
self._type = constraints.get('type')
self._starts_with = constraints.get('startsWith')
self._ends_with = constraints.get('endsWith')
self._is_upper_case = constraints.get('isUpperCase')
self._is_lower_case = constraints.get('isLowerCase')
self._min_value = _ConstraintValue(constraints.get('minValue'), field_type,
context)
self._max_value = _ConstraintValue(constraints.get('maxValue'), field_type,
context)
self._contains = constraints.get('contains')
self._excludes = constraints.get('excludes')
self._has_masks_set = constraints.get('hasMasksSet')
self._has_masks_clear = constraints.get('hasMasksClear')
self._not_value = _ConstraintValue(constraints.get('notValue'), field_type,
context)

def are_constrains_met(self, response) -> bool:
return_value = True

if self._has_value:
logger.warn(f'HasValue constraint currently not implemented, forcing failure')
return_value = False

if self._type:
logger.warn(f'Type constraint currently not implemented, forcing failure')
return_value = False

if self._starts_with and not response.startswith(self._starts_with):
return_value = False

if self._ends_with and not response.endswith(self._ends_with):
return_value = False

if self._is_upper_case and not response.isupper():
return_value = False

if self._is_lower_case and not response.islower():
return_value = False

min_value = self._min_value.get_value()
if response is not NullValue and min_value and response < min_value:
return_value = False

max_value = self._max_value.get_value()
if response is not NullValue and max_value and response > max_value:
return_value = False

if self._contains and not set(self._contains).issubset(response):
return_value = False

if self._excludes and not set(self._excludes).isdisjoint(response):
return_value = False

if self._has_masks_set:
for mask in self._has_masks_set:
if (response & mask) != mask:
return_value = False

if self._has_masks_clear:
for mask in self._has_masks_clear:
if (response & mask) != 0:
return_value = False

not_value = self._not_value.get_value()
if not_value and response == not_value:
return_value = False

return return_value


class _VariableToSave:
def __init__(self, variable_name: str, variable_storage: VariableStorage):
self._variable_name = variable_name
You are viewing a condensed version of this merge commit. You can view the full changes here.