Skip to content

Commit

Permalink
Fix mypy and flake violations
Browse files Browse the repository at this point in the history
  • Loading branch information
rquidute committed Nov 8, 2023
1 parent 1b8e180 commit 6b1bc86
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 13 deletions.
5 changes: 4 additions & 1 deletion app/tests/python_tests/test_python_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# flake8: noqa
# Ignore flake8 check for this file
from pathlib import Path
from unittest import mock

Expand All @@ -29,7 +31,8 @@ def test_python_folder_version() -> None:
# We mock open to read version_file_content and Path exists to ignore that we're
# testing with a fake path
with mock.patch(
"test_collections.sdk_tests.support.python_testing.models.python_test_folder.open",
"test_collections.sdk_tests.support.python_testing.models."
"python_test_folder.open",
new=mock.mock_open(read_data=version_file_content),
), mock.patch.object(target=Path, attribute="exists", return_value=True) as _:
python_test_folder = PythonTestFolder(test_python_path)
Expand Down
8 changes: 6 additions & 2 deletions app/tests/python_tests/test_python_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# flake8: noqa
# Ignore flake8 check for this file
from pathlib import Path
from unittest import mock

Expand Down Expand Up @@ -63,7 +65,8 @@ def test_python_file_parser_throws_pythonparserexception() -> None:
file_path = Path("/test/file.py")

with mock.patch(
"test_collections.sdk_tests.support.python_testing.models.python_test_parser.open",
"test_collections.sdk_tests.support.python_testing.models.python_test_parser."
"open",
new=mock.mock_open(read_data=sample_invalid_python_file_content),
):
try:
Expand All @@ -80,7 +83,8 @@ def test_python_file_parser() -> None:
# We mock builtin `open` method to read sample python file content,
# to avoid having to load a real file.
with mock.patch(
"test_collections.sdk_tests.support.python_testing.models.python_test_parser.open",
"test_collections.sdk_tests.support.python_testing.models.python_test_parser."
"open",
new=mock.mock_open(read_data=sample_python_file_content),
) as file_open:
test = parse_python_test(file_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
# 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.
#
# type: ignore
# Ignore mypy type check for this file

# flake8: noqa
# Ignore flake8 check for this file
"""
This is just a sample test case that should come from SDK.
It should not compile or run.
Expand Down
2 changes: 2 additions & 0 deletions app/tests/python_tests/test_python_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# flake8: noqa
# Ignore flake8 check for this file
from pathlib import Path
from typing import Any, Optional, Type
from unittest import mock
Expand Down
2 changes: 2 additions & 0 deletions app/tests/python_tests/test_python_test_declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# flake8: noqa
# Ignore flake8 check for this file
from unittest import mock

from test_collections.sdk_tests.support.python_testing.models.python_test_models import (
Expand Down
2 changes: 2 additions & 0 deletions app/tests/python_tests/test_sdk_python_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# flake8: noqa
# Ignore flake8 check for this file
from pathlib import Path

import pytest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from pathlib import Path
from typing import Any, Optional

from pydantic import BaseModel, Field
from pydantic import BaseModel

###
# This file declares Python test models that are used to parse the Python Test Cases.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# type: ignore
# Ignore mypy type check for this file
import ast
from pathlib import Path
from typing import List, Tuple
Expand Down Expand Up @@ -46,7 +44,8 @@ def parse_python_test(path: Path) -> PythonTest:
# The file name from path
tc_name = path.name.split(".")[0]
raise PythonParserException(
f"Test Case {tc_name} does not have methods desc_{tc_name} or steps_{tc_name}"
f"Test Case {tc_name} does not have methods desc_{tc_name} "
f"or steps_{tc_name}"
)

test = PythonTest(name=tc_desc, steps=tc_steps, config=tc_config, PICS=tc_pics)
Expand All @@ -69,7 +68,7 @@ def __extract_tcs_info(path: Path) -> Tuple[str, List[PythonTestStep]]:
methods = [m for m in class_.body if isinstance(m, ast.FunctionDef)]
for method in methods:
if "desc_" in method.name:
tc_desc = method.body[BODY_INDEX].value.value
tc_desc = method.body[BODY_INDEX].value.value # type: ignore

Check failure on line 71 in test_collections/sdk_tests/support/python_testing/models/python_test_parser.py

View workflow job for this annotation

GitHub Actions / Flake8

test_collections/sdk_tests/support/python_testing/models/python_test_parser.py#L71

At least two spaces before inline comment (E261)
elif "steps_" in method.name:
tc_steps = __retrieve_steps(method)

Expand All @@ -78,7 +77,7 @@ def __extract_tcs_info(path: Path) -> Tuple[str, List[PythonTestStep]]:

def __retrieve_steps(method: ast.FunctionDef) -> List[PythonTestStep]:
python_steps: List[PythonTestStep] = []
for step in method.body[BODY_INDEX].value.elts:
for step in method.body[BODY_INDEX].value.elts: # type: ignore

Check failure on line 80 in test_collections/sdk_tests/support/python_testing/models/python_test_parser.py

View workflow job for this annotation

GitHub Actions / Flake8

test_collections/sdk_tests/support/python_testing/models/python_test_parser.py#L80

At least two spaces before inline comment (E261)
step_name = step.args[ARG_STEP_DESCRIPTION_INDEX].value
arg_is_commissioning = False
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class PythonTestCase(TestCase):
This class provides a class factory that will dynamically declare a new sub-class
based on the test-type the Python test is expressing.
The PythonTest will be stored as a class property that will be used at run-time in all
instances of such subclass.
The PythonTest will be stored as a class property that will be used at run-time

Check failure on line 36 in test_collections/sdk_tests/support/python_testing/models/test_case.py

View workflow job for this annotation

GitHub Actions / Flake8

test_collections/sdk_tests/support/python_testing/models/test_case.py#L36

Trailing whitespace (W291)
in all instances of such subclass.
"""

python_test: PythonTest
Expand All @@ -47,7 +47,8 @@ def pics(cls) -> set[str]:

@classmethod
def default_test_parameters(cls) -> dict[str, Any]:
"""Python test config dict, sometimes have a nested dict with type and default value.
"""Python test config dict, sometimes have a nested dict with type

Check failure on line 50 in test_collections/sdk_tests/support/python_testing/models/test_case.py

View workflow job for this annotation

GitHub Actions / Flake8

test_collections/sdk_tests/support/python_testing/models/test_case.py#L50

Trailing whitespace (W291)
and default value.
Only defaultValue is used in this case.
"""
parameters = {}
Expand Down

0 comments on commit 6b1bc86

Please sign in to comment.