-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Declarative PIXITs in python tests #395 #36817
Open
asirko-soft
wants to merge
13
commits into
project-chip:master
Choose a base branch
from
asirko-soft:osirko-declarative_PIXITs_in_python_tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fbf03c4
add dataclass to support PIXIT validations
asirko-soft 11d86ab
Extend existing MatterTestConfig to handle PIXIT definitions
asirko-soft e96ec4b
move validation logic to a separate class
asirko-soft 93c6837
rename validators and adjust value type
asirko-soft d3976d0
change from boolean checks to handling of exceptions, fix issue where…
asirko-soft 17c05f9
don't validate pixits for commissioning test, fix typo, reformat
asirko-soft 13021d6
commit review suggestion
asirko-soft ef7d4bc
add tests for pixit validator
asirko-soft 663add6
apply linter suggestions
asirko-soft 7d14dc9
apply Ruff suggestions
asirko-soft d097888
Merge branch 'master' into osirko-declarative_PIXITs_in_python_tests
asirko-soft 2882b15
Merge branch 'master' into osirko-declarative_PIXITs_in_python_tests
asirko-soft ce2938e
add one more possible hex format to validator, add test for testing v…
asirko-soft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,9 @@ | |
|
||
import chip.clusters as Clusters | ||
from chip.clusters.Types import Nullable, NullValue | ||
from chip.testing.matter_testing import (MatterBaseTest, async_test_body, compare_time, default_matter_test_main, | ||
get_wait_seconds_from_set_time, parse_matter_test_args, type_matches, | ||
utc_time_in_matter_epoch) | ||
from chip.testing.matter_testing import (MatterBaseTest, PIXITDefinition, PIXITType, PIXITValidationError, PIXITValidator, | ||
async_test_body, compare_time, default_matter_test_main, get_wait_seconds_from_set_time, | ||
parse_matter_test_args, type_matches, utc_time_in_matter_epoch) | ||
from chip.testing.pics import parse_pics, parse_pics_xml | ||
from chip.testing.taglist_and_topology_test import (TagProblem, create_device_type_list_for_root, create_device_type_lists, | ||
find_tag_list_problems, find_tree_roots, flat_list_ok, get_all_children, | ||
|
@@ -656,6 +656,130 @@ def test_parse_matter_test_args(self): | |
asserts.assert_equal(parsed.global_test_params.get("PIXIT.TEST.STR.MULTI.2"), "bar") | ||
asserts.assert_equal(parsed.global_test_params.get("PIXIT.TEST.JSON"), {"key": "value"}) | ||
|
||
def test_pixit_validation(self): | ||
# Test integer validation | ||
PIXITValidator.validate_int_pixit_value("123") # Should pass | ||
PIXITValidator.validate_int_pixit_value("-123") # Should pass | ||
PIXITValidator.validate_int_pixit_value("0") # Should pass | ||
|
||
try: | ||
PIXITValidator.validate_int_pixit_value("abc") | ||
asserts.fail("Expected ValueError for invalid integer") | ||
except ValueError: | ||
pass | ||
|
||
try: | ||
PIXITValidator.validate_int_pixit_value("12.34") | ||
asserts.fail("Expected ValueError for float value") | ||
except ValueError: | ||
pass | ||
|
||
# Test boolean validation | ||
PIXITValidator.validate_bool_pixit_value("true") # Should pass | ||
PIXITValidator.validate_bool_pixit_value("false") # Should pass | ||
PIXITValidator.validate_bool_pixit_value("True") # Should pass | ||
PIXITValidator.validate_bool_pixit_value("False") # Should pass | ||
|
||
try: | ||
PIXITValidator.validate_bool_pixit_value("yes") | ||
asserts.fail("Expected ValueError for invalid boolean") | ||
except ValueError: | ||
pass | ||
|
||
try: | ||
PIXITValidator.validate_bool_pixit_value("1") | ||
asserts.fail("Expected ValueError for numeric boolean") | ||
except ValueError: | ||
pass | ||
|
||
# Test float validation | ||
PIXITValidator.validate_float_pixit_value("123.45") # Should pass | ||
PIXITValidator.validate_float_pixit_value("-123.45") # Should pass | ||
PIXITValidator.validate_float_pixit_value("0.0") # Should pass | ||
|
||
try: | ||
PIXITValidator.validate_float_pixit_value("abc") | ||
asserts.fail("Expected ValueError for invalid float") | ||
except ValueError: | ||
pass | ||
|
||
# Test string validation - should accept most inputs | ||
PIXITValidator.validate_string_pixit_value("abc") # Should pass | ||
PIXITValidator.validate_string_pixit_value("123") # Should pass | ||
|
||
# Test JSON validation | ||
PIXITValidator.validate_json_pixit_value('{"key": "value"}') # Should pass | ||
PIXITValidator.validate_json_pixit_value('[]') # Should pass | ||
PIXITValidator.validate_json_pixit_value('null') # Should pass | ||
|
||
try: | ||
PIXITValidator.validate_json_pixit_value('{invalid json}') | ||
asserts.fail("Expected ValueError for invalid JSON") | ||
except ValueError: | ||
pass | ||
|
||
try: | ||
PIXITValidator.validate_json_pixit_value('{"unclosed": "object"') | ||
asserts.fail("Expected ValueError for malformed JSON") | ||
except ValueError: | ||
pass | ||
|
||
# Test hex validation | ||
PIXITValidator.validate_hex_pixit_value("0x1234") # Should pass | ||
PIXITValidator.validate_hex_pixit_value("1234") # Should pass | ||
PIXITValidator.validate_hex_pixit_value("ABCD") # Should pass | ||
PIXITValidator.validate_hex_pixit_value("abcd") # Should pass | ||
|
||
try: | ||
PIXITValidator.validate_hex_pixit_value("0x123") # Odd number of digits | ||
asserts.fail("Expected ValueError for odd number of hex digits") | ||
except ValueError: | ||
pass | ||
|
||
try: | ||
PIXITValidator.validate_hex_pixit_value("123") # Odd number of digits | ||
asserts.fail("Expected ValueError for odd number of hex digits") | ||
except ValueError: | ||
pass | ||
|
||
try: | ||
PIXITValidator.validate_hex_pixit_value("WXYZ") # Invalid hex chars | ||
asserts.fail("Expected ValueError for invalid hex characters") | ||
except ValueError: | ||
pass | ||
|
||
# Test full PIXIT validation | ||
pixit_def = PIXITDefinition( | ||
name="PIXIT.TEST.INT", | ||
pixit_type=PIXITType.INT, | ||
description="Test integer PIXIT", | ||
required=True | ||
) | ||
|
||
PIXITValidator.validate_value("123", pixit_def) # Should pass | ||
|
||
try: | ||
PIXITValidator.validate_value("abc", pixit_def) | ||
asserts.fail("Expected PIXITValidationError for invalid type") | ||
except PIXITValidationError: | ||
pass | ||
|
||
try: | ||
PIXITValidator.validate_value(None, pixit_def) # Required but None | ||
asserts.fail("Expected PIXITValidationError for missing required value") | ||
except PIXITValidationError: | ||
pass | ||
|
||
# Test optional PIXIT | ||
optional_pixit = PIXITDefinition( | ||
name="PIXIT.TEST.INT", | ||
pixit_type=PIXITType.INT, | ||
description="Test integer PIXIT", | ||
required=False | ||
) | ||
|
||
PIXITValidator.validate_value(None, optional_pixit) # Should pass as it's optional | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also please add a test for the validate_pixits function to ensure they get mapped properly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
if __name__ == "__main__": | ||
default_matter_test_main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
one of the other formats we sometimes get is hex:12ab. I don't know if that is handled correctly in the argument parser though.
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.
Added support for hex:12ab format