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

Creating Namespace parser and unit test for Cecille's PR #37527 #4

Open
wants to merge 4 commits into
base: update_dms_and_add_namespace_docs
Choose a base branch
from

Conversation

j-ororke
Copy link

@j-ororke j-ororke commented Feb 19, 2025

Problem

Creates namespace parser

Summary of Changes

Creating namespace parser with data provided by Cecille:

  • Created new TestSpecParsingNamespace.py unit test to test namespaces
  • Updated tests.yaml to include TestSpecParsingNamespace.py
  • Updated test_metadata.yaml to include TestSpecParsingNamespace.py and reasoning
  • Updated matter_testing support module to include new NamespacePathLocation function for Namespace file locations
  • Updated spec_parsing to include new functions build_xml_namespaces and parse_namespace, as well as XmlNamespaces and XmlTags dataclasses

Updates Cecille's PR #37527

- Creating with data provided by Cecille in PR here: project-chip#37527
- Updated test.yaml to include TestSpecParsingNamespace.py to run in CI
- Updated matter_testing support module to include new NamespacePathLocation function for Namespace file locations
- Updated spec_parsing to include new functions build_xml_namespaces and parse_namespace, as well as XmlNamespaces and XmlTags dataclasses
- Added TestSpecParsingNamespace.py as it is a unit test and not run against an app.
@j-ororke j-ororke changed the title Creating TestSpecParsingNamespace test module for PR #37527 Creating Namespace parser and unit test for Cecille's PR #37527 Feb 19, 2025
Copy link
Owner

@cecille cecille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fairly minor comments, but this looks good

class TestSpecParsingNamespace(MatterBaseTest):
def setup_class(self):
# Get the data model paths
self.dm_1_3 = os.path.join(os.path.dirname(__file__), "..", "..", "data_model", "1.3")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to do this just using the PrebuiltDatamodelDirectory enum - added a comment below on how to do that in the parser.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, thank you.
That will be much cleaner, I had not realized that was available.

namespaces: dict[int, XmlNamespace] = {}
problems: list[ProblemNotice] = []

if not os.path.exists(namespace_path):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please replace this with get_data_model_directory(data_model_directory, DataModelLevel.kNamespace)

(you'll have to implement the enum for the namespace, but it's one line and it should just work)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I have updated this section of code to now use the get_data_model_directory(data_model_directory, DataModelLevel.kNamespace) implementation that you have mentioned, as well as adding the kNamespace to DataModelLevel.

# Validate 16-bit hex format (0xNNNN)
try:
# Remove '0x' prefix if present and try to parse
id_value = int(namespace_id.replace('0x', ''), 16)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use int( .... , 0) here, that's probably fine - I don't know that these necessarily need to be hex.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I have updated the code here to reflect the above change mentioned.

))

# Check format is exactly 0xNNNN where N is a hex digit
if not namespace_id.lower().startswith('0x') or len(namespace_id) != 6:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also fine - I don't think these need to be that strict.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I left this section as is for now but can swap it over if needed. Was trying to be as thorough as possible, but I might have gone overboard in that regards a little bit here it appears lol.


return problems

def test_all_namespace_files(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice.

Copy link
Author

@j-ororke j-ororke Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
I tried to test all scenarios that I could think of with the namespace files.
It also helped a lot that I had the TestSpecParsingDeviceTypes.py code to reflect on.

j-ororke and others added 2 commits February 20, 2025 12:34
- Updating to change method to using 0 instead of 16 bit enums
- Updating to use PrebuiltDatamodelDirectory instead of os to set filepaths
- Updated to utilizing the build_xml_namespaces function in spec_parsing.
…spec_parsing.py

Co-authored-by: C Freeman <cecille@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants