Skip to content

Commit

Permalink
[matter_yamltests] Add is_nullable method to SpecDefinitions (#24624)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored and pull[bot] committed Oct 5, 2023
1 parent 4d7c6f2 commit 3580354
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions scripts/py_matter_yamltests/matter_yamltests/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def is_fabric_scoped(self, target) -> bool:
return bool(target.qualities & StructQuality.FABRIC_SCOPED)
return False

def is_nullable(self, target) -> bool:
if hasattr(target, 'qualities'):
return bool(target.qualities & FieldQuality.NULLABLE)
return False

def __get_by_name(self, cluster_name: str, target_name: str, target_type: _ItemType):
if not cluster_name or not target_name:
return None
Expand Down
33 changes: 33 additions & 0 deletions scripts/py_matter_yamltests/test_spec_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@
</configurator>
'''

source_response_with_nullable = '''<?xml version="1.0"?>
<configurator>
<cluster>
<name>Test</name>
<code>0x1234</code>
<command source="server" code="0x0" name="TestCommandResponse">
<arg name="arg1" type="int8u"/>
<arg name="arg2" type="int8u" isNullable="true"/>
</command>
</cluster>
</configurator>
'''

source_attribute = '''<?xml version="1.0"?>
<configurator>
<global>
Expand Down Expand Up @@ -184,6 +199,24 @@ def test_response_name(self):
self.assertEqual(definitions.get_response_name(
0x1234, 0x0), 'TestCommandResponse')

def test_response_name_with_nullable(self):
definitions = SpecDefinitions(
[ParseSource(source=io.StringIO(source_response_with_nullable), name='source_response_with_nullable')])
cluster_name = 'Test'
response_name = 'TestCommandResponse'

self.assertEqual(definitions.get_cluster_name(0x1234), cluster_name)
self.assertEqual(definitions.get_response_name(
0x1234, 0x0), response_name)

response = definitions.get_response_by_name(
cluster_name, response_name)
for field in response.fields:
if field.name == 'arg1':
self.assertFalse(definitions.is_nullable(field))
else:
self.assertTrue(definitions.is_nullable(field))

def test_attribute_name(self):
definitions = SpecDefinitions(
[ParseSource(source=io.StringIO(source_attribute), name='source_attribute')])
Expand Down

0 comments on commit 3580354

Please sign in to comment.