Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[matter_yamltests] Add is_nullable method to SpecDefinitions #24624

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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