Skip to content

Commit

Permalink
[Matter_yamltests] Add to flake8 in workflow and fix python files (part
Browse files Browse the repository at this point in the history
#25193)  (#25250)

* [matter_yamltests] Add to flake8 in workflow and fix python files

* Restyled by isort

* Adding a comment for noqa use

* Fix after reabse

* Fix flake errors after rebase

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Feb 26, 2024
1 parent 1cff347 commit 0fbf28c
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 33 deletions.
12 changes: 0 additions & 12 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,7 @@ exclude = third_party
scripts/helpers/bloat_check.py
scripts/pregenerate/using_codegen.py
scripts/pregenerate/using_zap.py
scripts/py_matter_yamltests/matter_yamltests/constraints.py
scripts/py_matter_yamltests/matter_yamltests/definitions.py
scripts/py_matter_yamltests/matter_yamltests/fixes.py
scripts/py_matter_yamltests/matter_yamltests/parser.py
scripts/py_matter_yamltests/matter_yamltests/pics_checker.py
scripts/py_matter_yamltests/matter_yamltests/pseudo_clusters/pseudo_clusters.py
scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py
scripts/py_matter_yamltests/test_pics_checker.py
scripts/py_matter_yamltests/test_spec_definitions.py
scripts/py_matter_yamltests/test_yaml_loader.py
scripts/py_matter_yamltests/test_yaml_parser.py
scripts/run-clang-tidy-on-compile-commands.py
scripts/tests/chiptest/yamltest_with_chip_repl_tester.py
scripts/tools/check_zcl_file_sync.py
scripts/tools/convert_ini.py
scripts/tools/memory/memdf/__init__.py
Expand Down
7 changes: 4 additions & 3 deletions scripts/py_matter_yamltests/matter_yamltests/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
#

import math
import re
import string
from abc import ABC, abstractmethod
Expand Down Expand Up @@ -195,7 +196,7 @@ def _raise_error(self, reason):
raise ConstraintAnyOfError(self._context, reason)
else:
# This should not happens.
raise ConstraintParseError(f'Unknown constraint instance.')
raise ConstraintParseError('Unknown constraint instance.')


class _ConstraintHasValue(BaseConstraint):
Expand All @@ -219,7 +220,7 @@ def check_response(self, value, value_type_name) -> bool:

def get_reason(self, value, value_type_name) -> str:
if self._has_value:
return f"The constraint expects a value but there isn't one."
return "The constraint expects a value but there isn't one."
return f"The response contains the value ({value}), but wasn't expecting any value."


Expand Down Expand Up @@ -572,7 +573,7 @@ def get_reason(self, value, value_type_name) -> str:
chars = []

for char in value:
if not char in string.hexdigits:
if char not in string.hexdigits:
chars.append(char)

if len(chars) == 1:
Expand Down
3 changes: 2 additions & 1 deletion scripts/py_matter_yamltests/matter_yamltests/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import io
from typing import List, Optional

from matter_idl.matter_idl_types import *
from matter_idl.matter_idl_types import (Attribute, Bitmap, Cluster, Command, Enum, Event, FieldQuality, Struct, StructQuality,
StructTag)
from matter_idl.zapxml import ParseSource, ParseXmls

from .pseudo_clusters.pseudo_clusters import PseudoClusters
Expand Down
2 changes: 1 addition & 1 deletion scripts/py_matter_yamltests/matter_yamltests/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def try_apply_yaml_unrepresentable_integer_for_javascript_fixes(value):
if type(value) is str:
try:
value = int(value)
except:
except ValueError:
pass
return value

Expand Down
8 changes: 4 additions & 4 deletions scripts/py_matter_yamltests/matter_yamltests/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,8 @@ def post_process_response(self, received_responses):
return result

check_type = PostProcessCheckType.RESPONSE_VALIDATION
error_failure_wrong_response_number = f'The test expects {len(self.responses)} responses but got {len(received_responses)} responses.'
error_failure_wrong_response_number = (f'The test expects {len(self.responses)} responses '
f'but got {len(received_responses)} responses.')

received_responses_copy = copy.deepcopy(received_responses)
for expected_response in self.responses:
Expand Down Expand Up @@ -743,7 +744,6 @@ def _response_cluster_wait_validation(self, received_responses, result):
check_type = PostProcessCheckType.WAIT_VALIDATION
error_success = 'The test expectation "{wait_for}" for "{cluster}.{wait_type}" on endpoint {endpoint} is true'
error_failure = 'The test expectation "{expected} == {received}" is false'
error_failure_multiple_responses = 'The test expects a single response but got {len(received_responses)} responses.'

if len(received_responses) > 1:
result.error(check_type, error_failure.multiple_responses)
Expand All @@ -758,7 +758,7 @@ def _response_cluster_wait_validation(self, received_responses, result):
received_wait_type = received_response.get('event')
else:
expected_wait_type = self.command
received_wait_type = receive_response.get('command')
received_wait_type = received_response.get('command')

expected_values = [
self.wait_for,
Expand Down Expand Up @@ -1110,7 +1110,7 @@ def __init__(self, test_file: str, parser_config: TestParserConfig = TestParserC

def __apply_config_override(self, config, config_override):
for key, value in config_override.items():
if value is None or not key in config:
if value is None or key not in config:
continue

is_node_id = key == 'nodeId' or (isinstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __evaluate_sub_expression(self, tokens: List[str], pics: dict):
token = self.__normalize(token)
self.__expression_index += 1

if pics.get(token) == None:
if pics.get(token) is None:
# By default, let's consider that if a PICS item is not defined, it is |false|.
# It allows to create a file that only contains enabled features.
return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def execute(self, request):
if command:
status = await command(request)
# If the command does not returns an error, it is considered a success.
if status == None:
if status is None:
status = {}

return status, []
Expand Down
4 changes: 2 additions & 2 deletions scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

try:
from yaml import CSafeLoader as SafeLoader
except:
except ImportError:
from yaml import SafeLoader

import os
Expand Down Expand Up @@ -240,7 +240,7 @@ def __rule_step_with_verification_should_be_disabled_or_interactive(self, conten
if 'verification' in content:
disabled = content.get('disabled')
command = content.get('command')
if disabled != True and command != 'UserPrompt':
if disabled is not True and command != 'UserPrompt':
raise TestStepVerificationStandaloneError(content)

def __rule_response_value_and_values_are_mutually_exclusive(self, content):
Expand Down
1 change: 0 additions & 1 deletion scripts/py_matter_yamltests/test_pics_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import io
import unittest
from unittest.mock import mock_open, patch

Expand Down
2 changes: 1 addition & 1 deletion scripts/py_matter_yamltests/test_spec_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import io
import unittest

from matter_yamltests.definitions import *
from matter_yamltests.definitions import Attribute, Bitmap, Command, Enum, Event, ParseSource, SpecDefinitions, Struct

source_cluster = '''<?xml version="1.0"?>
<configurator>
Expand Down
1 change: 0 additions & 1 deletion scripts/py_matter_yamltests/test_yaml_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# limitations under the License.
#

import io
import unittest
from unittest.mock import mock_open, patch

Expand Down
2 changes: 1 addition & 1 deletion scripts/py_matter_yamltests/test_yaml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import tempfile
import unittest

from matter_yamltests.definitions import *
from matter_yamltests.definitions import ParseSource, SpecDefinitions
from matter_yamltests.parser import TestParser, TestParserConfig

simple_test_description = '''<?xml version="1.0"?>
Expand Down
14 changes: 10 additions & 4 deletions scripts/tests/chiptest/yamltest_with_chip_repl_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@

# isort: off

from chip import ChipDeviceCtrl # Needed before chip.FabricAdmin
# F401 is "Module imported but unused" line will be ignored by linter
# ChipDeviceCtrl is not used directly in this file but it is needed
from chip import ChipDeviceCtrl # noqa: F401 # Needed before chip.FabricAdmin
import chip.FabricAdmin # Needed before chip.CertificateAuthority

# isort: on

# ensure matter IDL is availale for import, otherwise set relative paths
try:
from matter_idl import matter_idl_types
except:
except ImportError:
SCRIPT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
import sys

Expand All @@ -40,11 +42,13 @@

from matter_idl import matter_idl_types

__ALL__ = (matter_idl_types)


import chip.CertificateAuthority
import chip.native
import click
from chip.ChipStack import *
from chip.ChipStack import ChipStack
from chip.yaml.runner import ReplTestRunner
from matter_yamltests.definitions import SpecDefinitionsFromPaths
from matter_yamltests.parser import PostProcessCheckStatus, TestParser, TestParserConfig
Expand All @@ -54,6 +58,8 @@
_CLUSTER_XML_DIRECTORY_PATH = os.path.abspath(
os.path.join(_DEFAULT_CHIP_ROOT, "src/app/zap-templates/zcl/data-model/"))

certificateAuthorityManager = None


async def execute_test(yaml, runner):
# Executing and validating test
Expand All @@ -70,7 +76,7 @@ async def execute_test(yaml, runner):
post_processing_result = test_step.post_process_response(
decoded_response)
if not post_processing_result.is_success():
logging.warning(f"Test step failure in 'test_step.label'")
logging.warning(f"Test step failure in {test_step.label}")
for entry in post_processing_result.entries:
if entry.state == PostProcessCheckStatus.SUCCESS:
continue
Expand Down

0 comments on commit 0fbf28c

Please sign in to comment.