Skip to content

Commit

Permalink
Fix isUpperCase/isLowerCase constraint checking in python yaml proces…
Browse files Browse the repository at this point in the history
…sing.

I just got a CI failure like so:

TEST OUT: isUpperCase: true <-- The response "9659674627744477" contains lowercase characters: [].

but of course it does not.  It just happens to be an instance name that didn't
end up using any hex chars that are > 9.

This change better aligns the way Python tests uppercase/lowercase with the
built-in chip-tool constraint impl.
  • Loading branch information
bzbarsky-apple committed May 12, 2023
1 parent bbff46a commit fc46770
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 83 deletions.
12 changes: 10 additions & 2 deletions scripts/py_matter_yamltests/matter_yamltests/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,11 @@ def __init__(self, context, is_upper_case):
self._is_upper_case = is_upper_case

def check_response(self, value, value_type_name) -> bool:
return value.isupper() == self._is_upper_case
# isupper() on the whole string will return false for digit-only
# strings, which is not what we want here. We want to treat digits as
# uppercase for purposes of isUpperCase.
isUpper = all(c.isdigit() or c.isupper() for c in value)
return isUpper == self._is_upper_case

def get_reason(self, value, value_type_name) -> str:
if self._is_upper_case:
Expand All @@ -608,7 +612,11 @@ def __init__(self, context, is_lower_case):
self._is_lower_case = is_lower_case

def check_response(self, value, value_type_name) -> bool:
return value.islower() == self._is_lower_case
# islower() on the whole string will return false for strings consisting
# of only digits, which is not what we want here. We want to treat digits as
# lowercase for purposes of isLowerCase.
hasUpper = any(c.isupper() for c in value)
return hasUpper != self._is_lower_case

def get_reason(self, value, value_type_name) -> str:
if self._is_lower_case:
Expand Down
15 changes: 15 additions & 0 deletions src/app/tests/suites/TestConstraints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ tests:
isUpperCase: false
isLowerCase: false

- label: "Write attribute CHAR_STRING Value with only digits"
command: "writeAttribute"
attribute: "char_string"
arguments:
value: "1234567890"

- label:
"Read attribute CHAR_STRING Value isLowerCase/isUpperCase Constraints"
command: "readAttribute"
attribute: "char_string"
response:
constraints:
isUpperCase: true
isLowerCase: true

- label: "Write attribute CHAR_STRING Value"
command: "writeAttribute"
attribute: "char_string"
Expand Down
103 changes: 64 additions & 39 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fc46770

Please sign in to comment.