Skip to content

Commit

Permalink
Devicetree: Devicetree Bindings: Adjust python tests
Browse files Browse the repository at this point in the history
Adjust existing tests to support the changes and add new tests to test
the newly added feature.

Signed-off-by: Joel Hirsbrunner <[email protected]>
  • Loading branch information
JHirsbrunner authored and nashif committed Oct 15, 2024
1 parent 8b02bc9 commit 7454cb9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
15 changes: 15 additions & 0 deletions scripts/dts/python-devicetree/tests/test-bindings/enums.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,20 @@ properties:
- whitespace is ok
- 123 is ok

array-enum:
type: array
enum:
- 0
- 10
- 20
- 30
- 40

string-array-enum: # tokenizable string-array
type: string-array
enum:
- bar
- foo

no-enum:
type: string
2 changes: 2 additions & 0 deletions scripts/dts/python-devicetree/tests/test.dts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@
string-enum = "foo_bar";
tokenizable-enum = "123 is ok";
tokenizable-lower-enum = "bar";
array-enum = <0 40 40 10>;
string-array-enum = "foo", "bar";
no-enum = "baz";
};

Expand Down
27 changes: 20 additions & 7 deletions scripts/dts/python-devicetree/tests/test_edtlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,31 +572,44 @@ def test_prop_enums():
string_enum = props['string-enum']
tokenizable_enum = props['tokenizable-enum']
tokenizable_lower_enum = props['tokenizable-lower-enum']
array_enum = props['array-enum']
string_array_enum = props['string-array-enum']
no_enum = props['no-enum']

assert int_enum.val == 1
assert int_enum.enum_index == 0
assert int_enum.enum_indices[0] == 0
assert not int_enum.spec.enum_tokenizable
assert not int_enum.spec.enum_upper_tokenizable

assert string_enum.val == 'foo_bar'
assert string_enum.enum_index == 1
assert string_enum.enum_indices[0] == 1
assert not string_enum.spec.enum_tokenizable
assert not string_enum.spec.enum_upper_tokenizable

assert tokenizable_enum.val == '123 is ok'
assert tokenizable_enum.val_as_token == '123_is_ok'
assert tokenizable_enum.enum_index == 2
assert tokenizable_enum.val_as_tokens[0] == '123_is_ok'
assert tokenizable_enum.enum_indices[0] == 2
assert tokenizable_enum.spec.enum_tokenizable
assert tokenizable_enum.spec.enum_upper_tokenizable

assert tokenizable_lower_enum.val == 'bar'
assert tokenizable_lower_enum.val_as_token == 'bar'
assert tokenizable_lower_enum.enum_index == 0
assert tokenizable_lower_enum.val_as_tokens[0] == 'bar'
assert tokenizable_lower_enum.enum_indices[0] == 0
assert tokenizable_lower_enum.spec.enum_tokenizable
assert not tokenizable_lower_enum.spec.enum_upper_tokenizable

assert no_enum.enum_index is None
assert array_enum.val == [0, 40, 40, 10]
assert array_enum.enum_indices == [0, 4, 4, 1]
assert not array_enum.spec.enum_tokenizable
assert not array_enum.spec.enum_upper_tokenizable

assert string_array_enum.val == ["foo", "bar"]
assert string_array_enum.val_as_tokens == ["foo", "bar"]
assert string_array_enum.enum_indices == [1, 0]
assert string_array_enum.spec.enum_tokenizable
assert string_array_enum.spec.enum_upper_tokenizable

assert no_enum.enum_indices is None
assert not no_enum.spec.enum_tokenizable
assert not no_enum.spec.enum_upper_tokenizable

Expand Down

0 comments on commit 7454cb9

Please sign in to comment.