From 08c55c4079c3842f54e7b780a5ba7b3638a2d125 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 8 Apr 2022 16:36:36 +0200 Subject: [PATCH] fixed all files and added pylint to CI --- .github/workflows/ci.yaml | 2 +- .pre-commit-config.yaml | 11 ----------- poetry.lock | 19 ++++++++++++++++++- pyproject.toml | 8 ++++++-- src/parse_source.py | 4 ++-- test/execute_tests_impl.py | 22 ++++++++++++---------- test/execute_tests_utest.py | 2 +- 7 files changed, 40 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 238b3063..da54c970 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,4 +16,4 @@ jobs: - run: pip install poetry - run: poetry install - name: Coverage - run: poetry run pytest --cov + run: poetry run pytest --cov --pylint diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 75a66e48..92837fd2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,14 +25,3 @@ repos: args: [ --py38-plus ] language: system types: [ python ] - - - id: pylint - name: pylint - entry: poetry run pylint ./src - language: system - types: [ python ] - args: - [ - "-rn", # Only display messages - "-sn", # Don't display the score - ] diff --git a/poetry.lock b/poetry.lock index 72d4fb6f..5fbc3697 100644 --- a/poetry.lock +++ b/poetry.lock @@ -327,6 +327,19 @@ pytest = ">=4.6" [package.extras] testing = ["fields", "hunter", "process-tests", "six", "pytest-xdist", "virtualenv"] +[[package]] +name = "pytest-pylint" +version = "0.18.0" +description = "pytest plugin to check source code with pylint" +category = "dev" +optional = false +python-versions = ">=3.5" + +[package.dependencies] +pylint = ">=2.3.0" +pytest = ">=5.4" +toml = ">=0.7.1" + [[package]] name = "pyupgrade" version = "2.31.1" @@ -415,7 +428,7 @@ python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "36f456da3fa2573d2e7da125a4f5a2a08754f9d81c5cd9c8c62afbe3dc37296e" +content-hash = "40af318318e9471837ae77e5227daaa5172ce1a17646f7e55217ca833a6ca1f3" [metadata.files] astroid = [ @@ -625,6 +638,10 @@ pytest-cov = [ {file = "pytest-cov-3.0.0.tar.gz", hash = "sha256:e7f0f5b1617d2210a2cabc266dfe2f4c75a8d32fb89eafb7ad9d06f6d076d470"}, {file = "pytest_cov-3.0.0-py3-none-any.whl", hash = "sha256:578d5d15ac4a25e5f961c938b85a05b09fdaae9deef3bb6de9a6e766622ca7a6"}, ] +pytest-pylint = [ + {file = "pytest-pylint-0.18.0.tar.gz", hash = "sha256:790c7a8019fab08e59bd3812db1657a01995a975af8b1c6ce95b9aa39d61da27"}, + {file = "pytest_pylint-0.18.0-py3-none-any.whl", hash = "sha256:b63aaf8b80ff33c8ceaa7f68323ed04102c7790093ccf6bdb261a4c2dc6fd564"}, +] pyupgrade = [ {file = "pyupgrade-2.31.1-py2.py3-none-any.whl", hash = "sha256:4060a7c20c79d373a3dcf34566b275c6de6cd2b034ad22465d3263fb0de82648"}, {file = "pyupgrade-2.31.1.tar.gz", hash = "sha256:22e0ad6dd39c4381805cb059f1e691b6315c62c0ebcec98a5f29d22cd186a72a"}, diff --git a/pyproject.toml b/pyproject.toml index fc505a45..1a1a234d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,13 +33,17 @@ pyupgrade = "^2.31.1" coverage = {extras = ["toml"], version = "^6.3.2"} pytest-cov = "^3.0.0" pylint = "^2.13.5" +pytest-pylint = "^0.18.0" [tool.pylint.FORMAT] max-line-length = 120 - disable = ["missing-function-docstring", "missing-module-docstring", - "missing-class-docstring"] + "missing-class-docstring", + "too-many-branches", "import-error"] + +[tool.pylint.SIMILARITIES] +ignore-imports=true [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/src/parse_source.py b/src/parse_source.py index 7efb20eb..3b365edc 100644 --- a/src/parse_source.py +++ b/src/parse_source.py @@ -76,7 +76,7 @@ def filter_includes(includes: List[Include], ignored_includes: set) -> List[Incl def get_relevant_includes_from_files(files: Union[List[str], None], ignored_includes: set) -> List[Include]: all_includes = [] if files: - for f in files: - includes = get_includes_from_file(Path(f)) + for file in files: + includes = get_includes_from_file(Path(file)) all_includes.extend(includes) return filter_includes(includes=all_includes, ignored_includes=ignored_includes) diff --git a/test/execute_tests_impl.py b/test/execute_tests_impl.py index 324893cc..2add02c2 100644 --- a/test/execute_tests_impl.py +++ b/test/execute_tests_impl.py @@ -24,7 +24,8 @@ class TestCmd: @dataclass class ExpectedResult: """ - Encapsulates an expected result of a DWYU analysis and offers functions to compare a given output to the expectations. + Encapsulates an expected result of a DWYU analysis and offers functions + to compare a given output to the expectations. """ success: bool @@ -136,10 +137,10 @@ def verify_test(test: TestCase, process: sb.CompletedProcess, verbose: bool) -> ok_verb = "succeeded" if test.expected.success else "failed" print(f"<<< OK '{test.name}' {ok_verb} as expected") return True - else: - print("\n" + process.stdout + "\n") - print(f"<<< ERROR '{test.name}' did not behave as expected") - return False + + print("\n" + process.stdout + "\n") + print(f"<<< ERROR '{test.name}' did not behave as expected") + return False def make_cmd(test_cmd: TestCmd, extra_args: List[str]) -> List[str]: @@ -186,8 +187,8 @@ def execute_tests( if not is_compatible_version(version=version, compatible_versions=test.compatible_versions): print(f"\n--- Skip '{test.name}' due to incompatible Bazel '{version}'") continue - else: - print(f"\n>>> Execute '{test.name}' with Bazel '{version}'") + + print(f"\n>>> Execute '{test.name}' with Bazel '{version}'") process = sb.run( make_cmd(test_cmd=test.cmd, extra_args=extra_args), @@ -195,6 +196,7 @@ def execute_tests( text=True, stdout=sb.PIPE, stderr=sb.STDOUT, + check=False, ) if not verify_test(test=test, process=process, verbose=verbose): @@ -229,6 +231,6 @@ def main(args: argparse.Namespace, test_cases: List[TestCase], test_versions: Li print("These tests failed:") print("\n".join(f"- '{t.name} - for Bazel version '{t.version}'" for t in failed_tests)) return 1 - else: - print("SUCCESS\n") - return 0 + + print("SUCCESS\n") + return 0 diff --git a/test/execute_tests_utest.py b/test/execute_tests_utest.py index 64d5ef0b..5b32387f 100644 --- a/test/execute_tests_utest.py +++ b/test/execute_tests_utest.py @@ -140,7 +140,7 @@ def test_with_aspect(self): cmd = make_cmd(test_cmd=TestCmd(target="//foo:bar"), extra_args=[]) self.assertEqual(cmd, self._base_cmd() + ["--", "//foo:bar"]) - def test_with_aspect(self): + def test_with_aspect_2(self): cmd = make_cmd(test_cmd=TestCmd(target="//foo:bar", aspect="//some/aspect.bzl"), extra_args=[]) self.assertEqual( cmd,