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. (#26536)

* Fix isUpperCase/isLowerCase constraint checking in python yaml processing.

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.

* Address review comments.

* Fix restyle issue.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Sep 28, 2023
1 parent 0fafb1c commit 1174787
Show file tree
Hide file tree
Showing 5 changed files with 589 additions and 99 deletions.
8 changes: 6 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,9 @@ 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
# Make sure we don't have any lowercase characters.
hasLower = any(c.islower() for c in value)
return hasLower != self._is_upper_case

def get_reason(self, value, value_type_name) -> str:
if self._is_upper_case:
Expand All @@ -608,7 +610,9 @@ 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
# Make sure we don't have any uppercase characters.
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
77 changes: 77 additions & 0 deletions src/app/tests/suites/TestConstraints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,83 @@ 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 with only non-letters"
command: "writeAttribute"
attribute: "char_string"
arguments:
value: "12.4,76:"

- 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 with uppercase letters and symbols"
command: "writeAttribute"
attribute: "char_string"
arguments:
value: "ABC;.* "

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

- label:
"Write attribute CHAR_STRING Value with lowercase letters and symbols"
command: "writeAttribute"
attribute: "char_string"
arguments:
value: "abc;.* "

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

- label: "Write attribute CHAR_STRING Value which is empty"
command: "writeAttribute"
attribute: "char_string"
arguments:
value: ""

- 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
2 changes: 1 addition & 1 deletion src/app/tests/suites/include/ConstraintsChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class ConstraintsChecker
bool isUpperCase = true;
for (size_t i = 0; i < strlen(current); i++)
{
if (!isdigit(current[i]) && !isupper(current[i]))
if (islower(current[i]))
{
isUpperCase = false;
break;
Expand Down
Loading

0 comments on commit 1174787

Please sign in to comment.