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

Allowing chip-repl test to send invalid enum values #24352

Merged
merged 16 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src/controller/python/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ chip_python_wheel_action("chip-core") {
"chip/ChipCommissionableNodeCtrl.py",
"chip/ChipCoreBluetoothMgr.py",
"chip/ChipStack.py",
"chip/enum.py",
"chip/FabricAdmin.py",
"chip/__init__.py",
"chip/ble/__init__.py",
Expand Down
8 changes: 4 additions & 4 deletions src/controller/python/chip/clusters/Objects.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions src/controller/python/chip/enum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Copyright (c) 2023 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from aenum import IntEnum as AenumsIntEnum
from aenum import extend_enum

_add_missing_enum_value_as_is = False
_map_missing_enum_to_unknown_enum_value = True
_dummy_count = 0
tehampson marked this conversation as resolved.
Show resolved Hide resolved


class IntEnum(AenumsIntEnum):
tehampson marked this conversation as resolved.
Show resolved Hide resolved
@classmethod
def _missing_(cls, value):
global _add_missing_enum_value_as_is
tehampson marked this conversation as resolved.
Show resolved Hide resolved
if _add_missing_enum_value_as_is:
global _dummy_count
return_value = extend_enum(cls, f'kDummy{_dummy_count}', value)
tehampson marked this conversation as resolved.
Show resolved Hide resolved
_dummy_count = _dummy_count + 1
return return_value
global _map_missing_enum_to_unknown_enum_value
if _map_missing_enum_to_unknown_enum_value:
return cls.kUnknownEnumValue

return None


def set_add_missing_enum_value_as_is(value: bool):
global _add_missing_enum_value_as_is
_add_missing_enum_value_as_is = value


def set_map_missing_enum_to_unknown_enum_value(value: bool):
global _map_missing_enum_to_unknown_enum_value
_map_missing_enum_to_unknown_enum_value = value
2 changes: 2 additions & 0 deletions src/controller/python/chip/yaml/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import stringcase
from chip import ChipDeviceCtrl
from chip.clusters.Attribute import AttributeStatus, ValueDecodeFailure
from chip.enum import set_add_missing_enum_value_as_is
from chip.yaml.errors import ParsingError, UnexpectedParsingError

from .data_model_lookup import *
Expand Down Expand Up @@ -265,6 +266,7 @@ class ReplTestRunner:
'''

def __init__(self, test_spec_definition, dev_ctrl):
set_add_missing_enum_value_as_is(True)
self._test_spec_definition = test_spec_definition
self._dev_ctrl = dev_ctrl
self._context = _ExecutionContext(data_model_lookup=PreDefinedDataModelLookup())
Expand Down