Skip to content

Commit

Permalink
check
Browse files Browse the repository at this point in the history
  • Loading branch information
cecille committed Dec 6, 2024
1 parent 6063e23 commit 2d6aada
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 29 deletions.
52 changes: 26 additions & 26 deletions src/python_testing/TestIdChecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ def check_standard(id):
id_type = device_type_id_type(id)
msg = f"Incorrect device type range assessment, expecting standard {id:08x}, type = {id_type}"
asserts.assert_equal(device_type_id_type(id), DeviceTypeIdType.kStandard, msg)
asserts.assert_true(is_valid_device_type_id(id_type, allow_test=True), msg)
asserts.assert_true(is_valid_device_type_id(id_type, allow_test=False), msg)
asserts.assert_true(is_valid_device_type_id(id, allow_test=True), msg)
asserts.assert_true(is_valid_device_type_id(id, allow_test=False), msg)

def check_manufacturer(id):
id_type = device_type_id_type(id)
msg = f"Incorrect device type range assessment, expecting manufacturer {id:08x}, type = {id_type}"
asserts.assert_equal(device_type_id_type(id), DeviceTypeIdType.kManufacturer, msg)
asserts.assert_true(is_valid_device_type_id(id_type, allow_test=True), msg)
asserts.assert_true(is_valid_device_type_id(id_type, allow_test=False), msg)
asserts.assert_true(is_valid_device_type_id(id, allow_test=True), msg)
asserts.assert_true(is_valid_device_type_id(id, allow_test=False), msg)

def check_test(id):
id_type = device_type_id_type(id)
msg = f"Incorrect device type range assessment, expecting test {id:08x}, type = {id_type}"
asserts.assert_equal(device_type_id_type(id), DeviceTypeIdType.kTest, msg)
asserts.assert_true(is_valid_device_type_id(id_type, allow_test=True), msg)
asserts.assert_false(is_valid_device_type_id(id_type, allow_test=False), msg)
asserts.assert_true(is_valid_device_type_id(id, allow_test=True), msg)
asserts.assert_false(is_valid_device_type_id(id, allow_test=False), msg)

def check_all_bad(id):
id_type = device_type_id_type(id)
msg = f"Incorrect device type range assessment, expecting invalid {id:08x}, type = {id_type}"
asserts.assert_equal(device_type_id_type(id), DeviceTypeIdType.kInvalid, msg)
asserts.assert_false(is_valid_device_type_id(id_type, allow_test=True), msg)
asserts.assert_false(is_valid_device_type_id(id_type, allow_test=False), msg)
asserts.assert_false(is_valid_device_type_id(id, allow_test=True), msg)
asserts.assert_false(is_valid_device_type_id(id, allow_test=False), msg)

for id in standard_good:
check_standard(id)
Expand Down Expand Up @@ -100,29 +100,29 @@ def check_standard(id):
id_type = cluster_id_type(id)
msg = f"Incorrect cluster range assessment, expecting standard {id:08x}, type = {id_type}"
asserts.assert_equal(id_type, ClusterIdType.kStandard, msg)
asserts.assert_true(is_valid_cluster_id(id_type, allow_test=True), msg)
asserts.assert_true(is_valid_cluster_id(id_type, allow_test=False), msg)
asserts.assert_true(is_valid_cluster_id(id, allow_test=True), msg)
asserts.assert_true(is_valid_cluster_id(id, allow_test=False), msg)

def check_manufacturer(id):
id_type = cluster_id_type(id)
msg = f"Incorrect cluster range assessment, expecting manufacturer {id:08x}, type = {id_type}"
asserts.assert_equal(id_type, ClusterIdType.kManufacturer, msg)
asserts.assert_true(is_valid_cluster_id(id_type, allow_test=True), msg)
asserts.assert_true(is_valid_cluster_id(id_type, allow_test=False), msg)
asserts.assert_true(is_valid_cluster_id(id, allow_test=True), msg)
asserts.assert_true(is_valid_cluster_id(id, allow_test=False), msg)

def check_test(id):
id_type = cluster_id_type(id)
msg = f"Incorrect cluster range assessment, expecting test {id:08x}, type = {id_type}"
asserts.assert_equal(id_type, ClusterIdType.kTest, msg)
asserts.assert_true(is_valid_cluster_id(id_type, allow_test=True), msg)
asserts.assert_false(is_valid_cluster_id(id_type, allow_test=False), msg)
asserts.assert_true(is_valid_cluster_id(id, allow_test=True), msg)
asserts.assert_false(is_valid_cluster_id(id, allow_test=False), msg)

def check_all_bad(id):
id_type = cluster_id_type(id)
msg = f"Incorrect cluster range assessment, expecting invalid {id:08x}, type = {id_type}"
asserts.assert_equal(id_type, ClusterIdType.kInvalid, msg)
asserts.assert_false(is_valid_cluster_id(id_type, allow_test=True), msg)
asserts.assert_false(is_valid_cluster_id(id_type, allow_test=False), msg)
asserts.assert_false(is_valid_cluster_id(id, allow_test=True), msg)
asserts.assert_false(is_valid_cluster_id(id, allow_test=False), msg)

