Skip to content

Commit c6634b3

Browse files
Fix "notValue: null" constraints to actually work right.
We were skipping notValue constraints if the value was null, so "notValue: null" always passed, no matter what the value was. The fix is to stop doing that skipping. Also adds a test that this constraint fails if the value is in fact null.
1 parent 9b9ed65 commit c6634b3

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

.github/workflows/tests.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ jobs:
247247
--chip-tool ./out/linux-x64-chip-tool${CHIP_TOOL_VARIANT}-${BUILD_VARIANT}/chip-tool \
248248
run \
249249
--iterations 1 \
250-
--expected-failures 1 \
250+
--expected-failures 2 \
251251
--keep-going \
252252
--test-timeout-seconds 120 \
253253
--all-clusters-app ./out/linux-x64-all-clusters-${BUILD_VARIANT}/chip-all-clusters-app \
@@ -398,7 +398,7 @@ jobs:
398398
--chip-tool ./out/darwin-x64-chip-tool${CHIP_TOOL_VARIANT}-${BUILD_VARIANT}/chip-tool \
399399
run \
400400
--iterations 1 \
401-
--expected-failures 1 \
401+
--expected-failures 2 \
402402
--keep-going \
403403
--test-timeout-seconds 120 \
404404
--all-clusters-app ./out/darwin-x64-all-clusters-${BUILD_VARIANT}/chip-all-clusters-app \

scripts/py_matter_yamltests/matter_yamltests/constraints.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -801,14 +801,15 @@ def get_reason(self, value, value_type_name) -> str:
801801

802802
class _ConstraintNotValue(BaseConstraint):
803803
def __init__(self, context, not_value):
804-
super().__init__(context, types=[], is_null_allowed=True)
804+
# NOTE: do not use is_null_allowed=True here, because 'notValue: null' needs to work.
805+
super().__init__(context, types=[])
805806
self._not_value = not_value
806807

807808
def check_response(self, value, value_type_name) -> bool:
808809
return value != self._not_value
809810

810811
def get_reason(self, value, value_type_name) -> str:
811-
return f'The response value "{value}" should differs from the constraint.'
812+
return f'The response value "{value}" should differ from the constraint.'
812813

813814

814815
class _ConstraintAnyOf(BaseConstraint):

scripts/tests/chiptest/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ def _GetPurposefulFailureTests() -> Set[str]:
277277
"""Tests that fail in YAML on purpose."""
278278
return {
279279
"TestPurposefulFailureEqualities.yaml"
280+
"TestPurposefulFailureNotNullConstraint.yaml"
280281
}
281282

282283

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name:
16+
Test that notValue constraint that says value must not be null fails if the
17+
value is null.
18+
19+
config:
20+
nodeId: 0x12344321
21+
cluster: "Unit Testing"
22+
endpoint: 1
23+
24+
tests:
25+
- label: "Write attribute NULLABLE_INT8U null value"
26+
command: "writeAttribute"
27+
attribute: "nullable_int8u"
28+
arguments:
29+
value: null
30+
31+
- label: "Read attribute NULLABLE_INT8U null value with constraint"
32+
command: "readAttribute"
33+
attribute: "nullable_int8u"
34+
response:
35+
constraints:
36+
# This should fail.
37+
notValue: null

0 commit comments

Comments
 (0)