Skip to content

Commit

Permalink
simplify checker call
Browse files Browse the repository at this point in the history
  • Loading branch information
cecille committed Aug 26, 2023
1 parent 3942afa commit 1e0f96c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/python_testing/TC_DeviceBasicComposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,11 @@ def check_non_empty_list_of_ints_in_range(min_value: int, max_value: int, max_si
return check_list_of_ints_in_range(min_value, max_value, min_size=1, max_size=max_size, allow_null=allow_null)


def check_no_duplicates() -> Callable:
def check_no_duplicates_checker(obj: Any):
if not isinstance(obj, list):
raise ValueError(f"Value {str(obj)} is not a list, but a list was expected (decoded type: {type(obj)})")
if len(set(obj)) != len(obj):
raise ValueError(f"Value {str(obj)} contains duplicate values")
return check_no_duplicates_checker
def check_no_duplicates(obj: Any) -> None:
if not isinstance(obj, list):
raise ValueError(f"Value {str(obj)} is not a list, but a list was expected (decoded type: {type(obj)})")
if len(set(obj)) != len(obj):
raise ValueError(f"Value {str(obj)} contains duplicate values")


class TC_DeviceBasicComposition(MatterBaseTest):
Expand Down Expand Up @@ -310,13 +308,13 @@ class RequiredMandatoryAttribute:
RequiredMandatoryAttribute(id=0xFFFD, name="ClusterRevision", validators=[check_int_in_range(1, 0xFFFF)]),
RequiredMandatoryAttribute(id=0xFFFC, name="FeatureMap", validators=[check_int_in_range(0, 0xFFFF_FFFF)]),
RequiredMandatoryAttribute(id=0xFFFB, name="AttributeList",
validators=[check_non_empty_list_of_ints_in_range(0, 0xFFFF_FFFF), check_no_duplicates()]),
validators=[check_non_empty_list_of_ints_in_range(0, 0xFFFF_FFFF), check_no_duplicates]),
# TODO: Check for EventList
# RequiredMandatoryAttribute(id=0xFFFA, name="EventList", validator=check_list_of_ints_in_range(0, 0xFFFF_FFFF)),
RequiredMandatoryAttribute(id=0xFFF9, name="AcceptedCommandList",
validators=[check_list_of_ints_in_range(0, 0xFFFF_FFFF), check_no_duplicates()]),
validators=[check_list_of_ints_in_range(0, 0xFFFF_FFFF), check_no_duplicates]),
RequiredMandatoryAttribute(id=0xFFF8, name="GeneratedCommandList",
validators=[check_list_of_ints_in_range(0, 0xFFFF_FFFF), check_no_duplicates()]),
validators=[check_list_of_ints_in_range(0, 0xFFFF_FFFF), check_no_duplicates]),
]

self.print_step(3, "Validate all reported attributes match AttributeList")
Expand Down

0 comments on commit 1e0f96c

Please sign in to comment.