Skip to content

Commit

Permalink
[matter_yamltests] Fix the pics checker (#24657)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored and pull[bot] committed Nov 28, 2023
1 parent c72327e commit b58dbd1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scripts/py_matter_yamltests/matter_yamltests/pics_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ def __evaluate_expression(self, tokens: list[str], pics: dict):

if token == '&&':
self.__expression_index += 1
rightExpr = self.__evaluate_sub_expression(tokens, pics)
rightExpr = self.__evaluate_expression(tokens, pics)
return leftExpr and rightExpr

if token == '||':
self.__expression_index += 1
rightExpr = self.__evaluate_sub_expression(tokens, pics)
rightExpr = self.__evaluate_expression(tokens, pics)
return leftExpr or rightExpr

raise InvalidPICSParsingError(f'Unknown token: {token}')
Expand All @@ -115,7 +115,7 @@ def __evaluate_sub_expression(self, tokens: list[str], pics: dict):

if token == '!':
self.__expression_index += 1
expr = self.__evaluate_expression(tokens, pics)
expr = self.__evaluate_sub_expression(tokens, pics)
return not expr

token = self.__normalize(token)
Expand Down
16 changes: 16 additions & 0 deletions scripts/py_matter_yamltests/test_pics_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@
A.D=1=
'''

simple_real_config = '''
# Color Control Cluster
CC.S.F00=0
CC.S.F01=1
CC.S.F02=1
CC.S.F03=1
CC.S.F04=1
'''


class TestPICSChecker(unittest.TestCase):
def test_no_file(self):
Expand Down Expand Up @@ -168,6 +177,13 @@ def test_simple_config_with_invalid_entry(self):
self.assertRaises(InvalidPICSConfigurationError,
PICSChecker, mock_file)

@patch('builtins.open', mock_open(read_data=simple_real_config))
def test_simple_real_config(self):
pics_checker = PICSChecker('')
self.assertIsInstance(pics_checker, PICSChecker)
self.assertFalse(pics_checker.check(
'( !CC.S.F00 && !CC.S.F01 && !CC.S.F02 && !CC.S.F03 && !CC.S.F04 )'))


if __name__ == '__main__':
unittest.main()

0 comments on commit b58dbd1

Please sign in to comment.