-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: update_dms_and_add_namespace_docs
Are you sure you want to change the base?
Creating Namespace parser and unit test for Cecille's PR #37527 #4
Conversation
- 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.
There was a problem hiding this 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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
src/python_testing/matter_testing_infrastructure/chip/testing/spec_parsing.py
Outdated
Show resolved
Hide resolved
# Validate 16-bit hex format (0xNNNN) | ||
try: | ||
# Remove '0x' prefix if present and try to parse | ||
id_value = int(namespace_id.replace('0x', ''), 16) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice.
There was a problem hiding this comment.
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.
- 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>
Problem
Creates namespace parser
Summary of Changes
Creating namespace parser with data provided by Cecille:
Updates Cecille's PR #37527