From 6f7fc638c7dad4315a318ea00b357916558ca6a3 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 17 Aug 2020 12:56:57 +0300 Subject: [PATCH] Fix PyLint errors in tests --- .pylintrc | 3 +++ Makefile | 3 ++- platformio/platform/base.py | 2 -- tests/__init__.py | 13 +++++++++++++ tests/commands/__init__.py | 13 +++++++++++++ tests/commands/test_account_org_team.py | 5 ++++- tests/commands/test_boards.py | 2 +- tests/commands/test_check.py | 2 ++ tests/commands/test_lib.py | 2 ++ tests/commands/test_lib_complex.py | 8 ++++++-- tests/commands/test_platform.py | 2 ++ tests/commands/test_test.py | 1 + tests/commands/test_update.py | 2 ++ tests/ino2cpp/__init__.py | 13 +++++++++++++ tests/package/__init__.py | 13 +++++++++++++ tests/package/test_manager.py | 2 ++ tests/package/test_manifest.py | 2 +- tests/test_examples.py | 7 ++++--- tests/test_maintenance.py | 2 ++ tests/test_misc.py | 3 +++ tests/test_projectconf.py | 4 +++- tox.ini | 2 +- 22 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/commands/__init__.py create mode 100644 tests/ino2cpp/__init__.py create mode 100644 tests/package/__init__.py diff --git a/.pylintrc b/.pylintrc index 67ce4ef7..6ce74864 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,6 @@ +[REPORTS] +output-format=colorized + [MESSAGES CONTROL] disable= bad-continuation, diff --git a/Makefile b/Makefile index 6b22d261..fa301e59 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ lint: - pylint --rcfile=./.pylintrc ./platformio + pylint -j 6 --rcfile=./.pylintrc ./platformio ./tests + pylint -j 6 --rcfile=./.pylintrc ./tests isort: isort -rc ./platformio diff --git a/platformio/platform/base.py b/platformio/platform/base.py index a5f3dd01..8e49288d 100644 --- a/platformio/platform/base.py +++ b/platformio/platform/base.py @@ -101,8 +101,6 @@ class PlatformBase( # pylint: disable=too-many-instance-attributes,too-many-pub if spec.name not in packages: packages[spec.name] = {} packages[spec.name].update(**options) - - print(13, packages) return packages @property diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..b0514903 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,13 @@ +# Copyright (c) 2014-present PlatformIO +# +# 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. diff --git a/tests/commands/__init__.py b/tests/commands/__init__.py new file mode 100644 index 00000000..b0514903 --- /dev/null +++ b/tests/commands/__init__.py @@ -0,0 +1,13 @@ +# Copyright (c) 2014-present PlatformIO +# +# 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. diff --git a/tests/commands/test_account_org_team.py b/tests/commands/test_account_org_team.py index b6d5b6d4..fc64db41 100644 --- a/tests/commands/test_account_org_team.py +++ b/tests/commands/test_account_org_team.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=global-statement,unused-argument + import json import os import random @@ -30,6 +32,7 @@ pytestmark = pytest.mark.skipif( username = None email = None +splited_email = None firstname = None lastname = None password = None @@ -43,7 +46,7 @@ team_description = None def test_prepare(): - global username, splited_email, email, firstname, lastname + global username, email, splited_email, firstname, lastname global password, orgname, display_name, second_username, teamname, team_description username = "test-piocore-%s" % str(random.randint(0, 100000)) diff --git a/tests/commands/test_boards.py b/tests/commands/test_boards.py index bcb1f280..21142dd4 100644 --- a/tests/commands/test_boards.py +++ b/tests/commands/test_boards.py @@ -40,7 +40,7 @@ def test_board_options(clirunner, validate_cliresult): validate_cliresult(result) search_result = json.loads(result.output) assert isinstance(search_result, list) - assert len(search_result) + assert search_result platforms = [item["name"] for item in search_result] result = clirunner.invoke(cmd_boards, ["mbed", "--json-output"]) diff --git a/tests/commands/test_check.py b/tests/commands/test_check.py index 998d44cf..655449b0 100644 --- a/tests/commands/test_check.py +++ b/tests/commands/test_check.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=redefined-outer-name + import json import sys from os.path import isfile, join diff --git a/tests/commands/test_lib.py b/tests/commands/test_lib.py index 1880d671..332161e1 100644 --- a/tests/commands/test_lib.py +++ b/tests/commands/test_lib.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=unused-argument + import json import os diff --git a/tests/commands/test_lib_complex.py b/tests/commands/test_lib_complex.py index a71330db..dfb853f4 100644 --- a/tests/commands/test_lib_complex.py +++ b/tests/commands/test_lib_complex.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=line-too-long + import json import re @@ -129,7 +131,9 @@ def test_global_install_repository(clirunner, validate_cliresult, isolated_pio_c assert set(items1) >= set(items2) -def test_install_duplicates(clirunner, validate_cliresult, without_internet): +def test_install_duplicates( # pylint: disable=unused-argument + clirunner, validate_cliresult, without_internet +): # registry result = clirunner.invoke( cmd_lib, @@ -231,7 +235,7 @@ def test_global_lib_update_check(clirunner, validate_cliresult): result = clirunner.invoke(cmd_lib, ["-g", "update", "--dry-run", "--json-output"]) validate_cliresult(result) output = json.loads(result.output) - assert set(["ESPAsyncTCP", "NeoPixelBus"]) == set([lib["name"] for lib in output]) + assert set(["ESPAsyncTCP", "NeoPixelBus"]) == set(lib["name"] for lib in output) def test_global_lib_update(clirunner, validate_cliresult): diff --git a/tests/commands/test_platform.py b/tests/commands/test_platform.py index 74bb6f45..2c197ec3 100644 --- a/tests/commands/test_platform.py +++ b/tests/commands/test_platform.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=unused-argument + import json from platformio.commands import platform as cli_platform diff --git a/tests/commands/test_test.py b/tests/commands/test_test.py index 16e0556c..9f072868 100644 --- a/tests/commands/test_test.py +++ b/tests/commands/test_test.py @@ -33,6 +33,7 @@ def test_local_env(): ) if result["returncode"] != 1: pytest.fail(str(result)) + # pylint: disable=unsupported-membership-test assert all([s in result["err"] for s in ("PASSED", "IGNORED", "FAILED")]), result[ "out" ] diff --git a/tests/commands/test_update.py b/tests/commands/test_update.py index 1817be33..b9ecb5c1 100644 --- a/tests/commands/test_update.py +++ b/tests/commands/test_update.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=unused-argument + from platformio.commands.update import cli as cmd_update diff --git a/tests/ino2cpp/__init__.py b/tests/ino2cpp/__init__.py new file mode 100644 index 00000000..b0514903 --- /dev/null +++ b/tests/ino2cpp/__init__.py @@ -0,0 +1,13 @@ +# Copyright (c) 2014-present PlatformIO +# +# 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. diff --git a/tests/package/__init__.py b/tests/package/__init__.py new file mode 100644 index 00000000..b0514903 --- /dev/null +++ b/tests/package/__init__.py @@ -0,0 +1,13 @@ +# Copyright (c) 2014-present PlatformIO +# +# 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. diff --git a/tests/package/test_manager.py b/tests/package/test_manager.py index c91924f4..f014a66b 100644 --- a/tests/package/test_manager.py +++ b/tests/package/test_manager.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=unused-argument + import os import time diff --git a/tests/package/test_manifest.py b/tests/package/test_manifest.py index 35fdf367..9dd5b878 100644 --- a/tests/package/test_manifest.py +++ b/tests/package/test_manifest.py @@ -741,7 +741,7 @@ def test_examples_from_dir(tmpdir_factory): return re.sub(r"[\\/]+", "/", path) def _sort_examples(items): - for i, item in enumerate(items): + for i, _ in enumerate(items): items[i]["base"] = _to_unix_path(items[i]["base"]) items[i]["files"] = [_to_unix_path(f) for f in sorted(items[i]["files"])] return sorted(items, key=lambda item: item["name"]) diff --git a/tests/test_examples.py b/tests/test_examples.py index d0a580d4..ada20d35 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -21,7 +21,8 @@ import pytest from platformio import util from platformio.compat import PY2 -from platformio.managers.platform import PlatformFactory, PlatformManager +from platformio.package.manager.platform import PlatformPackageManager +from platformio.platform.factory import PlatformFactory from platformio.project.config import ProjectConfig @@ -34,8 +35,8 @@ def pytest_generate_tests(metafunc): examples_dirs.append(normpath(join(dirname(__file__), "..", "examples"))) # dev/platforms - for manifest in PlatformManager().get_installed(): - p = PlatformFactory.new(manifest["__pkg_dir"]) + for pkg in PlatformPackageManager().get_installed(): + p = PlatformFactory.new(pkg) examples_dir = join(p.get_dir(), "examples") assert isdir(examples_dir) examples_dirs.append(examples_dir) diff --git a/tests/test_maintenance.py b/tests/test_maintenance.py index 4150bcdd..46bc82c8 100644 --- a/tests/test_maintenance.py +++ b/tests/test_maintenance.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=unused-argument + import json import os import re diff --git a/tests/test_misc.py b/tests/test_misc.py index d01cc46d..ae019f6b 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=unused-argument + import pytest import requests @@ -21,6 +23,7 @@ from platformio import exception, util def test_platformio_cli(): result = util.exec_command(["pio", "--help"]) assert result["returncode"] == 0 + # pylint: disable=unsupported-membership-test assert "Usage: pio [OPTIONS] COMMAND [ARGS]..." in result["out"] diff --git a/tests/test_projectconf.py b/tests/test_projectconf.py index 4d832c97..832ceb71 100644 --- a/tests/test_projectconf.py +++ b/tests/test_projectconf.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=redefined-outer-name + import os import pytest @@ -345,7 +347,7 @@ board = myboard ["check_types", [("float_option", 13.99), ("bool_option", True)]], ] ) - config.get("platformio", "extra_configs") == "extra.ini" + assert config.get("platformio", "extra_configs") == ["extra.ini"] config.remove_section("platformio") assert config.as_tuple() == [ ("env:myenv", [("board", "myboard"), ("framework", ["espidf", "arduino"])]), diff --git a/tox.ini b/tox.ini index fbe285e2..0faae46b 100644 --- a/tox.ini +++ b/tox.ini @@ -31,7 +31,7 @@ commands = [testenv:lint] commands = {envpython} --version - pylint --rcfile=./.pylintrc ./platformio + pylint --rcfile=./.pylintrc ./platformio ./tests [testenv:testcore] commands =