From 57ff3e69e00938253094e5eaf603761ce83de329 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Wed, 22 Jan 2025 16:33:33 -0800 Subject: [PATCH] We should only validate against None when optional=true (#37161) --- src/python_testing/TC_DGWIFI_2_1.py | 89 +++++++++++------------------ 1 file changed, 34 insertions(+), 55 deletions(-) diff --git a/src/python_testing/TC_DGWIFI_2_1.py b/src/python_testing/TC_DGWIFI_2_1.py index 3012baa153d716..707deb0198047f 100644 --- a/src/python_testing/TC_DGWIFI_2_1.py +++ b/src/python_testing/TC_DGWIFI_2_1.py @@ -64,15 +64,10 @@ def is_valid_bssid(bssid) -> bool: return False def assert_valid_bssid(self, value, field_name): - """Asserts that the value is a valid BSSID (MAC address), None, or NullValue.""" - if isinstance(value, Nullable): - if value == NullValue: - return - value = value.Value - - if value is not None: + """Asserts that the value is a valid BSSID (MAC address), or NullValue.""" + if value is not NullValue: asserts.assert_true(self.is_valid_bssid(value), - f"{field_name} should be a valid BSSID string (e.g., '00:11:22:33:44:55') or None/NullValue.") + f"{field_name} should be a valid BSSID string (e.g., '00:11:22:33:44:55') or NullValue.") async def read_dgwifi_attribute_expect_success(self, endpoint, attribute): cluster = Clusters.Objects.WiFiNetworkDiagnostics @@ -134,26 +129,22 @@ async def test_TC_DGWIFI_2_1(self): # SecurityType is an enum. If the interface is not operational, it could be NULL. # If not NULL, we expect an integer in the SecurityType enum range. # Just do a minimal check here; you can refine or extend based on the spec. - if security_type is not None: - asserts.assert_true(isinstance(security_type, Nullable), - "SecurityType must be of type 'Nullable' when not None.") - - if security_type is not NullValue: - security_type_value = security_type.Value - self.assert_valid_uint8(security_type_value, "SecurityType") - - # Check if the security_type is a valid SecurityTypeEnum member - self.assert_true( - security_type_value in [item.value for item in Clusters.Objects.WiFiNetworkDiagnostics.Enums.SecurityTypeEnum], - f"SecurityType {security_type_value} is not a valid SecurityTypeEnum value" - ) - - # Additional check that it's not kUnknownEnumValue: - self.assert_true( - security_type_value != Clusters.Objects.WiFiNetworkDiagnostics.Enums.SecurityTypeEnum.kUnknownEnumValue.value, - f"SecurityType should not be kUnknownEnumValue " - f"({Clusters.Objects.WiFiNetworkDiagnostics.Enums.SecurityTypeEnum.kUnknownEnumValue.value})" - ) + if security_type is not NullValue: + security_type_value = security_type.Value + self.assert_valid_uint8(security_type_value, "SecurityType") + + # Check if the security_type is a valid SecurityTypeEnum member + self.assert_true( + security_type_value in [item.value for item in Clusters.Objects.WiFiNetworkDiagnostics.Enums.SecurityTypeEnum], + f"SecurityType {security_type_value} is not a valid SecurityTypeEnum value" + ) + + # Additional check that it's not kUnknownEnumValue: + self.assert_true( + security_type_value != Clusters.Objects.WiFiNetworkDiagnostics.Enums.SecurityTypeEnum.kUnknownEnumValue.value, + f"SecurityType should not be kUnknownEnumValue " + f"({Clusters.Objects.WiFiNetworkDiagnostics.Enums.SecurityTypeEnum.kUnknownEnumValue.value})" + ) # # STEP 4: TH reads WiFiVersion attribute @@ -161,21 +152,17 @@ async def test_TC_DGWIFI_2_1(self): self.step(4) wifi_version = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.WiFiVersion) # WiFiVersion is an enum. If not configured or operational, might be NULL. - if wifi_version is not None: - asserts.assert_true(isinstance(wifi_version, Nullable), - "WiFiVersion must be of type 'Nullable' when not None.") - - if wifi_version is not NullValue: - wifi_version_value = wifi_version.Value - self.assert_valid_uint8(wifi_version_value, "WiFiVersion") + if wifi_version is not NullValue: + wifi_version_value = wifi_version.Value + self.assert_valid_uint8(wifi_version_value, "WiFiVersion") - # Check if the wifi_version is a valid WiFiVersionEnum member - self.assert_true(wifi_version_value in [item.value for item in Clusters.Objects.WiFiNetworkDiagnostics.Enums.WiFiVersionEnum], - f"WiFiVersion {wifi_version_value} is not a valid WiFiVersionEnum value") + # Check if the wifi_version is a valid WiFiVersionEnum member + self.assert_true(wifi_version_value in [item.value for item in Clusters.Objects.WiFiNetworkDiagnostics.Enums.WiFiVersionEnum], + f"WiFiVersion {wifi_version_value} is not a valid WiFiVersionEnum value") - # Additional check that it's not kUnknownEnumValue: - self.assert_true(wifi_version_value != Clusters.Objects.WiFiNetworkDiagnostics.Enums.WiFiVersionEnum.kUnknownEnumValue.value, - f"WiFiVersion should not be kUnknownEnumValue ({Clusters.Objects.WiFiNetworkDiagnostics.Enums.WiFiVersionEnum.kUnknownEnumValue.value})") + # Additional check that it's not kUnknownEnumValue: + self.assert_true(wifi_version_value != Clusters.Objects.WiFiNetworkDiagnostics.Enums.WiFiVersionEnum.kUnknownEnumValue.value, + f"WiFiVersion should not be kUnknownEnumValue ({Clusters.Objects.WiFiNetworkDiagnostics.Enums.WiFiVersionEnum.kUnknownEnumValue.value})") # # STEP 5: TH reads ChannelNumber attribute @@ -183,12 +170,8 @@ async def test_TC_DGWIFI_2_1(self): self.step(5) channel_number = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.ChannelNumber) # If not operational, might be NULL. Else we expect an unsigned integer channel. - if channel_number is not None: - asserts.assert_true(isinstance(channel_number, Nullable), - "ChannelNumber must be of type 'Nullable' when not None.") - - if channel_number is not NullValue: - self.assert_valid_uint16(channel_number.Value, "ChannelNumber") + if channel_number is not NullValue: + self.assert_valid_uint16(channel_number.Value, "ChannelNumber") # # STEP 6: TH reads RSSI attribute @@ -196,14 +179,10 @@ async def test_TC_DGWIFI_2_1(self): self.step(6) rssi = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.Rssi) # RSSI is typically a signed integer (dB). If not operational, might be NULL. - if rssi is not None: - asserts.assert_true(isinstance(rssi, Nullable), - "RSSI must be of type 'Nullable' when not None.") - - if rssi is not NullValue: - rssi_value = rssi.Value - asserts.assert_true(isinstance(rssi_value, int) and -120 <= rssi_value <= 0, - "rssi_value is not within valid range.") + if rssi is not NullValue: + rssi_value = rssi.Value + asserts.assert_true(isinstance(rssi_value, int) and -120 <= rssi_value <= 0, + "rssi_value is not within valid range.") # # STEP 7: TH reads BeaconLostCount attribute