for id in standard_good:
check_standard(id)
Expand Down Expand Up @@ -160,36 +160,36 @@ def check_standard_global(id):
id_type = attribute_id_type(id)
msg = f"Incorrect attribute range assessment, expecting standard global {id:08x}, type = {id_type}"
asserts.assert_equal(id_type, AttributeIdType.kStandardGlobal, msg)
asserts.assert_true(is_valid_attribute_id(id_type, allow_test=True), msg)
asserts.assert_true(is_valid_attribute_id(id_type, allow_test=False), msg)
asserts.assert_true(is_valid_attribute_id(id, allow_test=True), msg)
asserts.assert_true(is_valid_attribute_id(id, allow_test=False), msg)

def check_standard_non_global(id):
id_type = attribute_id_type(id)
msg = f"Incorrect attribute range assessment, expecting standard non-global {id:08x}, type = {id_type}"
asserts.assert_equal(id_type, AttributeIdType.kStandardNonGlobal, msg)
asserts.assert_true(is_valid_attribute_id(id_type, allow_test=True), msg)
asserts.assert_true(is_valid_attribute_id(id_type, allow_test=False), msg)
asserts.assert_true(is_valid_attribute_id(id, allow_test=True), msg)
asserts.assert_true(is_valid_attribute_id(id, allow_test=False), msg)

def check_manufacturer(id):
id_type = attribute_id_type(id)
msg = f"Incorrect attribute range assessment, expecting manufacturer {id:08x}, type = {id_type}"
asserts.assert_equal(id_type, AttributeIdType.kManufacturer, msg)
asserts.assert_true(is_valid_attribute_id(id_type, allow_test=True), msg)
asserts.assert_true(is_valid_attribute_id(id_type, allow_test=False), msg)
asserts.assert_true(is_valid_attribute_id(id, allow_test=True), msg)
asserts.assert_true(is_valid_attribute_id(id, allow_test=False), msg)

def check_test(id):
id_type = attribute_id_type(id)
msg = f"Incorrect attribute range assessment, expecting test {id:08x}, type = {id_type}"
asserts.assert_equal(id_type, AttributeIdType.kTest, msg)
asserts.assert_true(is_valid_attribute_id(id_type, allow_test=True), msg)
asserts.assert_false(is_valid_attribute_id(id_type, allow_test=False), msg)
asserts.assert_true(is_valid_attribute_id(id, allow_test=True), msg)
asserts.assert_false(is_valid_attribute_id(id, allow_test=False), msg)

def check_all_bad(id):
id_type = attribute_id_type(id)
msg = f"Incorrect attribute range assessment, expecting invalid {id:08x}, type = {id_type}"
asserts.assert_equal(id_type, AttributeIdType.kInvalid, msg)
asserts.assert_false(is_valid_attribute_id(id_type, allow_test=True), msg)
asserts.assert_false(is_valid_attribute_id(id_type, allow_test=False), msg)
asserts.assert_false(is_valid_attribute_id(id, allow_test=True), msg)
asserts.assert_false(is_valid_attribute_id(id, allow_test=False), msg)

for id in standard_global_good:
check_standard_global(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ def cluster_id_type(id: int) -> ClusterIdType:
return ClusterIdType.kInvalid


def is_valid_cluster_id(id_type: ClusterIdType, allow_test: bool = False) -> bool:
def is_standard_cluster_id(id: int):
id_type = cluster_id_type(id)
return id_type in [ClusterIdType.kStandard]


def is_valid_cluster_id(id: int, allow_test: bool = False) -> bool:
id_type = device_type_id_type(id)
valid = [ClusterIdType.kStandard, ClusterIdType.kManufacturer]
if allow_test:
valid.append(ClusterIdType.kTest)
Expand All @@ -152,13 +158,19 @@ def attribute_id_type(id: int) -> AttributeIdType:
return AttributeIdType.kInvalid


def is_valid_attribute_id(id_type: AttributeIdType, allow_test: bool = False):
def is_valid_attribute_id(id: int, allow_test: bool = False):
id_type = attribute_id_type(id)
valid = [AttributeIdType.kStandardGlobal, AttributeIdType.kStandardNonGlobal, AttributeIdType.kManufacturer]
if allow_test:
valid.append(AttributeIdType.kTest)
return id_type in valid


def is_standard_attribute_id(id: int):
id_type = attribute_id_type(id)
return id_type in [AttributeIdType.kStandardGlobal, AttributeIdType.kStandardNonGlobal]


def command_id_type(id: int) -> CommandIdType:
if id in STANDARD_PREFIX and id in COMMAND_ID_GLOBAL_STANDARD_SUFFIX:
return CommandIdType.kStandardGlobal
Expand All @@ -171,7 +183,13 @@ def command_id_type(id: int) -> CommandIdType:
return CommandIdType.kInvalid


def is_valid_command_id(id_type: CommandIdType, allow_test: bool = False):
def is_standard_command_id(id: int):
id_type = command_id_type(id)
return id in [CommandIdType.kScopedNonGlobal, CommandIdType.kStandardGlobal]


def is_valid_command_id(id: int, allow_test: bool = False):
id_type = command_id_type(id)
valid = [CommandIdType.kStandardGlobal, CommandIdType.kScopedNonGlobal, CommandIdType.kManufacturer]
if allow_test:
valid.append(CommandIdType.kTest)
Expand Down

0 comments on commit 2d6aada

Please sign in to comment.